From ab34b8f99c8ab4129c80d63198d979e8f84e80e1 Mon Sep 17 00:00:00 2001 From: Mark Keller <7525285+keller-mark@users.noreply.github.com> Date: Wed, 15 Aug 2018 13:32:07 -0400 Subject: [PATCH] Integration tests --- README.md | 7 ++++ requirements_dev.txt | 1 + test/constants_for_tests.py | 1 + test/test_clustering.py | 31 ++++++++++++++++ test/test_data_listing.py | 27 ++++++++++++++ test/test_exposures.py | 52 ++++++++++++++++++++++++++ test/test_exposures_single_donor.py | 54 +++++++++++++++++++++++++++ test/test_kataegis.py | 21 +++++++++++ test/test_rainfall.py | 24 ++++++++++++ test/test_samples_with_signatures.py | 55 ++++++++++++++++++++++++++++ test/test_signature.py | 35 ++++++++++++++++++ 11 files changed, 308 insertions(+) create mode 100644 requirements_dev.txt create mode 100644 test/constants_for_tests.py create mode 100644 test/test_clustering.py create mode 100644 test/test_data_listing.py create mode 100644 test/test_exposures.py create mode 100644 test/test_exposures_single_donor.py create mode 100644 test/test_kataegis.py create mode 100644 test/test_rainfall.py create mode 100644 test/test_samples_with_signatures.py create mode 100644 test/test_signature.py diff --git a/README.md b/README.md index e0aa8a7..281e672 100644 --- a/README.md +++ b/README.md @@ -24,3 +24,10 @@ cd app && python main.py docker build -t imuse-server . docker run -d -v $(pwd)/obj:/obj -p 80:80 imuse-server ``` + +### Integration Tests +To run the integration tests, start the service at localhost on port 8000 (see instructions above), then run the following: +``` +python -m unittest discover -s test +``` +Alternatively, you could change the `API_BASE` variable in `test/constants_for_tests.py` and run the tests against any running instance of the app. diff --git a/requirements_dev.txt b/requirements_dev.txt new file mode 100644 index 0000000..ba280a8 --- /dev/null +++ b/requirements_dev.txt @@ -0,0 +1 @@ +requests==2.19.1 \ No newline at end of file diff --git a/test/constants_for_tests.py b/test/constants_for_tests.py new file mode 100644 index 0000000..679e072 --- /dev/null +++ b/test/constants_for_tests.py @@ -0,0 +1 @@ +API_BASE = 'http://localhost:8000' diff --git a/test/test_clustering.py b/test/test_clustering.py new file mode 100644 index 0000000..2f8974c --- /dev/null +++ b/test/test_clustering.py @@ -0,0 +1,31 @@ +import requests +import json +import unittest + +from constants_for_tests import * + +class TestClustering(unittest.TestCase): + + def test_clustering(self): + url = API_BASE + '/clustering' + payload = { + "sources":["ICGC-BRCA-EU"], + "signatures":[ + "COSMIC 1", + "COSMIC 2", + "COSMIC 3", + "COSMIC 5", + "COSMIC 6", + "COSMIC 8", + "COSMIC 13", + "COSMIC 17", + "COSMIC 18", + "COSMIC 20", + "COSMIC 26", + "COSMIC 30" + ] + } + r = requests.post(url, data=json.dumps(payload)) + r.raise_for_status() + res = r.json() + self.assertEqual({'name', 'children'}, set(res.keys())) \ No newline at end of file diff --git a/test/test_data_listing.py b/test/test_data_listing.py new file mode 100644 index 0000000..16829f7 --- /dev/null +++ b/test/test_data_listing.py @@ -0,0 +1,27 @@ +import requests +import unittest + +from constants_for_tests import * + +class TestDataListing(unittest.TestCase): + + def test_data_listing(self): + url = API_BASE + '/data-listing' + r = requests.post(url) + r.raise_for_status() + res = r.json() + self.assertEqual(['sources', 'sigs', 'sig_presets'], list(res.keys())) + self.assertIn("ICGC-BRCA-EU", list(res['sources'].keys())) + brca_obj = { + "name": "Breast ER+ and HER2- Cancer - EU/UK", + "num_donors": 569, + "source": "ICGC", + "has_clinical": True, + "has_ssm": True, + "has_counts": True + } + self.assertEqual(brca_obj, res['sources']['ICGC-BRCA-EU']) + self.assertEqual({'name', 'description', 'index', 'publication'}, set(res['sigs'][0].keys())) + self.assertEqual({'group', 'id', 'cancer-types'}, set(res['sig_presets'][0].keys())) + self.assertEqual({'name', 'id', 'signatures'}, set(res['sig_presets'][0]['cancer-types'][0].keys())) + \ No newline at end of file diff --git a/test/test_exposures.py b/test/test_exposures.py new file mode 100644 index 0000000..9242c28 --- /dev/null +++ b/test/test_exposures.py @@ -0,0 +1,52 @@ +import requests +import json +import unittest + +from constants_for_tests import * + +class TestExposures(unittest.TestCase): + + def test_exposures(self): + url = API_BASE + '/exposures' + payload = { + "sources": ["ICGC-BRCA-EU"], + "signatures": [ + "COSMIC 1", + "COSMIC 2", + "COSMIC 3", + "COSMIC 4", + "COSMIC 5", + "COSMIC 6", + "COSMIC 7", + "COSMIC 8", + "COSMIC 9", + "COSMIC 10", + "COSMIC 11", + "COSMIC 12", + "COSMIC 13", + "COSMIC 14", + "COSMIC 15", + "COSMIC 16", + "COSMIC 17", + "COSMIC 18", + "COSMIC 19", + "COSMIC 20", + "COSMIC 21", + "COSMIC 22", + "COSMIC 23", + "COSMIC 24", + "COSMIC 25", + "COSMIC 26", + "COSMIC 27", + "COSMIC 28", + "COSMIC 29", + "COSMIC 30", + "5* A" + ] + } + r = requests.post(url, data=json.dumps(payload)) + r.raise_for_status() + res = r.json() + self.assertEqual(569, len(res)) + self.assertEqual({'donor_id', 'proj_id', 'exposures', 'clinical'}, set(res[0].keys())) + self.assertEqual(31, len(res[0]['exposures'])) \ No newline at end of file diff --git a/test/test_exposures_single_donor.py b/test/test_exposures_single_donor.py new file mode 100644 index 0000000..7944131 --- /dev/null +++ b/test/test_exposures_single_donor.py @@ -0,0 +1,54 @@ +import requests +import json +import unittest + +from constants_for_tests import * + +class TestExposuresSingleDonor(unittest.TestCase): + + def test_exposures_single_donor(self): + url = API_BASE + '/exposures-single-donor' + payload = { + "donor_id": "DO220823", + "proj_id": "ICGC-BRCA-EU", + "sources":["PCAWG-BRCA-EU"], + "signatures":[ + "COSMIC 1", + "COSMIC 2", + "COSMIC 3", + "COSMIC 4", + "COSMIC 5", + "COSMIC 6", + "COSMIC 7", + "COSMIC 8", + "COSMIC 9", + "COSMIC 10", + "COSMIC 11", + "COSMIC 12", + "COSMIC 13", + "COSMIC 14", + "COSMIC 15", + "COSMIC 16", + "COSMIC 17", + "COSMIC 18", + "COSMIC 19", + "COSMIC 20", + "COSMIC 21", + "COSMIC 22", + "COSMIC 23", + "COSMIC 24", + "COSMIC 25", + "COSMIC 26", + "COSMIC 27", + "COSMIC 28", + "COSMIC 29", + "COSMIC 30", + "5* A" + ] + } + r = requests.post(url, data=json.dumps(payload)) + r.raise_for_status() + res = r.json() + self.assertEqual(1, len(res)) + self.assertEqual({'donor_id', 'proj_id', 'exposures', 'clinical'}, set(res[0].keys())) + self.assertEqual(31, len(res[0]['exposures'])) \ No newline at end of file diff --git a/test/test_kataegis.py b/test/test_kataegis.py new file mode 100644 index 0000000..5cd099a --- /dev/null +++ b/test/test_kataegis.py @@ -0,0 +1,21 @@ +import requests +import json +import unittest + +from constants_for_tests import * + +class TestKataegis(unittest.TestCase): + + def test_kataegis(self): + url = API_BASE + '/kataegis' + + payload = { + "sources":[ + "ICGC-BRCA-EU" + ] + } + r = requests.post(url, data=json.dumps(payload)) + r.raise_for_status() + res = r.json() + self.assertEqual(569, len(res.keys())) + self.assertEqual(4, len(res['DO217786']['kataegis']['1'])) \ No newline at end of file diff --git a/test/test_rainfall.py b/test/test_rainfall.py new file mode 100644 index 0000000..0a8b0df --- /dev/null +++ b/test/test_rainfall.py @@ -0,0 +1,24 @@ +import requests +import json +import csv +import unittest + +from constants_for_tests import * + +class TestRainfall(unittest.TestCase): + + def test_rainfall(self): + url = API_BASE + '/kataegis-rainfall' + + payload = { + "proj_id": "ICGC-BRCA-EU", + "donor_id": "DO217786" + } + r = requests.post(url, data=json.dumps(payload)) + r.raise_for_status() + decoded_content = r.content.decode('utf-8') + + res = list(csv.reader(decoded_content.splitlines(), delimiter=',')) + self.assertEqual({'chr', 'pos', 'cat', 'cat_index', 'mut_dist', 'kataegis'}, set(res[0])) + + self.assertEqual(3107, len(res)) \ No newline at end of file diff --git a/test/test_samples_with_signatures.py b/test/test_samples_with_signatures.py new file mode 100644 index 0000000..fe7445c --- /dev/null +++ b/test/test_samples_with_signatures.py @@ -0,0 +1,55 @@ +import requests +import json +import unittest + +from constants_for_tests import * + +class TestSamplesWithSignatures(unittest.TestCase): + + def test_samples_with_signatures(self): + url = API_BASE + '/samples-with-signatures' + + payload = { + "sources":["ICGC-BRCA-EU"], + "signatures":[ + "COSMIC 1", + "COSMIC 2", + "COSMIC 3", + "COSMIC 4", + "COSMIC 5", + "COSMIC 6", + "COSMIC 7", + "COSMIC 8", + "COSMIC 9", + "COSMIC 10", + "COSMIC 11", + "COSMIC 12", + "COSMIC 13", + "COSMIC 14", + "COSMIC 15", + "COSMIC 16", + "COSMIC 17", + "COSMIC 18", + "COSMIC 19", + "COSMIC 20", + "COSMIC 21", + "COSMIC 22", + "COSMIC 23", + "COSMIC 24", + "COSMIC 25", + "COSMIC 26", + "COSMIC 27", + "COSMIC 28", + "COSMIC 29", + "COSMIC 30", + "5* A" + ] + } + r = requests.post(url, data=json.dumps(payload)) + r.raise_for_status() + res = r.json() + + self.assertEqual({'signatures', 'projects'}, set(res.keys())) + self.assertEqual(31, len(list(res['signatures'].keys()))) + self.assertEqual(569, res['projects']['ICGC-BRCA-EU']) + \ No newline at end of file diff --git a/test/test_signature.py b/test/test_signature.py new file mode 100644 index 0000000..7026e45 --- /dev/null +++ b/test/test_signature.py @@ -0,0 +1,35 @@ +import requests +import json +import unittest + +from constants_for_tests import * + +class TestSignature(unittest.TestCase): + + def test_signature(self): + url = API_BASE + '/signature' + + payload = { + "signature": "COSMIC 1" + } + r = requests.post(url, data=json.dumps(payload)) + r.raise_for_status() + res = r.json() + + self.assertEqual({'data', 'meta'}, set(res.keys())) + self.assertEqual(96, len(res['data'])) + self.assertEqual(["A[C>A]A", 0.011098326], res['data'][0]) + + self.assertEqual({'name', 'description', 'index', 'publication'}, set(res['meta'].keys())) + + def test_another_signature(self): + url = API_BASE + '/signature' + + payload = { + "signature": "COSMIC 2" + } + r = requests.post(url, data=json.dumps(payload)) + r.raise_for_status() + res = r.json() + + self.assertEqual(["A[C>A]A", 0.0006827080000000001], res['data'][0]) \ No newline at end of file