Fix documents tests on Windows ()

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
Karl Hobley 2020-02-25 23:21:32 +00:00 zatwierdzone przez GitHub
rodzic 78cc81c505
commit d48d3dfc5b
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 9 dodań i 1 usunięć
wagtail/documents/tests

Wyświetl plik

@ -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)