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