forked from AleksandarMuradyan/static_carrier_inventory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
120 lines (90 loc) · 3.63 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import json
import pytest
from carrier_inventory import app
# GET methods:
url = 'http://127.0.0.1:8000/api/locations'
url1 = 'http://127.0.0.1:8000/api/locations'
url2 = 'http://127.0.0.1:8000/api/products'
url3 = 'http://127.0.0.1:8000/api/ports'
url4 = 'http://127.0.0.1:8000/api/prices'
url5 = 'http://127.0.0.1:8000/api/requests'
# POST methods:
url6 = 'http://127.0.0.1:8000/api/login'
url7 = 'http://127.0.0.1:8000/api/locations'
url8 = 'http://127.0.0.1:8000/api/ports'
url9 = 'http://127.0.0.1:8000/api/connections'
@pytest.fixture
def client(request):
test_client = app.test_client()
def teardown():
pass
request.addfinalizer(teardown)
return test_client
def post_json(client, url, json_dict):
return client.post(url, data=json.dumps(json_dict), content_type='application/json')
def json_of_response(response):
"""Decode json from response"""
return json.loads(response.data.decode('utf8'))
def test_locations(client):
response = client.get(url1)
assert response.status_code == 200
assert b'UK_TEST_01' in response.data
assert b'customer_site_name' in response.data
assert "UK_TEST_01" in str(response.data)
def test_products(client):
response = client.get(url2)
assert response.status_code == 200
assert b'"service_type":"ETHERNETPORT"' in response.data
assert b'ports_available' in response.data
def test_ports_spec(client):
response = client.get(url3)
assert response.status_code == 200
assert b'port_type' in response.data
assert b'bandwidth' in response.data
def test_prices(client):
response = client.get(url4)
assert response.status_code == 200
assert b'"rental_unit"' in response.data
assert b'installation_charge' in response.data
assert b'installation_currency' in response.data
# def test_requests(client):
# response = client.get(url5)
# assert response.status_code == 200
# assert b'"requested_at"' in response.data
def test_login(client):
response = post_json(client, url6, {'key': 'value'})
assert response.status_code == 200
assert json_of_response(response) == {"token": "string"}
def test_locations_post(client):
response = post_json(client, url7, {"site_id": "2"})
assert response.status_code == 200
assert json_of_response(response) == {'customer_location_list': [{'customer_site_name': 'Headquarters',
'site_id': '2'},
{'customer_site_name': 'LexCorp Head Office',
'site_id': '543'}]}
def test_ports_post(client):
response = post_json(client, url8, {"site_id": "2"})
assert response.status_code == 200
assert 'response_url' in json_of_response(response)
def test_conn_post(client):
response = post_json(client, url9, {"price_id": "10"})
assert response.status_code == 200
assert 'response_url' in json_of_response(response)
# def test_products_api(client):
# response = client.get('http://127.0.0.1:8000/get/api/products')
# with open(os.path.join(basedir, 'ports_data.json'), 'r') as f:
# assert response.json in json.loads(f.read())
#
#
# def test_ports_api(client):
# response = client.get('http://127.0.0.1:8000/get/api/ports')
# # = os.path.join(basedir, 'port_spec_data.json')
#
# with open(os.path.join(basedir, 'ports_data.json'), 'r') as f:
# json_data = json.loads(f.read())
# assert response.json == json_data
# print(json_data)
# y = response.json
# print(y)
# #assert os.path.join(basedir, 'port_spec_data.json') in response.json
#assert "from_port_id" in str(response.data)