def test_create_user(self): """Test case for create user.""" user_utils.create_or_update_user('03ec8318-08ed-4aeb', 'abc', 'SNYK') assert user_utils.get_user( '03ec8318-08ed-4aeb').snyk_api_token == 'abc' assert user_utils.get_user( '03ec8318-08ed-4aeb').status == UserStatus.REGISTERED.name
def test_update_user(self): """Test case for update user.""" assert user_utils.get_user( '03ec8318-08ed-4aeb').snyk_api_token == 'abc' user_utils.create_or_update_user('03ec8318-08ed-4aeb', 'def', 'SNYK') assert user_utils.get_user( '03ec8318-08ed-4aeb').snyk_api_token == 'def'
def wrapper(*args, **kwargs): """Read uuid and decides user type based on its validity.""" # Rule of UUID validation and setting user status :: # ============================================================== # UUID in request | UUID in RDS | RDS User State | User Status # ============================================================== # MISSING | -- NA -- | -- NA -- | FREE # PRESENT | MISSING | -- NA -- | FREE # PRESENT | PRESENT | REGISTERED | REGISTERED # PRESENT | PRESENT | !REGISTERED | FREE # ============================================================== # By default set this to 'freetier' and uuid to None g.user_status = UserStatus.FREETIER g.uuid = None try: header_data = HeaderData(uuid=request.headers.get('uuid', None)) if header_data.uuid: g.uuid = str(header_data.uuid) user = get_user(g.uuid) g.user_status = UserStatus[user.status] except ValidationError as e: raise HTTPError(400, "Not a valid uuid") from e except UserNotFoundException: logger.warning("No User Found corresponding to UUID {}".format(header_data.uuid)) except UserException: logger.warning("Unable to get user status for uuid '{}'".format(header_data.uuid)) logger.debug('For UUID: %s, got user type: %s final uuid: %s', header_data.uuid, g.user_status, g.uuid) return view(*args, **kwargs)
def get_user(user_id): """Endpoint for getting user details.""" if not user_id: raise HTTPError(400, "user id should be present") user = user_utils.get_user(user_id) user_status = user.status if user.status else UserStatus.FREETIER.name return jsonify(user_id=user.user_id, status=user_status)
def get_user(user_id): """Endpoint for getting user details.""" if not user_id: raise HTTPError(400, "user id should be present") user_status = UserStatus.FREETIER.name user = user_utils.get_user(user_id) if user: user_status = user.status if user.status else UserStatus.FREETIER.name return jsonify(user_id=user_id, status=user_status) else: return jsonify(message='User not found', status=404), 404
def wrapper(*args, **kwargs): """Read uuid and decides user type based on its validity.""" # Rule of UUID validation and setting user status :: # ============================================================== # UUID in request | UUID in RDS | RDS User State | User Status # ============================================================== # MISSING | -- NA -- | -- NA -- | FREE # PRESENT | MISSING | -- NA -- | FREE # PRESENT | PRESENT | REGISTERED | REGISTERED # PRESENT | PRESENT | !REGISTERED | FREE # ============================================================== # By default set this to 'freetier' and uuid to None g.user_status = UserStatus.FREETIER g.uuid = None try: header_data = HeaderData(uuid=request.headers.get('uuid', None)) if header_data.uuid: g.uuid = str(header_data.uuid) if ENABLE_USER_CACHING: logger.info( "Getting user details from cache for user = %s", g.uuid) user = get_user_from_cache(g.uuid) if user: g.user_status = UserStatus["REGISTERED"] logger.info( 'For UUID: %s, got user type: %s final uuid: %s', header_data.uuid, g.user_status, g.uuid) else: logger.info( 'For UUID: %s, user not found type: %s final uuid: %s', header_data.uuid, g.user_status, g.uuid) else: logger.info("Getting user details from RDS.") user = get_user(g.uuid) if user: g.user_status = UserStatus[user.status] logger.info( 'For UUID: %s, got user type: %s final uuid: %s', header_data.uuid, g.user_status, g.uuid) except ValidationError as e: raise HTTPError(400, "Not a valid uuid") from e except UserException: logger.warning("Unable to get user status for uuid '{}'".format( header_data.uuid)) return view(*args, **kwargs)
def test_get_user_not_found(self): """Test case for get user not found.""" assert user_utils.get_user('uuid') is None
def test_get_user(self): """Test case for get user.""" user = user_utils.get_user('03ec8318-08ed-4aeb') assert user.snyk_api_token == 'abc'
def test_get_user_not_found(self): """Test case for get user not found.""" with pytest.raises(UserNotFoundException): user_utils.get_user('uuid')