Refactor user authentication tests.
This commit is contained in:
parent
bba746b984
commit
8446354b59
|
@ -17,6 +17,8 @@ from pytest_bdd import parsers
|
|||
from tests import utils
|
||||
|
||||
|
||||
bdd.scenarios('user_authentication.feature')
|
||||
|
||||
Credentials = collections.namedtuple('Credentials', ['username', 'password'])
|
||||
|
||||
INVALID_USER_INVALID_CREDENTIALS = Credentials('invalid_user', 'invalid_password')
|
||||
|
@ -32,21 +34,6 @@ def valid_test_user(db_engine):
|
|||
password=VALID_USER_VALID_CREDENTIALS.password)
|
||||
|
||||
|
||||
@bdd.scenario('user_authentication.feature', 'Valid user can authenticate against site with valid credentials')
|
||||
def test_authentication_with_valid_credentials():
|
||||
pass
|
||||
|
||||
|
||||
@bdd.scenario('user_authentication.feature', 'Valid user cannot authenticate against site with invalid credentials')
|
||||
def test_authentication_with_invalid_credentials():
|
||||
pass
|
||||
|
||||
|
||||
@bdd.scenario('user_authentication.feature', 'Invalid user cannot authenticate against site with credentials')
|
||||
def test_authentication_with_invalid_user():
|
||||
pass
|
||||
|
||||
|
||||
@bdd.given(parsers.parse('I am a {user_type} user with {login_type} credentials'))
|
||||
def user_credentials(user_type, login_type, valid_test_user):
|
||||
if not user_type == 'valid':
|
||||
|
@ -80,7 +67,11 @@ def assert_valid_user_json_web_token(user_credentials: Credentials, auth_endpoin
|
|||
|
||||
@bdd.then('I get an unauthorized response')
|
||||
def assert_unauthorized_response(auth_endpoint_response: requests.Response):
|
||||
expected_json = {
|
||||
'status_code': http.HTTPStatus.UNAUTHORIZED.value,
|
||||
'error': 'Bad Request',
|
||||
'description': 'Invalid credentials',
|
||||
}
|
||||
|
||||
assert auth_endpoint_response.status_code == http.HTTPStatus.UNAUTHORIZED
|
||||
assert auth_endpoint_response.json()['status_code'] == http.HTTPStatus.UNAUTHORIZED
|
||||
assert auth_endpoint_response.json()['error'] == 'Bad Request'
|
||||
assert auth_endpoint_response.json()['description'] == 'Invalid credentials'
|
||||
assert auth_endpoint_response.json() == expected_json
|
||||
|
|
Loading…
Reference in New Issue