Skip to content

Commit f3fe567

Browse files
jstone-devbencap
authored andcommitted
Fixes for MyPy and preexisting unit tests
1 parent c68e081 commit f3fe567

File tree

5 files changed

+22
-16
lines changed

5 files changed

+22
-16
lines changed

src/mavedb/routers/collections.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from mavedb import deps
1212
from mavedb.lib.authentication import UserData, get_current_user
13-
from mavedb.lib.authorization import require_current_user_with_email
13+
from mavedb.lib.authorization import require_current_user, require_current_user_with_email
1414
from mavedb.lib.logging import LoggedRoute
1515
from mavedb.lib.logging.context import (
1616
format_raised_exception_info_as_dict,
@@ -46,7 +46,7 @@
4646
def list_my_collections(
4747
*,
4848
db: Session = Depends(deps.get_db),
49-
user_data: Optional[UserData] = Depends(get_current_user),
49+
user_data: UserData = Depends(require_current_user),
5050
) -> Dict[str, Sequence[Collection]]:
5151
"""
5252
List my collections.
@@ -685,7 +685,7 @@ async def add_user_to_collection_role(
685685
)
686686
# A user can only be in one role per collection, so remove from any other roles
687687
elif collection_user_association:
688-
item.users.remove(User)
688+
item.users.remove(user)
689689

690690
setattr(user, "role", role)
691691
item.users.append(user)
@@ -762,7 +762,7 @@ async def remove_user_from_collection_role(
762762
assert_permission(user_data, item, Action.ADD_ROLE)
763763

764764
# Since this is a post request, user should not already be in this role
765-
if collection_user_association.contribution_role != role:
765+
if collection_user_association is not None and collection_user_association.contribution_role != role:
766766
logger.info(
767767
msg="Failed to remove user from collection role; the requested user does not currently hold the requested role for this collection.",
768768
extra=logging_context(),

src/mavedb/routers/permissions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ async def check_permission(
5050
"""
5151
save_to_logging_context({"requested_resource": urn})
5252

53-
item: Optional[Union[ExperimentSet, Experiment, ScoreSet]] = None
53+
item: Optional[Union[Collection, ExperimentSet, Experiment, ScoreSet]] = None
5454

5555
if model_name == ModelName.experiment_set:
5656
item = db.query(ExperimentSet).filter(ExperimentSet.urn == urn).one_or_none()

src/mavedb/view_models/collection.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,16 @@ class CollectionBase(BaseModel):
3333
)
3434

3535

36-
class CollectionModify(CollectionBase):
36+
class CollectionModify(BaseModel):
3737
# all fields should be optional, because the client should specify only the fields they want to update
3838
private: Optional[bool] = Field(
3939
description="Whether the collection is visible to all MaveDB users. If set during collection update, input ignored unless requesting user is collection admin."
4040
)
4141
name: Optional[str]
42+
description: Optional[str]
43+
badge_name: Optional[str] = Field(
44+
description="Badge name. Input ignored unless requesting user has MaveDB admin privileges."
45+
)
4246

4347

4448
class CollectionCreate(CollectionBase):

tests/helpers/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@
244244
# keys to be set after receiving response
245245
"urn": None,
246246
"experimentSetUrn": None,
247+
"officialCollections": [],
247248
}
248249

249250
TEST_EXPERIMENT_WITH_KEYWORD_RESPONSE = {
@@ -282,6 +283,7 @@
282283
# keys to be set after receiving response
283284
"urn": None,
284285
"experimentSetUrn": None,
286+
"officialCollections": [],
285287
}
286288

287289
TEST_EXPERIMENT_WITH_KEYWORD_HAS_DUPLICATE_OTHERS_RESPONSE = {
@@ -330,6 +332,7 @@
330332
# keys to be set after receiving response
331333
"urn": None,
332334
"experimentSetUrn": None,
335+
"officialCollections": [],
333336
}
334337

335338
TEST_TAXONOMY = {
@@ -522,6 +525,7 @@
522525
# keys to be set after receiving response
523526
"urn": None,
524527
"processingState": ProcessingState.incomplete.name,
528+
"officialCollections": [],
525529
}
526530

527531
TEST_MINIMAL_ACC_SCORESET = {
@@ -606,6 +610,7 @@
606610
# keys to be set after receiving response
607611
"urn": None,
608612
"processingState": ProcessingState.incomplete.name,
613+
"officialCollections": [],
609614
}
610615

611616
TEST_CDOT_TRANSCRIPT = {

tests/routers/test_permissions.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,8 @@ def test_cannot_get_permission_with_wrong_action_in_experiment_set(client, setup
6565
assert response.status_code == 422
6666
response_data = response.json()
6767
assert (
68-
response_data["detail"][0]["msg"] == "value is not a valid enumeration member; permitted: 'read', "
69-
"'update', 'delete', 'add_experiment', 'add_score_set', 'set_scores',"
70-
" 'add_role', 'publish'"
68+
response_data["detail"][0]["msg"] == "value is not a valid enumeration member; permitted: 'lookup', 'read', "
69+
"'update', 'delete', 'add_experiment', 'add_score_set', 'set_scores', 'add_role', 'publish', 'add_badge'"
7170
)
7271

7372

@@ -210,9 +209,8 @@ def test_cannot_get_permission_with_wrong_action_in_experiment(client, setup_rou
210209
assert response.status_code == 422
211210
response_data = response.json()
212211
assert (
213-
response_data["detail"][0]["msg"] == "value is not a valid enumeration member; permitted: 'read', "
214-
"'update', 'delete', 'add_experiment', 'add_score_set', 'set_scores',"
215-
" 'add_role', 'publish'"
212+
response_data["detail"][0]["msg"] == "value is not a valid enumeration member; permitted: 'lookup', 'read', "
213+
"'update', 'delete', 'add_experiment', 'add_score_set', 'set_scores', 'add_role', 'publish', 'add_badge'"
216214
)
217215

218216

@@ -347,9 +345,8 @@ def test_cannot_get_permission_with_wrong_action_in_score_set(client, setup_rout
347345
assert response.status_code == 422
348346
response_data = response.json()
349347
assert (
350-
response_data["detail"][0]["msg"] == "value is not a valid enumeration member; permitted: 'read', "
351-
"'update', 'delete', 'add_experiment', 'add_score_set', 'set_scores',"
352-
" 'add_role', 'publish'"
348+
response_data["detail"][0]["msg"] == "value is not a valid enumeration member; permitted: 'lookup', 'read', "
349+
"'update', 'delete', 'add_experiment', 'add_score_set', 'set_scores', 'add_role', 'publish', 'add_badge'"
353350
)
354351

355352

@@ -369,5 +366,5 @@ def test_cannot_get_permission_with_non_existing_item(client, setup_router_db):
369366
response_data = response.json()
370367
assert (
371368
response_data["detail"][0]["msg"] == "value is not a valid enumeration member; permitted: "
372-
"'experiment', 'experiment-set', 'score-set'"
369+
"'collection', 'experiment', 'experiment-set', 'score-set'"
373370
)

0 commit comments

Comments
 (0)