def login() -> Dict: """ API to login user. :return: JSON response """ payload = request.get_json() error, result = get_auth_token(**payload) return success(data=result) if not error else failure(message=error)
def _get_user(email: str, password: str) -> Tuple: """ This private method will help in fetching the auth token by hitting the get_auth_token method. :param email: email address in the form of string :param password: password in the form of string :return: Tuple of None and (Token or Value Error) """ from app.auth.services import get_auth_token return get_auth_token(email, password)
def test_get_auth_token_fail2(self, test_client, init_database): """ GIVEN an existing user WHEN get_auth_token() in auth services is called THEN return an error due to wrong password :param test_client: :param init_database: :return: """ from app.auth.services import get_auth_token email = '*****@*****.**' password = '******' token = get_auth_token(email, password) assert str(token[0]) == "Invalid credentials" assert token[1] is None
def test_get_auth_token_ok(self, test_client, init_database): """ GIVEN a database WHEN get_auth_token() in auth services is called THEN return an auth token :param test_client: :param init_database: :return: """ from app.auth.services import get_auth_token email = '*****@*****.**' password = '******' token = get_auth_token(email, password) assert token[0] is None assert type(token[1]) is str
def test_get_auth_token_fail2(self, test_client, init_database): """ GIVEN an existing user WHEN get_auth_token() in auth services is called THEN return an error due to wrong password :param test_client: :param init_database: :return: None """ from app.auth.services import get_auth_token email = TestConstants.TEST_USER_EMAIL_2 password = TestConstants.WRONG_PASSWORD token = get_auth_token(email, password) assert str(token[0]) == TestConstants.INVALID_CREDENTIALS assert token[1] is None
def test_get_auth_token_ok(self, test_client, init_database): """ GIVEN a database WHEN get_auth_token() in auth services is called THEN return an auth token :param test_client: :param init_database: :return: None """ from app.auth.services import get_auth_token email = TestConstants.TEST_USER_EMAIL password = TestConstants.TEST_USER_PASSWORD token = get_auth_token(email, password) assert token[0] is None assert type(token[1]) is str