Skip to content

Commit 8976a8e

Browse files
committed
Mocked remote calls in test_mw2isa #597
1 parent d1aa3a0 commit 8976a8e

File tree

4 files changed

+52
-5
lines changed

4 files changed

+52
-5
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"1":{"study_id":"ST000100","analysis_id":"AN000165","analysis_summary":"HESI positive ion mode","analysis_type":"MS","chromatography system":"Thermo Dionex Ultimate 3000 RS","column_name":"Waters Acquity HSS T3 (100 x 2.1mm,1.8um)","chromatography_type":"Reversed phase","ms_instrument_name":"Thermo Q Exactive Orbitrap","ms_instrument_type":"Orbitrap","ms_type":"ESI","ion_mode":"POSITIVE","nmr_instrument_type":"","nmr_experiment_type":"","spectrometer_frequency":"","nmr_solvent":"","units":""},"2":{"study_id":"ST000100","analysis_id":"AN000166","analysis_summary":"HESI negative ion mode","analysis_type":"MS","chromatography system":"Thermo Dionex Ultimate 3000 RS","column_name":"Waters Acquity HSS T3 (100 x 2.1mm,1.8um)","chromatography_type":"Reversed phase","ms_instrument_name":"Thermo Q Exactive Orbitrap","ms_instrument_type":"Orbitrap","ms_type":"ESI","ion_mode":"NEGATIVE","nmr_instrument_type":"","nmr_experiment_type":"","spectrometer_frequency":"","nmr_solvent":"","units":""},"3":{"study_id":"ST000101","analysis_id":"AN000167","analysis_summary":"NMR:13C 1D","analysis_type":"NMR","chromatography system":"","column_name":"","chromatography_type":"","ms_instrument_name":"","ms_instrument_type":"","ms_type":"","ion_mode":"","nmr_instrument_type":"FT-NMR","nmr_experiment_type":"1D 13C","spectrometer_frequency":"600 MHz","nmr_solvent":"D2O","units":""},"4":{"study_id":"ST000101","analysis_id":"AN000168","analysis_summary":"NMR: 1D 1H","analysis_type":"NMR","chromatography system":"","column_name":"","chromatography_type":"","ms_instrument_name":"","ms_instrument_type":"","ms_type":"","ion_mode":"","nmr_instrument_type":"FT-NMR","nmr_experiment_type":"1D 1H","spectrometer_frequency":"600 MHz","nmr_solvent":"D2O","units":""},"5":{"study_id":"ST000102","analysis_id":"AN000169","analysis_summary":"NMR: 1D presaturation 1H","analysis_type":"NMR","chromatography system":"","column_name":"","chromatography_type":"","ms_instrument_name":"","ms_instrument_type":"","ms_type":"","ion_mode":"","nmr_instrument_type":"FT-NMR","nmr_experiment_type":"1D 1H","spectrometer_frequency":"700 MHz","nmr_solvent":"D2O","units":""},"6":{"study_id":"ST000102","analysis_id":"AN000170","analysis_summary":"NMR: 2D 1H-13C HSQC","analysis_type":"NMR","chromatography system":"","column_name":"","chromatography_type":"","ms_instrument_name":"","ms_instrument_type":"","ms_type":"","ion_mode":"","nmr_instrument_type":"FT-NMR","nmr_experiment_type":"2D 1H-13C HSQC","spectrometer_frequency":"700 MHz","nmr_solvent":"D2O","units":""},"7":{"study_id":"ST000103","analysis_id":"AN000171","analysis_summary":"NMR:2D 1H-13C HSQC","analysis_type":"NMR","chromatography system":"","column_name":"","chromatography_type":"","ms_instrument_name":"","ms_instrument_type":"","ms_type":"","ion_mode":"","nmr_instrument_type":"FT-NMR","nmr_experiment_type":"2D-INADEQUATE","spectrometer_frequency":"600 MHz","nmr_solvent":"D2O and MeOD","units":""},"8":{"study_id":"ST000104","analysis_id":"AN000172","analysis_summary":"NMR:INADEQUATE","analysis_type":"NMR","chromatography system":"","column_name":"","chromatography_type":"","ms_instrument_name":"","ms_instrument_type":"","ms_type":"","ion_mode":"","nmr_instrument_type":"FT-NMR","nmr_experiment_type":"1D 1H","spectrometer_frequency":"700 MHz","nmr_solvent":"D20","units":""},"9":{"study_id":"ST000105","analysis_id":"AN000173","analysis_summary":"MS Q-TOF 6530 positive ion mode","analysis_type":"MS","chromatography system":"Agilent 1200","column_name":"Waters Acquity HSS T3","chromatography_type":"Reversed phase","ms_instrument_name":"Agilent 6530 QTOF","ms_instrument_type":"QTOF","ms_type":"ESI","ion_mode":"POSITIVE","nmr_instrument_type":"","nmr_experiment_type":"","spectrometer_frequency":"","nmr_solvent":"","units":"Counts"},"10":{"study_id":"ST000105","analysis_id":"AN000174","analysis_summary":"ESI negative ion mode","analysis_type":"MS","chromatography system":"Agilent 1200","column_name":"Waters Acquity HSS T3","chromatography_type":"Reversed phase","ms_instrument_name":"Agilent 6530 QTOF","ms_instrument_type":"QTOF","ms_type":"ESI","ion_mode":"NEGATIVE","nmr_instrument_type":"","nmr_experiment_type":"","spectrometer_frequency":"","nmr_solvent":"","units":"Counts"},"11":{"study_id":"ST000106","analysis_id":"AN000175","analysis_summary":"ESI positive ion mode","analysis_type":"MS","chromatography system":"Agilent 1200","column_name":"Waters Acquity HSS T3","chromatography_type":"Reversed phase","ms_instrument_name":"Agilent 6530 QTOF","ms_instrument_type":"QTOF","ms_type":"ESI","ion_mode":"POSITIVE","nmr_instrument_type":"","nmr_experiment_type":"","spectrometer_frequency":"","nmr_solvent":"","units":"Counts"},"12":{"study_id":"ST000106","analysis_id":"AN000176","analysis_summary":"ESI negative ion mode","analysis_type":"MS","chromatography system":"Agilent 1200","column_name":"Waters Acquity HSS T3","chromatography_type":"Reversed phase","ms_instrument_name":"Agilent 6530 QTOF","ms_instrument_type":"QTOF","ms_type":"ESI","ion_mode":"NEGATIVE","nmr_instrument_type":"","nmr_experiment_type":"","spectrometer_frequency":"","nmr_solvent":"","units":"Counts"},"13":{"study_id":"ST000107","analysis_id":"AN000177","analysis_summary":"LCMS Positive ion mode","analysis_type":"MS","chromatography system":"","column_name":"","chromatography_type":"GC","ms_instrument_name":"ABI Sciex API 4000 QTrap","ms_instrument_type":"Triple quadrupole","ms_type":"ESI","ion_mode":"POSITIVE","nmr_instrument_type":"","nmr_experiment_type":"","spectrometer_frequency":"","nmr_solvent":"","units":"nM"},"14":{"study_id":"ST000107","analysis_id":"AN000178","analysis_summary":"GCMS Positive ion mode","analysis_type":"MS","chromatography system":"","column_name":"","chromatography_type":"GC","ms_instrument_name":"Agilent 5973N","ms_instrument_type":"Single quadrupole","ms_type":"EI","ion_mode":"POSITIVE","nmr_instrument_type":"","nmr_experiment_type":"","spectrometer_frequency":"","nmr_solvent":"","units":"nM"}}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"1":{"study_id":"ST000367","analysis_id":"AN000600","analysis_summary":"Precellys homogenization (IC-FTMS1)","analysis_type":"MS","chromatography system":"Thermo Dionex ICS-5000+","column_name":"Unspecified","chromatography_type":"Ion Chromatography","ms_instrument_name":"Thermo Fusion Tribrid Orbitrap","ms_instrument_type":"FT-ICR-MS","ms_type":"ESI","ion_mode":"NEGATIVE","nmr_instrument_type":"","nmr_experiment_type":"","spectrometer_frequency":"","nmr_solvent":"","units":"normalized corrected peak area"},"2":{"study_id":"ST000367","analysis_id":"AN000601","analysis_summary":"Retsch homogenization (IC-FTMS2)","analysis_type":"MS","chromatography system":"Thermo Dionex ICS-5000+","column_name":"Unspecified","chromatography_type":"Ion Chromatography","ms_instrument_name":"Thermo Fusion Tribrid Orbitrap","ms_instrument_type":"FT-ICR-MS","ms_type":"ESI","ion_mode":"NEGATIVE","nmr_instrument_type":"","nmr_experiment_type":"","spectrometer_frequency":"","nmr_solvent":"","units":"normalized corrected peak area"}}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

