This repository has been archived by the owner on Sep 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_app.py
75 lines (64 loc) · 2.85 KB
/
test_app.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
# import os
# import tempfile
# import pytest
from app import app, db
from ghdb import GithubUser
def test_favicon():
'''Teset favicon is there.'''
with app.test_client() as test_client:
response = test_client.get('/favicon.ico')
assert response.status_code == 200
def test_home_page():
'''Check the title of the index.'''
with app.test_client() as test_client:
response = test_client.get('/')
assert response.status_code == 200
assert b'Github user list' in response.data
def test_pagination():
'''Test different pagination combinations'''
with app.test_client() as test_client:
response = test_client.get('/?total=1&page=0')
assert response.status_code == 200
assert 2 == str(response.data).count('</tr>')
assert b'mojombo' in response.data
response = test_client.get('/?total=1&page=1')
assert response.status_code == 200
assert 2 == str(response.data).count('</tr>')
assert b'defunkt' in response.data
def test_all_json_list():
'''Test that it returns all users in database.'''
with app.test_client() as test_client:
response = test_client.post('/all')
assert response.status_code == 200
assert response.content_type == 'application/json'
assert len(response.json) == len(dict(db.session.query(GithubUser.id, GithubUser)))
def test_json_filter():
'''If `username` is set, it should only return 1 element.'''
with app.test_client() as test_client:
response = test_client.post('/all?username=defunkt&pagination=20&order_by=id')
assert response.status_code == 200
assert response.content_type == 'application/json'
assert len(response.json) == 1
def test_pager_json_list():
'''Paging should work'''
with app.test_client() as test_client:
response1 = test_client.post('/all?total=20&page=0&order_by=user')
assert response1.status_code == 200
assert response1.content_type == 'application/json'
assert len(response1.json) == 20
response2 = test_client.post('/all?total=20&page=100&order_by=profile')
assert response2.status_code == 200
assert response2.content_type == 'application/json'
assert len(response2.json) == 20
assert response1.json[0] != response2.json[0]
assert response1.json[-1] != response2.json[-1]
response3 = test_client.post('/all?total=20&page=100&order_by=type')
assert response3.status_code == 200
assert response3.content_type == 'application/json'
assert len(response3.json) == 20
assert response1.json[0] != response3.json[0]
assert response1.json[-1] != response3.json[-1]
def test_datatables():
with app.test_client() as test_client:
response = test_client.get('/dt')
assert response.status_code == 200