def get(self, email): """ --- summary: Get User Metadata by email. parameters: - email tags: - Users-By-Email responses: 200: description: User successully retrieved. content: application/json: schema: $ref: '#/components/schemas/UserSchema' 401: $ref: '#/components/responses/401-Unauthorized' 404: $ref: '#/components/responses/404-NotFound' """ storage = get_storage() auth0_id = get_auth0_id_of_user(email) user_id = storage.read_user_id(auth0_id) user = storage.read_user(user_id) user['email'] = email return jsonify(UserSchema().dump(user))
def delete(self, email, role_id): """ --- summary: Remove a role from a User by email. parameters: - email - role_id tags: - Users-By-Email - Roles responses: 204: description: Role removed successfully.. 401: $ref: '#/components/responses/401-Unauthorized' 404: $ref: '#/components/responses/404-NotFound' """ storage = get_storage() auth0_id = get_auth0_id_of_user(email) try: user_id = storage.read_user_id(auth0_id) except StorageAuthError: return '', 204 return super().delete(user_id, role_id)
def test_get_auth0_id_of_user_empty(running_app, email, requests_mock, token_set): requests_mock.register_uri( 'GET', re.compile(running_app.config['AUTH0_BASE_URL'] + '/.*'), content=b'[]') out = auth0_info.get_auth0_id_of_user(email) assert out == 'Unable to retrieve'
def test_get_auth0_id_of_user_http_err(running_app, email, requests_mock, token_set): requests_mock.register_uri( 'GET', re.compile(running_app.config['AUTH0_BASE_URL'] + '/.*'), status_code=401) out = auth0_info.get_auth0_id_of_user(email) assert out == 'Unable to retrieve'
def test_get_auth0_id_of_user(running_app, auth0id, email, requests_mock, token_set): requests_mock.register_uri( 'GET', re.compile(running_app.config['AUTH0_BASE_URL'] + '/.*'), content=f'[{{"user_id": "{auth0id}"}}]'.encode()) out = auth0_info.get_auth0_id_of_user(email) assert out == auth0id r = auth0_info.token_redis_connection() assert r.get(email) == auth0id assert 90000 > r.ttl(email) > 80000
def post(self, email, role_id): """ --- summary: Add a Role to a User by email. parameters: - email - role_id tags: - Users-By-Email - Roles responses: 204: description: Role Added Successfully. 401: $ref: '#/components/responses/401-Unauthorized' 404: $ref: '#/components/responses/404-NotFound' """ storage = get_storage() auth0_id = get_auth0_id_of_user(email) user_id = storage.read_user_id(auth0_id) return super().post(user_id, role_id)
def test_get_auth0_id_of_user_in_redis(running_app, auth0id, email, email_in_redis, token_set): assert auth0_info.get_auth0_id_of_user(email) == auth0id