/
tests.py
96 lines (69 loc) · 2.46 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from os import path, environ
import sys
import requests
try:
import unittest2 as unittest
except ImportError:
import unittest
import liveandletdie
def abspath(pth):
return path.join(path.dirname(__file__), '../..', pth)
PORT = 8001
def test_decorator(cls):
@classmethod
def setUpClass(cls):
try:
# Run the live server.
cls.app.live(kill_port=True)
except Exception as e:
# Skip test if not started.
raise unittest.SkipTest(e)
@classmethod
def tearDownClass(cls):
cls.app.die()
def test_visit_start_page(self):
page_text = requests.get(self.app.check_url, verify=False).\
content.decode('utf-8')
self.assertIn(self.EXPECTED_TEXT, page_text)
cls.setUpClass = setUpClass
cls.tearDownClass = tearDownClass
cls.test_visit_start_page = test_visit_start_page
return cls
@test_decorator
class TestFlask(unittest.TestCase):
EXPECTED_TEXT = 'Home Flask'
app = liveandletdie.Flask(abspath('sample_apps/flask/main.py'), port=PORT)
@test_decorator
class TestFlaskSSL(unittest.TestCase):
EXPECTED_TEXT = 'Home Flask SSL'
app = liveandletdie.Flask(abspath('sample_apps/flask/main.py'), port=PORT,
ssl=True)
@test_decorator
class TestPyramid(unittest.TestCase):
EXPECTED_TEXT = 'Home Pyramid'
app = liveandletdie.WsgirefSimpleServer(abspath('sample_apps/pyramid/main.py'), port=PORT)
@test_decorator
class TestPyramidSSL(unittest.TestCase):
EXPECTED_TEXT = 'Home Pyramid SSL'
app = liveandletdie.WsgirefSimpleServer(abspath('sample_apps/pyramid/main.py'), port=PORT,
ssl=True)
@test_decorator
class TestDjango(unittest.TestCase):
EXPECTED_TEXT = 'Home Django'
app = liveandletdie.Django(abspath('sample_apps/django/example'), port=PORT)
@unittest.skipUnless(sys.version_info[0] is 2 and sys.version_info[1] is 7,
"GAE not implemented for {0}".format(sys.version))
@test_decorator
class TestGAE(unittest.TestCase):
EXPECTED_TEXT = 'Home GAE'
app = liveandletdie.GAE(environ['VIRTUAL_ENV'] + '/bin/dev_appserver',
abspath('sample_apps/gae'), port=PORT)
@test_decorator
class TestFastAPI(unittest.TestCase):
EXPECTED_TEXT = 'Home FastAPI'
app = liveandletdie.FastAPIServer(
abspath('sample_apps/fastapi/main.py'),
port=PORT
)
if __name__ == '__main__':
unittest.main()