-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathtests.py
More file actions
executable file
·45 lines (34 loc) · 1.24 KB
/
Copy pathtests.py
File metadata and controls
executable file
·45 lines (34 loc) · 1.24 KB
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
import urllib.request
import unittest
from threading import Thread
import simplebin
import bottle
BASE_URL = f'http://{simplebin.HTTP_HOST}:{simplebin.HTTP_PORT}'
def urlopen(path):
try:
res = urllib.request.urlopen(urllib.parse.urljoin(BASE_URL, path))
return res
except urllib.error.HTTPError as res:
return res
class TestSimpleBin(unittest.TestCase):
@classmethod
def setUpClass(cls):
print("Starting builtin server in a daemon thread")
threaded_server = Thread(target=bottle.run, daemon=True, kwargs={
'host': simplebin.HTTP_HOST,
'port': simplebin.HTTP_PORT,
'quiet': True,
})
threaded_server.start()
threaded_server.join(.5) # quick and dirty
def test_get_snippet(self):
""" Accessing a snippet that exist show the valid code """
with urlopen('/iexist') as res:
self.assertEqual(res.status, 200)
self.assertEqual(res.read().decode(), "Hello world")
def test_missing_snippet(self):
""" Accessing a snippet that does not exist fails with a 404 """
with urlopen('/idontexist') as res:
self.assertEqual(res.status, 404)
if __name__ == '__main__':
unittest.main()