Skip to content
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

Merged
merged 9 commits into from
Nov 5, 2024

Conversation

RuthShryock
Copy link
Member

@RuthShryock RuthShryock commented Oct 31, 2024

Checklist

  1. If you've added code that should be tested, add tests
  2. If you've changed APIs, update (or create!) the documentation
  3. Ensure the tests pass
  4. Run ./python-format.sh to make sure that your code lints and that you've followed our coding style
  5. Write a title and, if necessary, a description of your work suitable for publishing in our release notes
  6. Mention any related issues in this repository (as #ISSUE) and in other repositories (as kobotoolbox/other#ISSUE)
  7. Open an issue in the docs if there are UI/UX changes
  8. Create a testing plan for the reviewer and add it to the Testing section
  9. Add frontend or backend tag and any other appropriate tags to this pull request

Description

Refactor our export task function to handle different project type inputs.

Notes

send_mail is now accessed via the mail module instead of being imported directly. This was changed to allow for mocking of send_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.

Copy link

@RuthShryock RuthShryock changed the title feat(AccessLogsExport): refactor export in background TASK-1145 refactor(AccessLogsExport): refactor export in background TASK-1145 Nov 1, 2024
@RuthShryock RuthShryock changed the title refactor(AccessLogsExport): refactor export in background TASK-1145 refactor(AccessLogsExport): export in background TASK-1145 Nov 1, 2024
from kpi.tasks import export_task_in_background


class ExportTaskInBackgroundTests(TestCase):
Copy link
Contributor

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

Suggested change
class ExportTaskInBackgroundTests(TestCase):
@patch('django.core.mail.send_mail')
@patch('kobo.apps.project_views.models.project_view.ProjectView.objects.get')
class ExportTaskInBackgroundTests(TestCase):

self.task.refresh_from_db()
self.assertEqual(self.task.status, 'complete')

mock_send_mail.assert_called_once()
Copy link
Contributor

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}')
Copy link
Contributor

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.

Copy link
Contributor

@rgraber rgraber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Nice job!

@RuthShryock RuthShryock merged commit b600156 into main Nov 5, 2024
7 checks passed
@RuthShryock RuthShryock deleted the refactor-export-in-background branch November 5, 2024 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants