-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_app.py
55 lines (41 loc) · 1.48 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
import pytest
from app import app as flask_app
@pytest.fixture
def app():
yield flask_app
@pytest.fixture
def client(app):
return app.test_client()
def test_home_route(client):
response = client.get('/')
assert response.status_code == 200
assert b'Top Post' in response.data
def test_registration_route(client):
response = client.get('/register')
assert response.status_code == 200
assert b'Register' in response.data
def test_login_route(client):
response = client.get('/login')
assert response.status_code == 200
assert b'Login' in response.data
def test_logout_route(client):
response = client.get('/logout')
assert response.status_code == 302
def test_post_creation(client):
with client:
client.post('/login', data=dict(username='test_user', password='test_password'))
response = client.post('/post/new', data=dict(
title='Test Post Title',
body='Test Post Body',
link='https://example.com'
), follow_redirects=True)
assert response.status_code == 200
assert b'Test Post Title' in response.data
def test_profile_route(client):
response = client.get('/profile')
assert response.status_code == 302
assert b'Edit Profile' in response.data
def test_search_route(client):
response = client.post('/search', data=dict(searched='test_query'))
assert response.status_code == 200
assert b'You searched for' in response.data