annotate examples/project/zoo/test_race.py @ 5:22ae9aa457af

excercise more bits of the django 1.0b1 test framework
author Victor Ng <victor@monkeybean.ca>
date Thu, 28 Aug 2008 11:29:21 -0400
parents
children
rev   line source
5
22ae9aa457af excercise more bits of the django 1.0b1 test framework
Victor Ng <victor@monkeybean.ca>
parents:
diff changeset
1 # We have two test classes because we want to induce a race condition
22ae9aa457af excercise more bits of the django 1.0b1 test framework
Victor Ng <victor@monkeybean.ca>
parents:
diff changeset
2 # and ensure that the database is always reset between test methods
22ae9aa457af excercise more bits of the django 1.0b1 test framework
Victor Ng <victor@monkeybean.ca>
parents:
diff changeset
3
22ae9aa457af excercise more bits of the django 1.0b1 test framework
Victor Ng <victor@monkeybean.ca>
parents:
diff changeset
4 from zoo.models import *
22ae9aa457af excercise more bits of the django 1.0b1 test framework
Victor Ng <victor@monkeybean.ca>
parents:
diff changeset
5
22ae9aa457af excercise more bits of the django 1.0b1 test framework
Victor Ng <victor@monkeybean.ca>
parents:
diff changeset
6 class TestDBRace1(object):
22ae9aa457af excercise more bits of the django 1.0b1 test framework
Victor Ng <victor@monkeybean.ca>
parents:
diff changeset
7 def setup(self):
22ae9aa457af excercise more bits of the django 1.0b1 test framework
Victor Ng <victor@monkeybean.ca>
parents:
diff changeset
8 assert Zoo.objects.count() == 0
22ae9aa457af excercise more bits of the django 1.0b1 test framework
Victor Ng <victor@monkeybean.ca>
parents:
diff changeset
9
22ae9aa457af excercise more bits of the django 1.0b1 test framework
Victor Ng <victor@monkeybean.ca>
parents:
diff changeset
10 def test1(self):
22ae9aa457af excercise more bits of the django 1.0b1 test framework
Victor Ng <victor@monkeybean.ca>
parents:
diff changeset
11 obj = Zoo.objects.create(name='sample1')
22ae9aa457af excercise more bits of the django 1.0b1 test framework
Victor Ng <victor@monkeybean.ca>
parents:
diff changeset
12 assert Zoo.objects.count() == 1
22ae9aa457af excercise more bits of the django 1.0b1 test framework
Victor Ng <victor@monkeybean.ca>
parents:
diff changeset
13 assert Zoo.objects.all()[0].name == 'sample1'
22ae9aa457af excercise more bits of the django 1.0b1 test framework
Victor Ng <victor@monkeybean.ca>
parents:
diff changeset
14
22ae9aa457af excercise more bits of the django 1.0b1 test framework
Victor Ng <victor@monkeybean.ca>
parents:
diff changeset
15
22ae9aa457af excercise more bits of the django 1.0b1 test framework
Victor Ng <victor@monkeybean.ca>
parents:
diff changeset
16 class TestDBRace2(object):
22ae9aa457af excercise more bits of the django 1.0b1 test framework
Victor Ng <victor@monkeybean.ca>
parents:
diff changeset
17 def setup(self):
22ae9aa457af excercise more bits of the django 1.0b1 test framework
Victor Ng <victor@monkeybean.ca>
parents:
diff changeset
18 assert Zoo.objects.count() == 0
22ae9aa457af excercise more bits of the django 1.0b1 test framework
Victor Ng <victor@monkeybean.ca>
parents:
diff changeset
19
22ae9aa457af excercise more bits of the django 1.0b1 test framework
Victor Ng <victor@monkeybean.ca>
parents:
diff changeset
20 def test1(self):
22ae9aa457af excercise more bits of the django 1.0b1 test framework
Victor Ng <victor@monkeybean.ca>
parents:
diff changeset
21 obj = Zoo.objects.create(name='sample2')
22ae9aa457af excercise more bits of the django 1.0b1 test framework
Victor Ng <victor@monkeybean.ca>
parents:
diff changeset
22 assert Zoo.objects.count() == 1
22ae9aa457af excercise more bits of the django 1.0b1 test framework
Victor Ng <victor@monkeybean.ca>
parents:
diff changeset
23 assert Zoo.objects.all()[0].name == 'sample2'