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.

On Wednesday, December 2, 2015 at 6:28:06 AM UTC-8, Tim Graham wrote:
>
> It will be easier to help if you can provide a sample project that 
> reproduces the error.
>
> On Wednesday, December 2, 2015 at 3:01:31 AM UTC-5, Siddhi Divekar wrote:
>>
>> Hi,
>>
>> Am seeing that test case in suite are failing but passing when ran 
>> individually.
>> I have gone through most of the thread on the internet but did not find 
>> any solution.
>>
>> Below is the snip of what am trying to do.
>>
>> class A(TestCase):
>>   def test_a():
>>    create an obj in db
>>    retrive obj list from db and check the length of the list (should be 1)
>>    update same obj in db
>>    delte same obj in db
>>
>>  def b():
>>   create an obj in db and check the length.
>>
>> When ran in suite test_a fails as the length of the list is 2.
>> test_b() runs before test_a and leave the object in the database.
>>
>> From various threads suggested using 'django.test import TestCase' 
>> instead of 'from django.unittest import TestCase' which am already doing.
>>
>> Is there anything else i need to do here ?
>>
>

-- 
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/d3a0973b-166c-49da-912d-08db8783d623%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to