-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
58 lines (49 loc) · 1.86 KB
/
tests.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
import json
import os
import requests
import subprocess
import time
import unittest
class CommandlineTest(unittest.TestCase):
def setUp(self):
command = "docker port container-{STAMP}{SUFFIX} | perl -pne 's/.*://'".format(
**os.environ)
os.environ['PORT'] = subprocess.check_output(
command, shell=True).strip().decode('utf-8')
self.url = 'http://localhost:{PORT}/tree'.format(**os.environ)
self.files_url = 'http://localhost:{PORT}/api/contents/refinery-data'.format(
**os.environ)
while True:
if 0 == subprocess.call('curl --fail --silent ' + self.url + ' > /dev/null', shell=True):
break
print('still waiting for server...')
time.sleep(1)
def assertRun(self, command, res=[r'']):
output = subprocess.check_output(
command.format(**os.environ), shell=True).strip()
for re in res:
self.assertRegexpMatches(output, re)
# Tests:
def test_hello(self):
self.assertRun('echo "hello?"', [r'hello'])
# Test if the data we specify in input.json gets ingested properly by
# jupyter upon container startup
def test_data_ingested(self):
time.sleep(5)
response = requests.get(self.files_url)
self.assertIn("pep-0020.txt", response.content)
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(CommandlineTest)
result = unittest.TextTestRunner(verbosity=2).run(suite)
lines = [
'browse: http://localhost:{PORT}/',
'shell: docker exec --interactive --tty container-{STAMP}{SUFFIX} bash',
'logs: docker exec container-{STAMP}{SUFFIX} ./logs.sh'
]
for line in lines:
print(line.format(**os.environ))
if result.wasSuccessful():
print('PASS!')
else:
print('FAIL!')
exit(1)