-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
82 lines (65 loc) · 2.26 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import docker
import requests
import sys
import time
import unittest
from test_utils import TestContainerRunner
class ContainerTest(unittest.TestCase):
def get_url(self, name):
client = docker.APIClient(base_url='unix://var/run/docker.sock')
port = client.port(name, 80)[0]["HostPort"]
url = 'http://localhost:{}'.format(port)
for i in range(5):
try:
requests.get(url)
return url
except:
print('Still waiting for server...')
time.sleep(1)
else:
self.fail('Server never came up')
def assert_expected_response(self, name, expected, path='/'):
url = self.get_url(name)
response = requests.get(url + path)
# TODO: Not ideal for error pages
self.assertEqual(200, response.status_code)
self.assertIn(expected, response.text)
# Good configurations:
def test_good_home_page(self):
self.assert_expected_response('good', '>IGV<')
def test_input_data_url(self):
self.assert_expected_response(
'good',
'{',
path='/options.json'
)
def test_input_data_url_index_included(self):
self.assert_expected_response(
'good_bam',
'.bai',
path='/options.json'
)
# Bad configurations:
def test_missing_assembly(self):
self.assert_expected_response(
'missing_assembly',
'Unexpected 404 from https://s3.amazonaws.com/data.cloud.refinery-platform.org/data/igv-reference/hgFAKE/cytoBand.txt'
)
def test_multiple_assemblies(self):
self.assert_expected_response(
'multiple_assemblies',
# If this happens often, could return more detail, but this is
# enough, for now.
'AssertionError()'
)
def test_no_parameters(self):
self.assert_expected_response(
'no_parameters',
"KeyError('parameters',)"
)
if __name__ == '__main__':
with TestContainerRunner():
suite = unittest.TestLoader().loadTestsFromTestCase(ContainerTest)
result = unittest.TextTestRunner(verbosity=2).run(suite)
if not result.wasSuccessful():
sys.exit(1)