From 1f2ec72f1cce0ca9c0fd478238660a698a0ffed5 Mon Sep 17 00:00:00 2001 From: Sandy Rogers Date: Thu, 2 May 2024 09:37:24 +0100 Subject: [PATCH] fixes regression bug with EBI Search dump commands, following refactoring for metagenomics exchange. also adds some simple e2e tests for ebisearch dump commands. (#352) --- .../commands/ebi_search_analysis_dump.py | 4 +- .../commands/ebi_search_study_dump.py | 4 +- emgcli/__init__.py | 2 +- pyproject.toml | 2 +- .../test_ebisearch_dump.py | 48 +++++++++++++++++++ .../test_metagenomics_exchange.py | 0 .../test_populate_metagenomics_exchange.py | 0 7 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 tests/external_indexing_services/test_ebisearch_dump.py rename tests/{me => external_indexing_services}/test_metagenomics_exchange.py (100%) rename tests/{me => external_indexing_services}/test_populate_metagenomics_exchange.py (100%) diff --git a/emgapi/management/commands/ebi_search_analysis_dump.py b/emgapi/management/commands/ebi_search_analysis_dump.py index 03edb30d3..2692de35d 100644 --- a/emgapi/management/commands/ebi_search_analysis_dump.py +++ b/emgapi/management/commands/ebi_search_analysis_dump.py @@ -172,9 +172,9 @@ def handle(self, *args, **options): analyses: QuerySet = AnalysisJob.objects_dump.available(None) if not is_full_snapshot: - analyses = AnalysisJob.objects_for_indexing.to_add() + analyses = AnalysisJob.objects_for_ebisearch_indexing.to_add() - removals = AnalysisJob.objects_for_indexing.to_delete() + removals = AnalysisJob.objects_for_ebisearch_indexing.to_delete() # produce incremental deletion file deletions_file = pathlib.Path(output_dir) / pathlib.Path('analyses-deletes.xml') diff --git a/emgapi/management/commands/ebi_search_study_dump.py b/emgapi/management/commands/ebi_search_study_dump.py index ee14b91c4..fb1262640 100644 --- a/emgapi/management/commands/ebi_search_study_dump.py +++ b/emgapi/management/commands/ebi_search_study_dump.py @@ -71,9 +71,9 @@ def handle(self, *args, **options): studies: QuerySet = Study.objects.available(None) if not is_full_snapshot: - studies = Study.objects_for_indexing.to_add() + studies = Study.objects_for_ebisearch_indexing.to_add() - removals = Study.objects_for_indexing.to_delete() + removals = Study.objects_for_ebisearch_indexing.to_delete() # produce incremental deletion file deletions_file = pathlib.Path(output_dir) / pathlib.Path('projects-deletes.xml') diff --git a/emgcli/__init__.py b/emgcli/__init__.py index 43e1294ff..b465c0679 100644 --- a/emgcli/__init__.py +++ b/emgcli/__init__.py @@ -1 +1 @@ -__version__: str = "2.4.45" +__version__: str = "2.4.46" diff --git a/pyproject.toml b/pyproject.toml index 4407d26c6..c44705362 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -117,7 +117,7 @@ max-line-length = 119 """ [tool.bumpversion] -current_version = "2.4.45" +current_version = "2.4.46" [[tool.bumpversion.files]] filename = "emgcli/__init__.py" diff --git a/tests/external_indexing_services/test_ebisearch_dump.py b/tests/external_indexing_services/test_ebisearch_dump.py new file mode 100644 index 000000000..065f1b7ac --- /dev/null +++ b/tests/external_indexing_services/test_ebisearch_dump.py @@ -0,0 +1,48 @@ +import os + +import pytest +from django.core.management import call_command + +from test_utils.emg_fixtures import * # noqa + +@pytest.mark.django_db(transaction=True) +@pytest.mark.usefixtures("experiment_type") +class TestEbiSearchDump: + def test_dump_studies(self, sample): + """Test ebi search dump studies""" + call_command( + "ebi_search_study_dump", "-o", f"/tmp/emg_dump_studies", + ) + assert os.path.exists(f"/tmp/emg_dump_studies/projects.xml") + assert os.path.isfile(f"/tmp/emg_dump_studies/projects.xml") + assert os.path.exists(f"/tmp/emg_dump_studies/projects-deletes.xml") + assert os.path.isfile(f"/tmp/emg_dump_studies/projects-deletes.xml") + + with open(f"/tmp/emg_dump_studies/projects.xml") as f: + dump = f.read() + assert "MGYS00001234" in dump + assert "1" in dump + + with open(f"/tmp/emg_dump_studies/projects-deletes.xml") as f: + dump = f.readlines() + assert len(dump) == 5 # i.e. no entries within the xml + + def test_dump_analyses(self, run_v5): + """Test ebi search dump analyses""" + call_command( + "ebi_search_analysis_dump", "-o", f"/tmp/emg_dump_analyses", + ) + assert os.path.exists(f"/tmp/emg_dump_analyses/analyses_0001.xml") + assert os.path.isfile(f"/tmp/emg_dump_analyses/analyses_0001.xml") + assert os.path.exists(f"/tmp/emg_dump_analyses/analyses-deletes.xml") + assert os.path.isfile(f"/tmp/emg_dump_analyses/analyses-deletes.xml") + + with open(f"/tmp/emg_dump_analyses/analyses_0001.xml") as f: + dump = f.read() + assert "MGYA00001234" in dump + assert "1" in dump + + with open(f"/tmp/emg_dump_analyses/analyses-deletes.xml") as f: + dump = f.readlines() + assert len(dump) == 5 # i.e. no entries within the xml + diff --git a/tests/me/test_metagenomics_exchange.py b/tests/external_indexing_services/test_metagenomics_exchange.py similarity index 100% rename from tests/me/test_metagenomics_exchange.py rename to tests/external_indexing_services/test_metagenomics_exchange.py diff --git a/tests/me/test_populate_metagenomics_exchange.py b/tests/external_indexing_services/test_populate_metagenomics_exchange.py similarity index 100% rename from tests/me/test_populate_metagenomics_exchange.py rename to tests/external_indexing_services/test_populate_metagenomics_exchange.py