-
Notifications
You must be signed in to change notification settings - Fork 5
/
exo_lib.py
89 lines (56 loc) · 2.76 KB
/
exo_lib.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
#!/usr/bin/env python3.7
from checklib import *
PORT = 17171
class CheckMachine:
def __init__(self, checker):
self.checker = checker
self.port = PORT
@property
def url(self):
return f'http://{self.checker.host}:{self.port}'
def health_check(self, session):
url = self.url
response = session.get(self.url)
self.checker.assert_eq(response.status_code, 200, "Can't get the main page")
def add_star(self, session, star):
url = f"{self.url}/api/stars/"
response = session.post(url, json=star)
obj = self.checker.get_json(response, "Can't add star")
self.checker.assert_eq(response.status_code, 201, "Can't add star")
self.checker.assert_eq(type(obj), type({}), 'Incorrect star model')
self.checker.assert_in('id', obj, 'Incorrect star model')
for key, value in star.items():
self.checker.assert_in(key, obj, "Can't add star")
self.checker.assert_eq(value, obj.get(key), "Can't add star")
return obj
def add_planet(self, session, planet):
url = f'{self.url}/api/planets/'
response = session.post(url, json=planet)
obj = self.checker.get_json(response, "Can't add planet")
self.checker.assert_eq(response.status_code, 201, "Can't add planet")
self.checker.assert_eq(type(obj), type({}), 'Incorrect planet model')
self.checker.assert_in('id', obj, 'Incorrect planet model')
for key, value in planet.items():
self.checker.assert_in(key, obj, "Can't add planet")
self.checker.assert_eq(value, obj.get(key), "Can't add planet")
return obj
def get_star(self, session, star_id, star={}):
url = f'{self.url}/api/stars/{star_id}'
response = session.get(url)
obj = self.checker.get_json(response, "Can't get star")
self.checker.assert_eq(response.status_code, 200, "Can't get star")
self.checker.assert_eq(type(obj), type({}), 'Incorrect star model')
for key, value in star.items():
self.checker.assert_in(key, obj, "Can't get star")
self.checker.assert_eq(value, obj.get(key), "Can't get star")
return obj
def get_planet(self, session, planet_id, planet={}):
url = f'{self.url}/api/planets/{planet_id}'
response = session.get(url)
obj = self.checker.get_json(response, "Can't get planet")
self.checker.assert_eq(response.status_code, 200, "Can't get planet")
self.checker.assert_eq(type(obj), type({}), 'Incorrect planet model')
for key, value in planet.items():
self.checker.assert_in(key, obj, "Can't get planet")
self.checker.assert_eq(value, obj.get(key), "Can't get planet")
return obj