Use compressed log file for upload test
The actual client sends zipped log files to the server, thus the test
should be aligned to do it the same way.
Issue: HIC-234
Change-Id: I76831113e3f98a3676784f59d4ccd55649049451
diff --git a/crashreports/tests/test_rest_api_logfiles.py b/crashreports/tests/test_rest_api_logfiles.py
index b646e2a..c55f4c9 100644
--- a/crashreports/tests/test_rest_api_logfiles.py
+++ b/crashreports/tests/test_rest_api_logfiles.py
@@ -1,7 +1,6 @@
"""Tests for the logfiles REST API."""
import os
-import tempfile
from django.urls import reverse
@@ -40,8 +39,8 @@
device_local_id = self._upload_crashreport(user, uuid)
# Upload a logfile for the crashreport
- logfile = tempfile.NamedTemporaryFile("w+", suffix=".log", delete=True)
- logfile.write(u"blihblahblub")
+ logfile = open(Dummy.DEFAULT_DUMMY_LOG_FILE_PATH, "rb")
+
response = user.post(
reverse(
self.PUT_LOGFILE_URL,
@@ -50,6 +49,7 @@
{"file": logfile},
format="multipart",
)
+ logfile.close()
self.assertEqual(status.HTTP_201_CREATED, response.status_code)
def test_logfile_upload_as_user(self):
diff --git a/crashreports/tests/utils.py b/crashreports/tests/utils.py
index 6ec7486..ac59231 100644
--- a/crashreports/tests/utils.py
+++ b/crashreports/tests/utils.py
@@ -1,5 +1,6 @@
"""Utility functions shared by all crashreports tests."""
+import os
from typing import Optional
from django.contrib.auth.models import User
@@ -72,6 +73,10 @@
"other": "whatever",
}
+ DEFAULT_DUMMY_LOG_FILE_PATH = os.path.join(
+ "resources", "test", "test_logfile.zip"
+ )
+
@staticmethod
def _update_copy(original, update):
"""Merge fields of update into a copy of original."""