fixed various typos and variable name changes

This commit is contained in:
2021-10-17 23:27:53 -06:00
parent e4c051b8c2
commit 110281ce0a
5 changed files with 16 additions and 18 deletions
+3 -3
View File
@@ -19,7 +19,7 @@ def register():
error = None error = None
if not userid: if not userid:
error = 'Username if required.' error = 'Userid is required.'
elif not email: elif not email:
error = 'Email is required.' error = 'Email is required.'
elif not password: elif not password:
@@ -53,9 +53,9 @@ def login():
).fetchone() ).fetchone()
if user is None: if user is None:
error = 'Incorrect username.' error = 'Userid or Password incorrect.'
elif not check_password_hash(user['password'], password): elif not check_password_hash(user['password'], password):
error = 'Incorrect password.' error = 'Userid or Password incorrect.'
if error is None: if error is None:
session.clear() session.clear()
-2
View File
@@ -8,8 +8,6 @@
<form method="post"> <form method="post">
<label for="userid">Userid</label> <label for="userid">Userid</label>
<input name="userid" id="userid" required> <input name="userid" id="userid" required>
<label for="email">Email</label>
<input type="email" name="email" id="email" required>
<label for="password">Password</label> <label for="password">Password</label>
<input type="password" name="password" id="password" required> <input type="password" name="password" id="password" required>
<input type="submit" value="Login"> <input type="submit" value="Login">
+2 -2
View File
@@ -38,10 +38,10 @@ class AuthActions(object):
def __init__(self, client): def __init__(self, client):
self._client = client self._client = client
def login(self, username='test', password='test'): def login(self, username='test', email='a@.c', password='test'):
return self._client.post( return self._client.post(
'auth/login', 'auth/login',
data={'username': username, 'password': password} data={'userid': username, 'email': email, 'password': password}
) )
def logout(self): def logout(self):
+10 -10
View File
@@ -7,29 +7,29 @@ def test_register(client, app):
response = client.post( response = client.post(
'auth/register', data={'userid': 'a', 'email': 'a@b.c', 'password': 'a'} 'auth/register', data={'userid': 'a', 'email': 'a@b.c', 'password': 'a'}
) )
assert 'http://localhost/auth/login' == response.headers['Location'] assert 'http://localhost/auth/login' == response.headers['Path']
with app.app_context(): with app.app_context():
assert get_db().execute( assert get_db().execute(
"SELECT * FROM users WHERE userid = 'a'", "SELECT * FROM users WHERE userid = 'a'",
).fetchone() is not None ).fetchone() is not None
@pytest.mark.parametrize(('userid', 'password', 'message'), ( @pytest.mark.parametrize(('userid', 'email', 'password', 'message'), (
('', '', b'Userid is required.'), ('', '', '', b'Userid is required.'),
('a', '', b'Password is required.'), ('a', 'a@b.c', '', b'Password is required.'),
('test', 'test', b'already registered'), ('test', 'test', 'test', b'already registered'),
)) ))
def test_register_validate_input(client, userid, password, message): def test_register_validate_input(client, userid, email, password, message):
response = client.post( response = client.post(
'/auth/register', '/auth/register',
data={'userid': userid, 'password': password} data={'userid': userid, 'email': email, 'password': password}
) )
assert message in response.data assert message in response.data
def test_login(client, auth): def test_login(client, auth):
assert client.get('/auth/login').status_code == 200 assert client.get('/auth/login').status_code == 200
response = auth.login() response = auth.login()
assert response.headers['Location'] == 'http://localhost/' assert response.headers['Path'] == 'http://localhost/'
with client: with client:
client.get('/') client.get('/')
@@ -37,8 +37,8 @@ def test_login(client, auth):
assert g.user['userid'] == 'test' assert g.user['userid'] == 'test'
@pytest.mark.parametrize(('userid', 'password', 'message'), ( @pytest.mark.parametrize(('userid', 'password', 'message'), (
('a', 'test', b'Incorrect userid'), ('a', 'test', b'Userid or Password incorrect.'),
('test', 'a', b'Incorrect password.'), ('test', 'a', b'Userid or Password incorrect.'),
)) ))
def test_login_validate_input(auth, userid, password, message): def test_login_validate_input(auth, userid, password, message):
response = auth.login(userid, password) response = auth.login(userid, password)
+1 -1
View File
@@ -6,4 +6,4 @@ def test_config():
def test_hello(client): def test_hello(client):
response = client.get('/hello') response = client.get('/hello')
assert response.data == b'Hello World!' assert response.data == b'Hello, World!'