tests/test_clients/test_mw2isa.py

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import json
12
import logging
23
import os
34
import shutil
45
import tempfile
56
import unittest
7+
from pathlib import Path
8+
from unittest.mock import Mock, patch
69

710
from isatools import isatab
811
from isatools.net.mw2isa import mw2isa_convert
@@ -19,7 +22,31 @@ def setUp(self):
1922
def tearDown(self):
2023
shutil.rmtree(self._tmp_dir)
2124

22-
def test_conversion_ms(self):
25+
def _load_fixture(self, name):
26+
data_path = Path(__file__).parent / "fixtures" / name
27+
return data_path.read_bytes()
28+
29+
def _make_requests_response(self, body_bytes, status=200, headers=None):
30+
m = Mock()
31+
m.status_code = status
32+
m.content = body_bytes
33+
m.text = body_bytes.decode("utf-8")
34+
35+
# Provide .json() for convenience if used by code
36+
def _json():
37+
return json.loads(m.text)
38+
39+
m.json = _json
40+
m.headers = headers or {}
41+
return m
42+
43+
@patch("isatools.net.mw2isa.mw2isa_convert")
44+
def test_conversion_ms(self, mock_get):
45+
def _side_effect():
46+
return self._make_requests_response(self._load_fixture("ST000367.json"))
47+
48+
mock_get.side_effect = _side_effect
49+
2350
success, study_id, validate = mw2isa_convert(
2451
studyid="ST000367", outputdir=self._tmp_dir, dl_option="no", validate_option=True
2552
)
@@ -37,8 +64,13 @@ def test_conversion_ms(self):
3764
else:
3865
self.fail("conversion failed, validation was not invoked")
3966

