Skip to content

Commit

Permalink
Update fixtures to return User objects
Browse files Browse the repository at this point in the history
  • Loading branch information
jterry64 committed May 7, 2024
1 parent 97a2ec7 commit 23265cd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
10 changes: 4 additions & 6 deletions app/routes/authentication/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,10 @@ async def create_api_key(
Default keys are valid for one year
"""

user_id, user_role = user.id, user.role

if api_key_data.never_expires and user_role != "ADMIN":
if api_key_data.never_expires and user.role != "ADMIN":
raise HTTPException(
status_code=400,
detail=f"Users with role {user_role} cannot set `never_expires` to True.",
detail=f"Users with role {user.role} cannot set `never_expires` to True.",
)

input_data = api_key_data.dict(by_alias=True)
Expand All @@ -86,15 +84,15 @@ async def create_api_key(

# Give a good error code/message if user is specifying an alias that exists for
# another one of his API keys.
prev_keys: List[ORMApiKey] = await api_keys.get_api_keys_from_user(user_id=user_id)
prev_keys: List[ORMApiKey] = await api_keys.get_api_keys_from_user(user_id=user.id)
for key in prev_keys:
if key.alias == api_key_data.alias:
raise HTTPException(
status_code=409,
detail="Key with specified alias already exists; use a different alias",
)

row: ORMApiKey = await api_keys.create_api_key(user_id=user_id, **input_data)
row: ORMApiKey = await api_keys.create_api_key(user_id=user.id, **input_data)

is_internal = api_key_is_internal(
api_key_data.domains, user_id=None, origin=origin, referrer=referrer
Expand Down
20 changes: 18 additions & 2 deletions tests_v2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,27 @@ def submit_batch_job(self, *args, **kwargs) -> uuid.UUID:


async def get_user_mocked() -> Tuple[str, str]:
return "userid_123", "USER"
return User(
id="userid_123",
name="Ms. User",
email="[email protected]",
createdAt="2021-06-13T03:18:23.000Z",
role="USER",
applications=[],
extraUserData={},
)


async def get_admin_mocked() -> Tuple[str, str]:
return "adminid_123", "ADMIN"
return User(
id="adminid_123",
name="Sir Admin",
email="[email protected]",
createdAt="2021-06-13T03:18:23.000Z",
role="ADMIN",
applications=[],
extraUserData={},
)


async def get_manager_mocked() -> str:
Expand Down

0 comments on commit 23265cd

Please sign in to comment.