现在我只检查这种联系的对策:
self.client = Client()
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
是否有Django-ic途径测试一个链接,看看是否实际进行了档案下载活动? 在这个问题上似乎找不到很多资源。
现在我只检查这种联系的对策:
self.client = Client()
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
是否有Django-ic途径测试一个链接,看看是否实际进行了档案下载活动? 在这个问题上似乎找不到很多资源。
如果尿液意在生成一个文档而不是一个“热”的回复,则其<代码>连续型和/或content-disposition
将有所不同。
答复对象基本上是一个字典,因此你可以这样作。
self.assertEquals(
response.get( Content-Disposition ),
"attachment; filename=mypic.jpg"
)
UPD: If you want to read the actual contents of the attached file, you can use response.content. Example for a zip file:
try:
f = io.BytesIO(response.content)
zipped_file = zipfile.ZipFile(f, r )
self.assertIsNone(zipped_file.testzip())
self.assertIn( my_file.txt , zipped_file.namelist())
finally:
zipped_file.close()
f.close()
如果您的返回是FileResponse,那么,你需要知道它会返回一个连续。
{AttributeError}AttributeError( This FileResponse instance has no `content` attribute. Use `streaming_content` instead. )
你们需要首先评价整个流层——连续,然后从缓冲中读。
import io
with io.BytesIO(b"".join(response.streaming_content)) as buf_bytes:
loaded_response_content = buf_bytes.read()
What do software engineers encounter after another stressfull release? Well, the first thing we encounter in our group are the bugs we have released out in the open. The biggest problem that we as ...
I have some funny noob problem. I try to run unit tests from commandline: H:PROpyEstimator>python src estpython est_power_estimator.py Traceback (most recent call last): File "src est...
I´m working on a huge project at my work. We have about 200 database tables, accordingly a huge number of Models, Actions and so on. How should I begin to write tests for this? My biggest problem ...
Just wondering what people are using for code coverage tools when using MS Visual Studio 2008 Pro. We are using the built-in MS test project and unit testing tool (the one that come pre-installed ...
Say you have this shell of a class: public class Number { private int value; public Number() : this(0) {} public Number(int initialValue) : this(initialValue, 0, 100) {} ...
I have a C++ legacy codebase with 10-15 applications, all sharing several components. While setting up unittests for both shared components and for applications themselves, I was wondering if there ...
There s a bug/feature in Visual Studio 2010 where you can t create a unit test project with the 2.0 CLR. https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=483891&wa=...
Is there a simple (Attribute-driven) way to have the following test fail on the message of the exception. [TestMethod()] [ExpectedException(typeof(ArgumentException))] public void ExceptionTestTest() ...