Ticket #12615: tests.py

File tests.py, 1000 bytes (added by yxven, 15 years ago)
Line 
1from bug.models import *
2from django.test import TestCase
3
4class BugTest(TestCase):
5 def setUp(self):
6 self.bob = Person(name = "Bob")
7 self.bob.save()
8
9 z1 = Zipcode()
10 z1.save()
11 z1p = ZipcodePerson(zipcode = z1, person = self.bob)
12 z1p.save()
13
14 z2 = Zipcode()
15 z2.save()
16 z2p = ZipcodePerson(zipcode = z2, person = self.bob)
17 z2p.save()
18 def test_bug(self):
19 zipcodes = Zipcode.objects.filter(people = self.bob)
20 values= zipcodes.values()
21 self.assertEqual(zipcodes.values().__str__(), "[{'id': 1}, {'id': 2}]")
22 self.assertEqual(zipcodes[1].id, 2)
23 self.assertEqual(zipcodes[0].id, 1)
24 #this fails with zipcodes[1] equal to 2
25 def test_this_works(self):
26 zipcodes = Zipcode.objects.all()
27 self.assertEqual(zipcodes.values().__str__(), "[{'id': 3}, {'id': 4}]")
28 self.assertEqual(zipcodes[1].id, 4)
29 self.assertEqual(zipcodes[0].id, 3)
30
31
Back to Top