Question

So I'm doing some unittests on a particular Django app. When in a testing environment, I basically create a fresh database with my own data.

In a normal non-testing environment, I load up a page with a person's details. When this happens a signal is sent and it retrieves the person's picture (which is in a different app) and some other certain data (which is also in a different app).

So in my testing I have used fixtures to get all of the relevant data for the people who I create in the testing database. But I can't work out how to do this with the pictures...Can I create two lots of 'fixtures'?

The first test I am trying is ever so simple

resp = self.client.get(reverse('person_detail', kwargs={'id': 'blobby'}))
self.assertEqual(resp.status_code, 200)

So 'person_detail' is a named url I have and it successfully gets the "other data" using the fixtures, but I somehow need it to get a picture as my test(s) fail with the message 'Pic matching query does not exist'. Even just giving all of my test database people a default picture would be great. Anyone got any ideas about how to approach this? The pictures are saved on file...

Was it helpful?

Solution

In your TestCase class, include a setUp() function that pulls in the pictures for everyone. (https://docs.djangoproject.com/en/dev/topics/testing/overview/)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top