-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
71 lines (63 loc) · 2.03 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import json
import pytest_mock
from apistar.test import TestClient
from app import app, welcome
def test_welcome():
"""
Testing a view directly.
"""
data = welcome()
assert data == {'message': 'Welcome to API Star!'}
def test_http_request():
"""
Testing a view, using the test client.
"""
client = TestClient(app)
response = client.get('http://localhost/')
assert response.status_code == 200
assert response.json() == {'message': 'Welcome to API Star!'}
def test_search():
client = TestClient(app)
# TODO レスポンスをモック化したい
response = client.get('http://localhost/search?query=hoge&order_by=date')
result = [
{
"kind": "youtube#searchResult",
"etag": "dummy",
"id": {
"kind": "youtube#video",
"videoId": "dummy"
},
"snippet": {
"publishedAt": "2017-09-30T00:00:00.000Z",
"channelId": "dummy",
"title": "dummy response",
"channelTitle": "dummy",
"description": "This is dummy data",
"liveBroadcastContent": "none",
"thumbnails": {
"default": {
"height": 90,
"url": "https://dummy.jpg",
"width": 120
},
"high": {
"height": 360,
"url": "https://dummy.jpg",
"width": 480
},
"medium": {
"height": 180,
"url": "https://dummy.jpg",
"width": 320
}
}
}
}
]
assert response.status_code == 200
assert response.json() == result
def test_search_without_query():
client = TestClient(app)
response = client.get('http://localhost/search')
assert response.json() == {'message': 'query is empty!'}