40-
def test_conversion_nmr(self):
41-
report = {}
67+
@patch("isatools.net.mw2isa.mw2isa_convert")
68+
def test_conversion_nmr(self, mock_get):
69+
def _side_effect():
70+
return self._make_requests_response(self._load_fixture("ST000102.json"))
71+
72+
mock_get.side_effect = _side_effect
73+
4274
success, study_id, validate = mw2isa_convert(
4375
studyid="ST000102", outputdir=self._tmp_dir, dl_option="no", validate_option=True
4476
)
@@ -50,13 +82,25 @@ def test_conversion_nmr(self):
5082
else:
5183
self.assertFalse(success)
5284

53-
def test_conversion_invalid_id(self):
85+
@patch("isatools.net.mw2isa.mw2isa_convert")
86+
def test_conversion_invalid_id(self, mock_get):
87+
def _side_effect():
88+
return self._make_requests_response(self._load_fixture("TOTO.json"))
89+
90+
mock_get.side_effect = _side_effect
91+
5492
success, study_id, validate = mw2isa_convert(
5593
studyid="TOTO", outputdir=self._tmp_dir, dl_option="no", validate_option=True
5694
)
5795
self.assertFalse(success)
5896

59-
def test_conversion_invalid_dloption(self):
97+
@patch("isatools.net.mw2isa.mw2isa_convert")
98+
def test_conversion_invalid_dloption(self, mock_get):
99+
def _side_effect():
100+
return self._make_requests_response(self._load_fixture("ST000102.json"))
101+
102+
mock_get.side_effect = _side_effect
103+
60104
with self.assertRaises(Exception) as context:
61105
success, study_id, validate = mw2isa_convert(
62106
studyid="ST000102", outputdir=self._tmp_dir, dl_option="TOTO", validate_option=False

0 commit comments

Comments
 (0)