On Wed, Dec 2, 2015 at 4:20 PM, Siddhi Divekar <siddhesh.dive...@gmail.com> wrote: > Hi Tim, > > Below is what am trying to achieve. > > class OrcaTestCase(TestCase): > > def test_customer_create_modify_delete(self): > '''Test customer object create, modify and delete operations in > DB.''' > # Create. > CustomerDb.objects.create(c_name='Pnc', c_role='ADFS-Admin', > c_date_created=timezone.now(), > c_date_updated=timezone.now()) > customer_list = CustomerDb.objects.all() > self.assertEqual(len(customer_list), 1) > > # Modify. > customer = CustomerDb.objects.get(c_name='Pnc') > self.assertNotEqual(customer, None) > setattr(customer, 'c_name', 'Zoo') > customer.save() > customer_list = CustomerDb.objects.all() > self.assertEqual(len(customer_list), 1) > self.assertEqual(str(customer_list[0]), 'Gap') > > # Delete. > customer = CustomerDb.objects.get(c_name='foo') > self.assertNotEqual(customer, None) > customer.delete() > customer_list = CustomerDb.objects.all() > self.assertEqual(len(customer_list), 0) > > def test_create_customer(self): > '''Handle customer create.''' > customer_list = CustomerDb.objects.all() > self.assertEqual(len(customer_list), 1) > > test_create_customer runs first, test_customer_create_modify_delete fails at > the highlighted line. >
You really really do not need to be testing that Django's CRUD operations work - there is no value in doing so, since Django is well tested. Tests should concentrate on the custom business logic that your app uses, not that when you create an object in the database, an object exists in the database. As to your question, what DB backend are you using for tests? Each django.test.TestCase test is run inside a transaction that is rolled back[1]; if your backend "supports" transactions by ignoring them (cough, MySQL/MyISAM), then nothing happens when the transaction is rolled back. Cheers Tom [1] https://docs.djangoproject.com/en/1.9/topics/testing/overview/#writing-tests -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFHbX1%2B6W%3Dgg2op%2BFc5xKHDCE8QOhiZx-CdCdm6a%3DtWG3YvNEw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.