Skip to content

Commit

Permalink
Integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
keller-mark committed Aug 15, 2018
1 parent 7c08f9e commit ab34b8f
Show file tree
Hide file tree
Showing 11 changed files with 308 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests==2.19.1
1 change: 1 addition & 0 deletions test/constants_for_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
API_BASE = 'http://localhost:8000'
31 changes: 31 additions & 0 deletions test/test_clustering.py
Original file line number Diff line number Diff line change
@@ -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()))
27 changes: 27 additions & 0 deletions test/test_data_listing.py
Original file line number Diff line number Diff line change
@@ -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()))

52 changes: 52 additions & 0 deletions test/test_exposures.py
Original file line number Diff line number Diff line change
@@ -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']))
54 changes: 54 additions & 0 deletions test/test_exposures_single_donor.py
Original file line number Diff line number Diff line change
@@ -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']))
21 changes: 21 additions & 0 deletions test/test_kataegis.py
Original file line number Diff line number Diff line change
@@ -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']))
24 changes: 24 additions & 0 deletions test/test_rainfall.py
Original file line number Diff line number Diff line change
@@ -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))
55 changes: 55 additions & 0 deletions test/test_samples_with_signatures.py
Original file line number Diff line number Diff line change
@@ -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'])

35 changes: 35 additions & 0 deletions test/test_signature.py
Original file line number Diff line number Diff line change
@@ -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])

0 comments on commit ab34b8f

Please sign in to comment.