First, the code of my tests.py
def test_get_current(self):
m = Member.objects.create(...)
q = Question.objects.create(name="q1", text="q1", start_datetime=self.day_before, close_datetime=self.day_after, type=self.type)
r = Response.objects.create(question=q, text='response')
expected = q, None
#self.assertEquals(expected, Question.objects.get_current(m.id))
q2 = Question.objects.create(name="q2", text="q2", start_datetime=self.day_before, close_datetime=self.day_after, type=self.type)
#print Question.objects.all()
#self.assertEquals(expected, Question.objects.get_current(m.id))
MemberResponse.objects.create(member=m, response=r)
print Question.objects.all().exclude(response__memberresponse__member=m)
print Question.objects.all().exclude(response__memberresponse__member=m)
I've got unexpected results in my get_current function, so, I commented it and tried to debug by printing main queryset used inside function and got also strange results:
...
Installing index for ... model
[<Question: q1>, <Question: q2>]
[<Question: q2>]
.....
----------------------------------------------------------------------
Ran 5 tests in 3.125s
I'm wondering, why QuerySet with the same arguments returns first wrong data, but by the next call - correct and how can I avoid it?
Btw, does django world have something similar to rail's factory girl for creating test data?