Refactor user authentication tests.

This commit is contained in:
Dorian 2017-03-08 21:25:23 -05:00
parent bba746b984
commit 8446354b59
1 changed files with 9 additions and 18 deletions

View File

@ -17,6 +17,8 @@ from pytest_bdd import parsers
from tests import utils from tests import utils
bdd.scenarios('user_authentication.feature')
Credentials = collections.namedtuple('Credentials', ['username', 'password']) Credentials = collections.namedtuple('Credentials', ['username', 'password'])
INVALID_USER_INVALID_CREDENTIALS = Credentials('invalid_user', 'invalid_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) 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')) @bdd.given(parsers.parse('I am a {user_type} user with {login_type} credentials'))
def user_credentials(user_type, login_type, valid_test_user): def user_credentials(user_type, login_type, valid_test_user):
if not user_type == 'valid': 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') @bdd.then('I get an unauthorized response')
def assert_unauthorized_response(auth_endpoint_response: requests.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.status_code == http.HTTPStatus.UNAUTHORIZED
assert auth_endpoint_response.json()['status_code'] == http.HTTPStatus.UNAUTHORIZED assert auth_endpoint_response.json() == expected_json
assert auth_endpoint_response.json()['error'] == 'Bad Request'
assert auth_endpoint_response.json()['description'] == 'Invalid credentials'