-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
52 lines (39 loc) · 1.1 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
"""
File: tests.py
Authors: Rafal Marguzewicz
Emails: [email protected]
Description: tests - pytest
"""
from json import load
from urllib.request import urlopen, Request
from urllib import error
host = f"https://blockchain.info/rawblock/"
endpoint = '0000000000000bae09a7a393a8acded75aa67e46cb81f7acaa5ad94f9eacd103'
def headers():
"""
Posibility adding authorization token to header of request
"""
return {'Authorization': 'token_secure'}
def request(endpoint_url: str=''):
return Request(f"{host}/{endpoint_url}", headers=headers())
def test_endpoint_200():
"""
Response 200
"""
req = request(f"{endpoint}")
assert 200 == urlopen(req).getcode()
def test_endpoint_data_in_json():
"""
Response json
"""
json_data = load(urlopen(f"{host}/0000000000000bae09a7a393a8acded75aa67e46cb81f7acaa5ad94f9eacd103"))
assert json_data['hash'] == endpoint
def test_endpoint_500():
"""
Reponse 404
"""
req = request(f"endpoint_with_404")
try:
urlopen(req).getcode()
except error.HTTPError as e:
assert e.code == 500 # or 404