def test_retrieve_user_invalid_credentials(app): from aura.models import User db = get_db() db.session.add(User(username='******', password='******')) db.session.commit() from aura.services import retrieve_user #Non existing user with pytest.raises(ServiceError): retrieve_user({'username':'******', 'password': '******'}) #Wrong password still raises Service error with pytest.raises(ServiceError): retrieve_user({'username':'******', 'password': '******'})
def fresh_login(): result, payload = retrieve_user(g.data) if result: new_token = create_access_token(identity=payload.id, fresh=True) return build_response(SUCCESS, {'access_token': new_token}) else: return build_response(FAIL, str(payload))
def route_login(): result, payload = retrieve_user(g.data) if result: response = { 'access_token': create_access_token(identity=payload.id), 'refresh_token': create_refresh_token(identity=payload.id) } return build_response(SUCCESS, response) else: return build_response(FAIL, str(payload))
def test_retrieve_user(app): from aura.models import User from aura.services import retrieve_user with app.app_context(): db = get_db() db.session.add(User(username='******', password='******')) db.session.commit() user = User.query.filter_by(username='******').first() print("==") print(user) print("==") user = retrieve_user({'username':'******', 'password': '******'}) assert isinstance(user, User) assert user.username == 'admin' assert user.password_is('admin')
def test_retrieve_user_schema(app, data): from aura.services import retrieve_user #Checks absence of keys: password, username with pytest.raises(ServiceError): retrieve_user(data)