Caching Django Models? How to disable testing

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 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?

+3
source share
2 answers

factory_boy is a replacement for fixtures based on thinkbot factory_girl.

Rails, , factory_girl. .

+2

django - factory ?

, , "factory ". , Django , .

, , .

class AnimalTestCase(TestCase):
    fixtures = ['mammals.json', 'birds']

    def setUp(self):
    # Test definitions as before.
    call_setup_methods()

    def testFluffyAnimals(self):
    # A test that uses the fixtures.
    call_some_test_code()

, , python manage.py dumpdata

, , "Dummy Caching" .

django :

CACHE_BACKEND = 'dummy://'

localsettings.py .

+1

Source: https://habr.com/ru/post/1732521/


All Articles