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

1025 - Add test_dispatch_to_batch #1042

Open
wants to merge 13 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions api/scpca_portal/test/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,15 @@ class Meta:
class ProjectFactory(LeafProjectFactory):
computed_file1 = factory.RelatedFactory(ProjectComputedFileFactory, "project")
sample1 = factory.RelatedFactory(SampleFactory, "project")
library1 = factory.RelatedFactory(LibraryFactory, "project")
summary1 = factory.RelatedFactory(ProjectSummaryFactory, factory_related_name="project")

@factory.post_generation
def add_sample_library_relation(self, create, extracted, **kwargs):
if not create:
return
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a doc string that explains the many to many consideration here


sample = self.samples.first()
library = self.libraries.first()

sample.libraries.add(library)
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from functools import partial
from unittest.mock import patch

from django.core.management import call_command
from django.test import TestCase

from scpca_portal.test.factories import ProjectFactory


class TestLoadData(TestCase):
def setUp(self):
self.dispatch_to_batch = partial(call_command, "dispatch_to_batch")

@patch("scpca_portal.management.commands.dispatch_to_batch.Command.submit_job")
def test_only_projects_without_computed_files_submitted(self, mock_submit_job):
project_with_files = ProjectFactory()

project_no_files = ProjectFactory()
project_no_files.computed_files.delete()

# TODO: remove this patch when we get rid of sample computed file generation
with patch("scpca_portal.models.Project.samples_to_generate", []):
self.dispatch_to_batch()
mock_submit_job.assert_called()

submitted_project_ids = set(
call.kwargs["project_id"] for call in mock_submit_job.call_args_list
)
self.assertIn(project_no_files.scpca_id, submitted_project_ids)
self.assertNotIn(project_with_files.scpca_id, submitted_project_ids)

@patch("scpca_portal.management.commands.dispatch_to_batch.Command.submit_job")
def test_project_id_submission(self, mock_submit_job):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def test_project_id_submission(self, mock_submit_job):
def test_project_id_argument(self, mock_submit_job):

project = ProjectFactory()

# TODO: remove this patch when we get rid of sample computed file generation
with patch("scpca_portal.models.Project.samples_to_generate", []):
self.dispatch_to_batch(project_id=project.scpca_id)
mock_submit_job.assert_called()

submitted_project_id = mock_submit_job.call_args.kwargs["project_id"]
self.assertEqual(project.scpca_id, submitted_project_id)
Loading