简体   繁体   English

Django测试,需要图片夹具

[英]Django testing, need fixtures for picture

So I'm doing some unittests on a particular Django app. 因此,我正在特定的Django应用程序上进行一些单元测试。 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'. 因此,“ person_detail”是我拥有的一个已命名的url,它使用固定装置成功获取了“其他数据”,但是由于测试失败并显示消息“ Pic匹配查询不存在”,我以某种方式需要它来获取图片。 。 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... 图片已保存在文件中...

In your TestCase class, include a setUp() function that pulls in the pictures for everyone. 在您的TestCase类中,包括一个setUp()函数,该函数为所有人提取图片。 ( https://docs.djangoproject.com/en/dev/topics/testing/overview/ ) https://docs.djangoproject.com/en/dev/topics/testing/overview/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM