kopia lustrzana https://github.com/wagtail/wagtail
Fix documents tests on Windows (#5752)
As documents are streamed, the files are not closed until the datastream has been fully consumed by the test. But most of the documents tests never do this. On Windows, files must be closed before deleting them. This change makes the tests always consume the file so that they are closed before deleting them.pull/5865/head
rodzic
78cc81c505
commit
d48d3dfc5b
wagtail/documents/tests
|
@ -18,12 +18,20 @@ class TestServeView(TestCase):
|
|||
self.document.file.save('example.doc', ContentFile("A boring example document"))
|
||||
|
||||
def tearDown(self):
|
||||
if hasattr(self, 'response'):
|
||||
# Make sure the response is fully read before deleting the document so
|
||||
# that the file is closed by the view.
|
||||
# This is required on Windows as the below line that deletes the file
|
||||
# will crash if the file is still open.
|
||||
b"".join(self.response.streaming_content)
|
||||
|
||||
# delete the FieldFile directly because the TestCase does not commit
|
||||
# transactions to trigger transaction.on_commit() in the signal handler
|
||||
self.document.file.delete()
|
||||
|
||||
def get(self):
|
||||
return self.client.get(reverse('wagtaildocs_serve', args=(self.document.id, self.document.filename)))
|
||||
self.response = self.client.get(reverse('wagtaildocs_serve', args=(self.document.id, self.document.filename)))
|
||||
return self.response
|
||||
|
||||
def test_response_code(self):
|
||||
self.assertEqual(self.get().status_code, 200)
|
||||
|
|
Ładowanie…
Reference in New Issue