Skip to content

Commit

Permalink
Fix unit tests with FileSystemStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
noliveleger committed Aug 8, 2024
1 parent 244c38e commit be7505e
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
default_kobocat_storage as default_storage,
)


class TestAttachment(TestBase):

def setUp(self):
Expand Down
3 changes: 1 addition & 2 deletions kobo/apps/openrosa/libs/utils/image_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,10 @@ def _save_thumbnails(image, original_path, size, suffix):

def resize(filename):
image = None

if isinstance(default_storage, FileSystemStorage):
path = default_storage.path(filename)
image = Image.open(path)
original_path = path
original_path = filename
else:
path = default_storage.url(filename)
original_path = filename
Expand Down
7 changes: 0 additions & 7 deletions kobo/settings/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,3 @@
TEST_USERNAME = 'bob'

OPENROSA_DB_ALIAS = DEFAULT_DB_ALIAS

# STORAGES['default']['BACKEND'] = 'django.core.files.storage.FileSystemStorage'
# KOBOCAT_DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage'
# KOBOCAT_MEDIA_ROOT = os.environ.get(
# 'KOBOCAT_MEDIA_ROOT', MEDIA_ROOT.replace('kpi', 'kobocat')
# )
# PASSWORD_HASHERS = ['django.contrib.auth.hashers.MD5PasswordHasher']
6 changes: 3 additions & 3 deletions kpi/tests/api/v1/test_api_submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ def test_list_submissions_as_owner_with_params(self):
'limit': 5,
'sort': '{"q1": -1}',
'fields': '["q1", "_submitted_by"]',
'query': '{"_submitted_by": {"$in": ["unknown", "someuser", "another"]}}',
'query': '{"_submitted_by": {"$in": ["unknownuser", "someuser", "anotheruser"]}}',
}
)
# ToDo add more assertions. E.g. test whether sort, limit, start really work
self.assertEqual(len(response.data), 5)
self.assertEqual(response.status_code, status.HTTP_200_OK)

def test_delete_submission_as_owner(self):
submission = self.get_random_submission(self.asset.owner)
submission = self.submissions_submitted_by_someuser[0]
url = reverse(
self._get_endpoint('submission-detail'),
kwargs={
Expand All @@ -116,7 +116,7 @@ def test_delete_submission_as_owner(self):
def test_delete_submission_shared_as_anotheruser(self):
self.asset.assign_perm(self.anotheruser, PERM_VIEW_SUBMISSIONS)
self._log_in_as_another_user()
submission = self.get_random_submission(self.asset.owner)
submission = self.submissions_submitted_by_someuser[0]
url = reverse(
self._get_endpoint('submission-detail'),
kwargs={
Expand Down
4 changes: 3 additions & 1 deletion kpi/tests/api/v2/test_api_attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ def test_duplicate_attachment_with_submission(self):
duplicate_file = response.data

# Ensure that the files are the same
assert original_file.read() == duplicate_file.read()
with default_storage.open(str(original_file), 'rb') as of:
with default_storage.open(str(duplicate_file), 'rb') as df:
assert of.read() == df.read()

def test_xpath_not_found(self):
query_dict = QueryDict('', mutable=True)
Expand Down
Loading

0 comments on commit be7505e

Please sign in to comment.