-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_api.py
81 lines (61 loc) · 2.52 KB
/
test_api.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
# To run, navigate to memechain-api/tests and enter "py.test -s"
# The -s flag prints any messages in the std i/o, so prints become usable.
from falcon import testing
import pytest
from api import app
@pytest.fixture
def client():
return testing.TestClient(app)
# pytest will inject the object returned by the `client` function
# as an additional parameter.
def test_get_memechain_height(client):
known_result = 0
response = client.simulate_get('/api/getheight')
queried_result = response.json['result']
assert known_result == queried_result
def test_get_meme_data_by_height(client):
# TODO: Once the database can be populated, define
# the genesis meme data and run this test
GENESIS_MEME_DATA = {}
known_result = GENESIS_MEME_DATA
test_height = 0
response = client.simulate_get('/api/getmemedatabyheight/%i'
% (test_height))
queried_result = response.json['result']
assert known_result == queried_result
def test_get_meme_data_by_hash(client):
# TODO: Once the database can be populated, define
# the genesis meme data test_hash and run this test
GENESIS_MEME_DATA = {}
known_result = GENESIS_MEME_DATA
test_hash = 'Fill in test hash here...'
response = client.simulate_get('/api/getmemedatabyhash/%s'
% (test_hash))
queried_result = response.json['result']
assert known_result == queried_result
def test_get_meme_img_by_height(client):
# TODO: Once the database can be populated, define
# the genesis meme img and run this test
GENESIS_MEME = None
known_result = GENESIS_MEME
test_height = 0
response = client.simulate_get('/api/getmemeimgbyheight/%i'
% (test_height))
queried_result = response.json['result']
assert known_result == queried_result
def test_get_meme_img_by_hash(client):
# TODO: Once the database can be populated, define
# the genesis meme img and run this test
GENESIS_MEME = None
known_result = GENESIS_MEME
test_hash = 'Fill in test hash here...'
response = client.simulate_get('/api/getmemeimgbyhash/%s'
% (test_hash))
queried_result = response.json['result']
assert known_result == queried_result
def test_add_meme(client):
response = client.simulate_post('/api/addmeme')
# Check image written to local storage
# Check image added to ipfs
# Wait sufficient time for block to be staked,
# then check existence in blockchain