-
-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(AccessLogsExport): export in background TASK-1145 #5216
Conversation
…rtTask and add tests
from kpi.tasks import export_task_in_background | ||
|
||
|
||
class ExportTaskInBackgroundTests(TestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can patch the whole class at once instead of each individual method
class ExportTaskInBackgroundTests(TestCase): | |
@patch('django.core.mail.send_mail') | |
@patch('kobo.apps.project_views.models.project_view.ProjectView.objects.get') | |
class ExportTaskInBackgroundTests(TestCase): |
kpi/tests/test_export_tasks.py
Outdated
self.task.refresh_from_db() | ||
self.assertEqual(self.task.status, 'complete') | ||
|
||
mock_send_mail.assert_called_once() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shortcut: you can use assert_called_once_with
and pass the expected arguments
kpi/tasks.py
Outdated
) -> None: | ||
user = User.objects.get(username=username) | ||
|
||
export_task = ProjectViewExportTask.objects.get(uid=export_task_uid) | ||
export_task_class = apps.get_model(f'kpi.{export_task_name}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this will break if we have tasks defined outside kpi/tasks.py.
Better to just pass the fully qualified name of the task model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Nice job!
Checklist
./python-format.sh
to make sure that your code lints and that you've followed our coding styleDescription
Refactor our export task function to handle different project type inputs.
Notes
send_mail
is now accessed via themail
module instead of being imported directly. This was changed to allow for mocking ofsend_mail
in the tests.Testing
Most testing is covered by the tests but you can also ensure that the
Export all data
button in Project views is exporting data and sending an email.