def test_unauthorized(self, test_client, credentials): with test_client as client: response = client.post(oauth2_token_url, data=build_form_data(credentials)) assert response.json().get( "detail") == "invalid authentication credentials" assert response.status_code == 401
def test_success(self, test_client, credentials): insert_user({ "email": credentials.email, "password_hash": hash_service.hash_(credentials.password), }) with test_client as client: response = client.post(oauth2_token_url, data=build_form_data(credentials)) body = response.json() assert body["access_token"] assert body["expire"] assert body["token_type"] == "bearer" assert response.status_code == 200
def logged_user(test_client, credentials): id_ = 1 email = credentials.email password_hash = hash_service.hash_(credentials.password) register_user({ "id": id_, "email": credentials.email, "password_hash": password_hash }) with test_client as client: response = client.post(oauth2_token_url, data=build_form_data(credentials)) body = response.json() return LoggedUser( User(id=id_, email=email, password_hash=password_hash), body["access_token"], )