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
q2 = Question.objects.create(name="q2", text="q2", start_datetime=self.day_before, close_datetime=self.day_after, type=self.type)
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 have unexpected results in my get_current function, so I commented on this and tried to debug by typing the main query used inside the function, and also got strange results:
...
Installing index for ... model
[<Question: q1>, <Question: q2>]
[<Question: q2>]
.....
----------------------------------------------------------------------
Ran 5 tests in 3.125s
I am wondering why a QuerySet with the same arguments returns the first invalid data, but in the following way - correctly and how can I avoid it?
Btw, does the django world have something like a rail factory for creating test data?
source
share