Skip to content

Commit

Permalink
fix: use django storage to handle file objects (#5325)
Browse files Browse the repository at this point in the history
### 📣 Summary
For dev interests. Replace `open` and `os.path` with Django storage
utility (i.e: `from django.core.files.storage import default_storage`)
  • Loading branch information
noliveleger authored Dec 4, 2024
1 parent f5e9183 commit 70407e3
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions kpi/tests/test_access_logs_export_task.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import csv
import os

from django.conf import settings
from django.test import TestCase
from django.core.files.storage import default_storage

from kobo.apps.audit_log.models import AccessLog
from kobo.apps.kobo_auth.shortcuts import User
Expand Down Expand Up @@ -62,8 +62,8 @@ def test_run_task_creates_csv(self):
'The task.result file name format is incorrect.',
)
self.assertTrue(
os.path.exists(task.result.path),
f'The file at {task.result.path} should exist.',
default_storage.exists(str(task.result)),
f'The file at {str(task.result)} should exist.',
)

def test_csv_content_structure(self):
Expand All @@ -82,7 +82,7 @@ def test_csv_content_structure(self):
task = self.create_export_task(self.superuser)
task.run()

with open(task.result.path, mode='r', encoding='utf-8') as csv_file:
with default_storage.open(str(task.result), mode='r') as csv_file:
reader = csv.DictReader(csv_file)
rows = list(reader)

Expand Down

0 comments on commit 70407e3

Please sign in to comment.