On Sat, Jun 7, 2008 at 12:33 AM, Michael Hipp <[EMAIL PROTECTED]> wrote:
>
>
> EricHolmberg wrote:
>>
>> I do just what you're trying to avoid -- I create example records with
>> test data and then verify everything.  I do this with SQLite and an in-
>> memory database so the tests run quickly.
>>
>> I would be interested in better patterns if they exist, but
>> ultimately, if you are following test-drive development, you will
>> write a new test for every bug that you find, so if you don't test how
>> you use the database initially, I bet you will end up writing tests as
>> bugs pop up!
>>
>> #
>> # import database model as model here
>> # DB Connection URI:  sqlalchemy.default.url = sqlite:///:memory:
>> from unittest import TestCase
>>
>> class SchemaTest(TestCase):
>>
>>     def setUp(self):
>>         TestCase.setUp(self)
>>
>>         # Clear out the database
>>         model.Recreate()
>>
>>     def tearDown(self):
>>         # abort any unclosed transactions and delete the session
>>         model.Session.rollback()
>>         model.Session.remove()
>>
>>         TestCase.tearDown(self)
>>
>>     def test_Address(self):
>>         # insert test addresses
>>         model.Session.begin()
>>         for n in range(3):
>>             # Create an email message with known fields (but all
>> unique) so we
>>             # can retrieve them and verify they are correct
>>             rAddress = model.Address()
>>             rAddress.email = '[EMAIL PROTECTED]' % (n)
>>             rAddress.strName=u'User name %d' % (n)
>>         model.Session.commit()
>>
>>         # Verify the addresses have been retrieved correctly
>>         model.Session.begin()
>>         rows =
>> model.Address.query().order_by(model.Address.email).all()
>>         self.assertEqual(3,len(rows))
>>         for n,row in zip(range(3),rows):
>>             self.assertEqual(row.email,'[EMAIL PROTECTED]' % (n))
>>             self.assertEqual(row.strName,'User name %d' % (n))
>>
>>         model.Session.commit()
>
> Thanks, Eric. This gives me some good ideas.
>
> Question: My production database is PostgreSQL. If I test good against SQLite
> in memory, can I rest assured that it will also work with Postgres? (Or am I
> just showing a lack of faith in Elixir/SA?)

Depends on what you test. I have the same setup as you and in most
case you should have no problem. I've had some surprises when
switching to Postgres (which I do once in a while) but those tend to
be quickly fixed. The most common problem I have (which is not so
common) is that SQLite is more tolerant to wrong data than Postgres
(for example it doesn't enforce foreign keys, it accepts arbitrary
length strings for limited length varchar and so on), so some wrong
code passed on SQLite and failed on Postgres, but I just added
explicit tests for those cases to my test suite and all is fine now.

-- 
Gaƫtan de Menten
http://openhex.org

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"SQLElixir" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to