register in auth.py and change username to userid in tests
This commit is contained in:
+11
-11
@@ -5,24 +5,24 @@ from flaskfdx.db import get_db
|
||||
def test_register(client, app):
|
||||
assert client.get('/auth/register').status_code == 200
|
||||
response = client.post(
|
||||
'auth/register', data={'username': 'a', 'password': 'a'}
|
||||
'auth/register', data={'userid': 'a', 'email': 'a@b.c', 'password': 'a'}
|
||||
)
|
||||
assert 'http://localhost/auth/login' == response.headers['Location']
|
||||
|
||||
with app.app_context():
|
||||
assert get_db().execute(
|
||||
"SELECT * FROM users WHERE username = 'a'",
|
||||
"SELECT * FROM users WHERE userid = 'a'",
|
||||
).fetchone() is not None
|
||||
|
||||
@pytest.mark.parametrize(('username', 'password', 'message'), (
|
||||
('', '', b'Username is required.'),
|
||||
@pytest.mark.parametrize(('userid', 'password', 'message'), (
|
||||
('', '', b'Userid is required.'),
|
||||
('a', '', b'Password is required.'),
|
||||
('test', 'test', b'already registered'),
|
||||
))
|
||||
def test_register_validate_input(client, username, password, message):
|
||||
def test_register_validate_input(client, userid, password, message):
|
||||
response = client.post(
|
||||
'/auth/register',
|
||||
data={'username': username, 'password': password}
|
||||
data={'userid': userid, 'password': password}
|
||||
)
|
||||
assert message in response.data
|
||||
|
||||
@@ -34,14 +34,14 @@ def test_login(client, auth):
|
||||
with client:
|
||||
client.get('/')
|
||||
assert session['user_id'] == 1
|
||||
assert g.user['username'] == 'test'
|
||||
assert g.user['userid'] == 'test'
|
||||
|
||||
@pytest.mark.parametrize(('username', 'password', 'message'), (
|
||||
('a', 'test', b'Incorrect username'),
|
||||
@pytest.mark.parametrize(('userid', 'password', 'message'), (
|
||||
('a', 'test', b'Incorrect userid'),
|
||||
('test', 'a', b'Incorrect password.'),
|
||||
))
|
||||
def test_login_validate_input(auth, username, password, message):
|
||||
response = auth.login(username, password)
|
||||
def test_login_validate_input(auth, userid, password, message):
|
||||
response = auth.login(userid, password)
|
||||
assert message in response.data
|
||||
|
||||
def testz_logout(client, auth):
|
||||
|
||||
Reference in New Issue
Block a user