Skip to content

Commit

Permalink
Fix typos in method args
Browse files Browse the repository at this point in the history
  • Loading branch information
mberacochea committed Feb 16, 2024
1 parent b2d60bd commit e3e9cfb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 38 deletions.
9 changes: 4 additions & 5 deletions emgapi/management/commands/populate_metagenomics_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,14 @@ def process_to_index_and_update_records(self, analyses_to_index_and_update):
):
jobs_to_update = []
for annotation_job in page:

sequence_accession = ""
if annotation_job.run:
sequence_accession = annotation_job.run.accession
if annotation_job.assembly:
sequence_accession = annotation_job.assembly.accession

metadata = self.mgx_api.generate_metadata(
mgya=annotation_job.accession, run_accession=sequence_accession
mgya=annotation_job.accession, sequence_accession=sequence_accession
)
registry_id, metadata_match = self.mgx_api.check_analysis(
mgya=annotation_job.accession,
Expand All @@ -129,7 +128,8 @@ def process_to_index_and_update_records(self, analyses_to_index_and_update):
continue

response = self.mgx_api.add_analysis(
mgya=annotation_job.accession, run_accession=annotation_job.run
mgya=annotation_job.accession,
sequence_accession=annotation_job.run,
)
if response.ok:
logging.info(f"Successfully added {annotation_job}")
Expand Down Expand Up @@ -193,15 +193,14 @@ def process_to_delete_records(self, analyses_to_delete):
jobs_to_update = []

for annotation_job in page:

sequence_accession = ""
if annotation_job.run:
sequence_accession = annotation_job.run.accession
if annotation_job.assembly:
sequence_accession = annotation_job.assembly.accession

metadata = self.mgx_api.generate_metadata(
mgya=annotation_job.accession, run_accession=annotation_job.run
mgya=annotation_job.accession, sequence_accession=sequence_accession
)
registry_id, _ = self.mgx_api.check_analysis(
mgya=annotation_job.accession,
Expand Down
25 changes: 10 additions & 15 deletions tests/me/test_metagenomics_exchange.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pytest
import logging
from unittest import mock

import pytest
import requests
import responses
from django.conf import settings

from emgapi.metagenomics_exchange import MetagenomicsExchangeAPI

import requests
import responses
from unittest import mock


class TestME:

def test_check_existing_analysis_me(self):
me_api = MetagenomicsExchangeAPI()
source_id = "MGYA00293719"
seq_id = "ERR3063408"
return_values = me_api.check_analysis(source_id, seq_id, True)
mgya = "MGYA00293719"
sequence_accession = "ERR3063408"
return_values = me_api.check_analysis(mgya, sequence_accession)
assert return_values[0]

def test_check_not_existing_analysis_me(self):
me_api = MetagenomicsExchangeAPI()
source_id = "MGYA10293719"
seq_id = "ERR3063408"
return_values = me_api.check_analysis(source_id, seq_id, True)
return_values = me_api.check_analysis(source_id, seq_id)
assert not return_values[0]

@pytest.mark.skip(reason="Error on ME API side")
Expand All @@ -35,9 +32,7 @@ def test_post_existing_analysis_me(self):
source_id = "MGYA00293719"
# Should return -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409
with pytest.raises(requests.HTTPError, match="401 Client Error"):
me_api.add_analysis(
mgya=source_id, run_accession="ERR3063408", public=True
).json()
me_api.add_analysis(mgya=source_id, sequence_accession="ERR3063408").json()

@responses.activate
def test_mock_post_new_analysis(self):
Expand All @@ -48,7 +43,7 @@ def test_mock_post_new_analysis(self):
responses.add(responses.POST, url, json={"success": True}, status=201)

response = me_api.add_analysis(
mgya="MGYA00593709", run_accession="SRR3960575", public=True
mgya="MGYA00593709", sequence_accession="SRR3960575"
)

assert response.status_code == 201
Expand Down
28 changes: 10 additions & 18 deletions tests/me/test_populate_metagenomics_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ def test_population_dry_mode(self, caplog):
assert "Dry-mode run: no addition to real ME for MGYA00466090" in caplog.text
assert "Dry-mode run: no addition to real ME for MGYA00466091" in caplog.text
assert "Processing 1 analyses to remove" in caplog.text
assert "MGYA00005678 doesn't exist in the registry, nothing to delete" in caplog.text

assert (
"MGYA00005678 doesn't exist in the registry, nothing to delete"
in caplog.text
)

@pytest.mark.usefixtures("run_multiple_analysis_me")
@mock.patch("emgapi.metagenomics_exchange.MetagenomicsExchangeAPI.add_analysis")
Expand All @@ -56,16 +58,18 @@ def test_add_new_analysis(self, mock_check_analysis, mock_add_analysis, caplog):
"""
pipeline = 4.1
registry_id = "MGX1"

class MockResponse:
def __init__(self, json_data, status_code):
self.json_data = json_data
self.status_code = status_code
self.ok = True

def json(self):
return self.json_data

def mock_check_process(*args, **kwargs):
if 'metadata' in kwargs:
if "metadata" in kwargs:
return None, True
else:
return registry_id, True
Expand All @@ -84,14 +88,10 @@ def mock_check_process(*args, **kwargs):
assert ajob.last_mgx_indexed
assert ajob.mgx_accession == registry_id


@pytest.mark.usefixtures("run_multiple_analysis_me")
@mock.patch("emgapi.metagenomics_exchange.MetagenomicsExchangeAPI.check_analysis")
@mock.patch("emgapi.metagenomics_exchange.MetagenomicsExchangeAPI.delete_analysis")
def test_removals(self,
mock_delete_analysis,
mock_check_analysis,
caplog):
def test_removals(self, mock_delete_analysis, mock_check_analysis, caplog):
"""
Test delete process.
1 analysis should be removed and updated indexed field in DB
Expand All @@ -100,10 +100,7 @@ def test_removals(self,
mock_check_analysis.return_value = True, True
mock_delete_analysis.return_value = True

call_command(
"populate_metagenomics_exchange",
pipeline=pipeline
)
call_command("populate_metagenomics_exchange", pipeline=pipeline)
assert "Indexing 0 new analyses" in caplog.text
assert "Processing 1 analyses to remove" in caplog.text
assert "Deleting MGYA00005678" in caplog.text
Expand All @@ -114,10 +111,7 @@ def test_removals(self,
@pytest.mark.usefixtures("run_multiple_analysis_me")
@mock.patch("emgapi.metagenomics_exchange.MetagenomicsExchangeAPI.check_analysis")
@mock.patch("emgapi.metagenomics_exchange.MetagenomicsExchangeAPI.patch_analysis")
def test_update(self,
mock_patch_analysis,
mock_check_analysis,
caplog):
def test_update(self, mock_patch_analysis, mock_check_analysis, caplog):
"""
Test update process for job that was indexed before updated.
MGX accession and last_mgx_indexed should be updated
Expand All @@ -138,5 +132,3 @@ def test_update(self,
ajob = AnalysisJob.objects.filter(pipeline__release_version=pipeline).first()
assert ajob.last_mgx_indexed.date() == timezone.now().date()
assert ajob.mgx_accession == registry_id


0 comments on commit e3e9cfb

Please sign in to comment.