Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import tempfile
- import pytest
- from flaskr import flaskr
- @pytest.fixture
- def client():
- db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
- flaskr.app.config['TESTING'] = True
- client = flaskr.app.test_client()
- with flaskr.app.app_context():
- flaskr.init_db()
- yield client
- os.close(db_fd)
- os.unlink(flaskr.app.config['DATABASE'])
- def login(client, username, password):
- return client.post('/login', data=dict(
- username=username,
- password=password
- ), follow_redirects=True)
- def logout(client):
- return client.get('/logout', follow_redirects=True)
- def test_login_logout(client):
- rv = login(client, flaskr.app.config['USERNAME'], flaskr.app.config['PASSWORD'])
- assert b'You are logged in!' in rv.data
- rv = logout(client)
- assert b'You were logged out' in rv.data
- rv = login(client, flaskr.app.config['USERNAME'] + 'x', flaskr.app.config['PASSWORD'])
- assert b'Login Unsuccessful. Please check email and password' in rv.data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement