Skip to content

Commit

Permalink
(edit) replace command classes with call_command in test_create_porta…
Browse files Browse the repository at this point in the history
…l_metadata, and remove return statement in create_portal_metadata management command
  • Loading branch information
nozomione committed Sep 11, 2024
1 parent b623c08 commit 8933941
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ def create_portal_metadata(self, clean_up_output_data: bool, update_s3: bool, **
logger.info("Cleaning up the output directory")
computed_file.clean_up_local_computed_file()

return computed_file

def purge_computed_file(self, computed_file, update_s3=False):
if update_s3:
logger.info("Deleting the zip from S3")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import csv
import shutil
from functools import partial
from io import TextIOWrapper
from typing import Dict
from unittest.mock import patch
from zipfile import ZipFile

from django.conf import settings
from django.core.management import call_command
from django.test import TransactionTestCase

from scpca_portal import common, metadata_file, readme_file
from scpca_portal.management.commands import create_portal_metadata, load_data
from scpca_portal.models import ComputedFile, Library, Project, Sample

# NOTE: Test data bucket is defined in `scpca_porta/common.py`.
Expand All @@ -23,8 +24,8 @@

class TestCreatePortalMetadata(TransactionTestCase):
def setUp(self):
self.processor = create_portal_metadata.Command()
self.loader = load_data.Command()
self.create_portal_metadata = partial(call_command, "create_portal_metadata")
self.load_data = partial(call_command, "load_data")

@classmethod
def tearDownClass(cls):
Expand All @@ -37,12 +38,11 @@ def load_test_data(self):
SAMPLES_COUNT = 9
LIBRARIES_COUNT = 7

self.loader.load_data(
self.load_data(
input_bucket_name=settings.AWS_S3_INPUT_BUCKET_NAME,
clean_up_input_data=False,
clean_up_output_data=False,
max_workers=4,
reload_all=False,
reload_existing=False,
scpca_project_id="",
update_s3=False,
Expand Down Expand Up @@ -74,7 +74,7 @@ def test_create_portal_metadata(self, mock_upload_output_file):
# Set up the database for test
self.load_test_data()
# Create the portal metadata computed file
self.processor.create_portal_metadata(clean_up_output_data=False, update_s3=True)
self.create_portal_metadata(clean_up_output_data=False, update_s3=True)

# Test the computed file
computed_files = ComputedFile.objects.filter(portal_metadata_only=True)
Expand Down Expand Up @@ -143,8 +143,8 @@ def test_only_one_computed_file_at_any_point(self, mock_delete_output_file):
# Set up the database for test
self.load_test_data()
# Make sure pre-existing computed_file has been deleted and only one exists
self.processor.create_portal_metadata(clean_up_output_data=False, update_s3=True)
self.processor.create_portal_metadata(clean_up_output_data=False, update_s3=True)
self.create_portal_metadata(clean_up_output_data=False, update_s3=True)
self.create_portal_metadata(clean_up_output_data=False, update_s3=True)
computed_files = ComputedFile.objects.filter(portal_metadata_only=True)
self.assertEqual(computed_files.count(), 1)
# Make sure mock_delete_output_file can be called with computed_file field values
Expand Down

0 comments on commit 8933941

Please sign in to comment.