| 1 | |
| 2 | from django.test import TestCase |
| 3 | |
| 4 | from models import A, B, D |
| 5 | |
| 6 | class SimpleTest(TestCase): |
| 7 | def setUp(self): |
| 8 | self.a1=A.objects.create() |
| 9 | self.a2=A.objects.create() |
| 10 | for x in range(20): |
| 11 | B.objects.create(a=self.a1) |
| 12 | D.objects.create(a=self.a1) |
| 13 | |
| 14 | def tearDown(self): |
| 15 | B.objects.all().delete() |
| 16 | A.objects.all().delete() |
| 17 | |
| 18 | |
| 19 | def test_nonempty_update(self): |
| 20 | """ |
| 21 | Test that update changes that right number of rows for a nonempty queryset |
| 22 | """ |
| 23 | num_updated=self.a1.b_set.update(y=100) |
| 24 | self.failUnlessEqual(num_updated, 20) |
| 25 | cnt=B.objects.filter(y=100).count() |
| 26 | self.failUnlessEqual(cnt, 20) |
| 27 | |
| 28 | def test_empty_update(self): |
| 29 | """ |
| 30 | Test that update changes that right number of rows for an empty queryset |
| 31 | """ |
| 32 | |
| 33 | num_updated=self.a2.b_set.update(y=100) |
| 34 | self.failUnlessEqual(num_updated, 0) |
| 35 | cnt=B.objects.filter(y=100).count() |
| 36 | self.failUnlessEqual(cnt, 0) |
| 37 | |
| 38 | def test_nonempty_update_with_inheritance(self): |
| 39 | """ |
| 40 | Test that update changes that right number of rows for an empty queryset |
| 41 | when the update affects only a base table |
| 42 | """ |
| 43 | |
| 44 | num_updated=self.a1.d_set.update(y=100) |
| 45 | self.failUnlessEqual(num_updated, 20) |
| 46 | cnt=D.objects.filter(y=100).count() |
| 47 | self.failUnlessEqual(cnt, 20) |
| 48 | |
| 49 | |
| 50 | def test_empty_update_with_inheritance(self): |
| 51 | """ |
| 52 | Test that update changes that right number of rows for an empty queryset |
| 53 | when the update affects only a base table |
| 54 | """ |
| 55 | |
| 56 | num_updated=self.a2.d_set.update(y=100) |
| 57 | self.failUnlessEqual(num_updated, 0) |
| 58 | cnt=D.objects.filter(y=100).count() |
| 59 | self.failUnlessEqual(cnt, 0) |