Skip to content

Commit

Permalink
Move test for mock API to test_mgx_api.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KateSakharova committed Oct 23, 2023
1 parent 481a4d5 commit b1f348c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
20 changes: 0 additions & 20 deletions tests/me/test_metagenomics_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
# -*- coding: utf-8 -*-

import pytest
from unittest import mock

from emgapi.metagenomics_exchange import MetagenomicsExchangeAPI

import requests
import responses
import settings


class TestME:
def test_check_existing_analysis(self):
Expand All @@ -28,19 +24,3 @@ def test_post_existing_analysis(self):
# Should return -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409
with pytest.raises(requests.HTTPError, match="409 Client Error"):
me_api.add_record(mgya=source_id, run_accession="ERR3063408", public=True).json()

@responses.activate
def test_mock_post_new_analysis(self):
me_api = MetagenomicsExchangeAPI()
endpoint = "datasets"
url = settings.ME_API + f"/{endpoint}"

responses.add(responses.POST, url, json={'success': True}, status=201)

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

assert response.status_code == 201
assert response.json() == {'success': True}



17 changes: 17 additions & 0 deletions tests/me/test_mgx_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,31 @@
# limitations under the License.

import pytest
import responses
from unittest.mock import patch

from django.core.management import call_command
import settings

from test_utils.emg_fixtures import * # noqa

from emgapi.metagenomics_exchange import MetagenomicsExchangeAPI
from emgapi.models import AnalysisJob, MetagenomicsExchange, ME_Broker

class TestMockResponse:
@responses.activate
def test_mock_post_new_analysis(self):
me_api = MetagenomicsExchangeAPI()
endpoint = "datasets"
url = settings.ME_API + f"/{endpoint}"

responses.add(responses.POST, url, json={'success': True}, status=201)

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

assert response.status_code == 201
assert response.json() == {'success': True}

@pytest.mark.django_db
class TestMeAPI:
@patch("emgapi.metagenomics_exchange.MetagenomicsExchangeAPI.post_request")
Expand Down

0 comments on commit b1f348c

Please sign in to comment.