Skip to content

Commit d2fb46e

Browse files
authored
Fix linter issues in user management (#54)
1 parent 3355de7 commit d2fb46e

File tree

4 files changed

+105
-94
lines changed

4 files changed

+105
-94
lines changed

components/user_management/src/routes/discipline_association_group_test.py

+33-29
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
from routes.discipline_association_group import router
2525
from testing.test_config import API_URL
2626
from schemas.schema_examples import (BASIC_ASSOCIATION_GROUP_EXAMPLE,
27-
BASIC_USER_MODEL_EXAMPLE,
28-
TEST_CURRICULUM_PATHWAY,
29-
FULL_DISCIPLINE_ASSOCIATION_GROUP_EXAMPLE,
30-
FULL_USER_MODEL_EXAMPLE,
31-
BASIC_CURRICULUM_PATHWAY_EXAMPLE)
27+
BASIC_USER_MODEL_EXAMPLE,
28+
TEST_CURRICULUM_PATHWAY,
29+
FULL_DISCIPLINE_ASSOCIATION_GROUP_EXAMPLE,
30+
FULL_USER_MODEL_EXAMPLE,
31+
BASIC_CURRICULUM_PATHWAY_EXAMPLE)
3232
from common.models import AssociationGroup, UserGroup, User, CurriculumPathway
3333
from common.testing.firestore_emulator import (firestore_emulator,
3434
clean_firestore)
@@ -62,11 +62,11 @@ def test_get_association_group(clean_firestore):
6262
json_response = resp.json()
6363

6464
assert resp.status_code == 200, "Status 200"
65-
assert json_response["data"]["association_type"] == \
66-
association_group_dict["association_type"]
65+
assert (json_response["data"]["association_type"] ==
66+
association_group_dict["association_type"])
6767
assert json_response["data"]["name"] == association_group_dict["name"]
68-
assert json_response["data"]["description"] == \
69-
association_group_dict["description"]
68+
assert (json_response["data"]["description"] ==
69+
association_group_dict["description"])
7070

7171

7272
def test_get_association_group_negative(clean_firestore):
@@ -198,8 +198,9 @@ def test_post_association_group_negative(clean_firestore):
198198

199199
assert post_resp_json.get("success") is False, "Success not False"
200200
assert post_resp.status_code == 409
201-
assert post_resp_json.get("message") == \
202-
"AssociationGroup with the given name: Association Group1 already exists"
201+
assert (post_resp_json.get("message") ==
202+
"AssociationGroup with the given name: "
203+
"Association Group1 already exists")
203204

204205

205206
def test_update_association_group(clean_firestore):
@@ -221,8 +222,8 @@ def test_update_association_group(clean_firestore):
221222
update_response = resp.json()
222223

223224
assert update_response.get("success") is True, "Success not true"
224-
assert update_response["message"] == \
225-
"Successfully updated the association group"
225+
assert (update_response["message"] ==
226+
"Successfully updated the association group")
226227
assert update_response["data"]["name"] == "new group name"
227228
assert update_response["data"]["description"] == "new group description"
228229

@@ -257,8 +258,9 @@ def test_update_association_group_negative_1(clean_firestore):
257258

258259
assert update_response.get("success") is False, "Success not False"
259260
assert resp.status_code == 409
260-
assert update_response.get("message") == \
261-
"AssociationGroup with the given name: Association Group already exists"
261+
assert (update_response.get("message") ==
262+
"AssociationGroup with the given name: "
263+
"Association Group already exists")
262264

263265

264266
def test_update_association_group_negative_2(clean_firestore):
@@ -318,7 +320,6 @@ def test_delete_association_group(clean_firestore):
318320
association_group.uuid = association_group.id
319321
association_group.update()
320322

321-
322323
learner_association_group_dict = {
323324
**BASIC_ASSOCIATION_GROUP_EXAMPLE, "association_type": "learner"
324325
}
@@ -350,7 +351,7 @@ def test_delete_association_group(clean_firestore):
350351
assert resp.status_code == 200, "Status code not 200"
351352
assert del_json_response == expected_data, "Expected response not same"
352353

353-
get_learner_association_group = AssociationGroup.find_by_uuid(
354+
get_learner_association_group = AssociationGroup.find_by_uuid(
354355
learner_association_group_uuid)
355356
assert get_learner_association_group.associations["instructors"] == []
356357

@@ -405,7 +406,7 @@ def test_add_discipline_to_discipline_association_group(clean_firestore):
405406
# test for ResourceNotFound
406407
url = f"{api_url}/wrong_id/discipline/add"
407408
resp = client_with_emulator.post(url, json=request_body)
408-
json_response = resp.json()["data"]
409+
_ = resp.json()["data"]
409410
assert resp.status_code == 404, f"Status Code = {resp.status_code}"
410411

411412
# test for ValidationError
@@ -446,13 +447,13 @@ def test_remove_discipline_from_discipline_association_group(clean_firestore):
446447
resp = client_with_emulator.post(url, json=request_body)
447448
json_response = resp.json()["data"]
448449
assert resp.status_code == 200, f"Status {resp.status_code}"
449-
assert json_response["associations"]["curriculum_pathways"] == [], \
450-
"Associations not same"
450+
assert (json_response["associations"]["curriculum_pathways"] ==
451+
[]), "Associations not same"
451452

452453
# test for ResourceNotFound
453454
url = f"{api_url}/wrong_id/discipline/remove"
454455
resp = client_with_emulator.post(url, json=request_body)
455-
json_response = resp.json()["data"]
456+
_ = resp.json()["data"]
456457
assert resp.status_code == 404, f"Status Code = {resp.status_code}"
457458

458459
# test for ValidationError
@@ -488,7 +489,9 @@ def create_user_and_group(user_group_name, user_type):
488489
user_dict.update()
489490
user_id2 = user_dict.user_id
490491

491-
GROUP_EXAMPLE = {"name": user_group_name, "users": [user_id1, user_id2], "description" : "example group"}
492+
GROUP_EXAMPLE = {"name": user_group_name,
493+
"users": [user_id1, user_id2],
494+
"description": "example group"}
492495

493496
group_dict = UserGroup.from_dict({**GROUP_EXAMPLE})
494497
group_dict.uuid = ""
@@ -540,7 +543,7 @@ def test_remove_user_from_discipline_association_group(clean_firestore):
540543
assert len(post_resp_json.get("data").get("users")) == 2
541544
assert post_resp_json["data"]["users"][0]["user"] in add_users["users"]
542545

543-
# Remove user from the assication group
546+
# Remove user from the association group
544547
url = api_url + f"/{uuid}/user/remove"
545548
remove_user = {"user": add_users["users"][0]}
546549
post_resp = client_with_emulator.post(url, json=remove_user)
@@ -594,8 +597,8 @@ def test_update_association_status(clean_firestore):
594597
update_response = resp.json()
595598

596599
assert update_response.get("success") is True, "Success not true"
597-
assert update_response["message"] == \
598-
"Successfully updated the association group"
600+
assert (update_response["message"] ==
601+
"Successfully updated the association group")
599602
assert update_response["data"]["users"][0]["status"] == "inactive"
600603

601604

@@ -641,8 +644,9 @@ def test_update_association_status_negative_1(clean_firestore):
641644
update_response = resp.json()
642645

643646
assert update_response.get("success") is False, "Success not False"
644-
assert update_response["message"] == \
645-
"User for given user_id is not present in the discipline association group"
647+
assert (update_response["message"] ==
648+
"User for given user_id is not present "
649+
"in the discipline association group")
646650

647651

648652
def test_update_association_status_negative_2(clean_firestore):
@@ -701,7 +705,7 @@ def test_get_instructors_associated_to_discipline(clean_firestore):
701705
user.update()
702706

703707
users.append({"user": user.user_id, "status": "active"})
704-
users[i]["user_type"] = "assessor" if i%2 == 0 else "instructor"
708+
users[i]["user_type"] = "assessor" if i % 2 == 0 else "instructor"
705709

706710
curriculum_pathway_dict = deepcopy(BASIC_CURRICULUM_PATHWAY_EXAMPLE)
707711
curriculum_pathway = CurriculumPathway.from_dict(curriculum_pathway_dict)
@@ -743,7 +747,7 @@ def test_add_user_to_discipline_association_group_negative(clean_firestore):
743747
add_users = {"users": add_users, "status": "active"}
744748
url = api_url + f"/{uuid}/users/add"
745749
post_resp = client_with_emulator.post(url, json=add_users)
746-
post_resp_json = post_resp.json()
750+
_ = post_resp.json()
747751
assert post_resp.status_code == 200, "Status 200"
748752

749753
url = api_url + f"/{uuid}/users/add"

components/user_management/src/routes/learner_association_group_test.py

+34-31
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ def test_post_association_group(clean_firestore):
177177

178178
def test_post_association_group_negative(clean_firestore):
179179
# Create learner association group:
180-
active_cp=create_curriculum_pathway(
180+
active_cp = create_curriculum_pathway(
181181
payload={**BASIC_CURRICULUM_PATHWAY_EXAMPLE,
182182
"is_active": True, "alias": "program",
183-
"is_deleted": False})
183+
"is_deleted": False})
184184
input_group = {**BASIC_ASSOCIATION_GROUP_EXAMPLE, "name": "Learner Group1"}
185185
url = api_url
186186
post_resp = client_with_emulator.post(url, json=input_group)
@@ -437,7 +437,7 @@ def test_update_association_status_2(clean_firestore):
437437
discipline_group.users = [{"user": user_2.user_id, "status": "active"}]
438438
discipline_group.associations = {
439439
"curriculum_pathways": [{
440-
"curriculum_pathway_id": curriculum_pathway_id, "status": "active"
440+
"curriculum_pathway_id": curriculum_pathway_id, "status": "active"
441441
}]
442442
}
443443
discipline_group.update()
@@ -468,7 +468,7 @@ def test_update_association_status_2(clean_firestore):
468468
url = f"{api_url}/{association_group_uuid}/user-association/status"
469469
request_body = {
470470
"instructor": {"instructor_id": user_2.user_id,
471-
"curriculum_pathway_id":curriculum_pathway_id,
471+
"curriculum_pathway_id": curriculum_pathway_id,
472472
"status": "active"}
473473
}
474474

@@ -615,7 +615,7 @@ def test_update_association_status_negative_3(clean_firestore):
615615
discipline_group.users = [{"user": user_2.user_id, "status": "inactive"}]
616616
discipline_group.associations = {
617617
"curriculum_pathways": [{
618-
"curriculum_pathway_id": curriculum_pathway_id, "status": "active"
618+
"curriculum_pathway_id": curriculum_pathway_id, "status": "active"
619619
}]
620620
}
621621
discipline_group.update()
@@ -646,7 +646,7 @@ def test_update_association_status_negative_3(clean_firestore):
646646
url = f"{api_url}/{association_group_uuid}/user-association/status"
647647
request_body = {
648648
"instructor": {"instructor_id": user_2.user_id,
649-
"curriculum_pathway_id":curriculum_pathway_id,
649+
"curriculum_pathway_id": curriculum_pathway_id,
650650
"status": "active"}
651651
}
652652

@@ -683,7 +683,9 @@ def create_user_and_group(user_group_name, user_type):
683683
user_dict.update()
684684
user_id2 = user_dict.user_id
685685

686-
group_example = {"name": user_group_name, "users": [user_id1, user_id2], "description" : "example group"}
686+
group_example = {"name": user_group_name,
687+
"users": [user_id1, user_id2],
688+
"description": "example group"}
687689

688690
group_dict = UserGroup.from_dict(group_example)
689691
group_dict.uuid = ""
@@ -894,6 +896,7 @@ def create_learner_association_group(payload: dict,
894896
Parameters
895897
----------
896898
payload: dict
899+
program_id: str
897900
898901
Returns
899902
-------
@@ -942,7 +945,7 @@ def test_add_instructor_positive_1(mocker, clean_firestore):
942945
}]
943946
discipline_assoc.associations = {
944947
"curriculum_pathways": [
945-
{"curriculum_pathway_id": curriculum_pathway_id, "status": "active"}
948+
{"curriculum_pathway_id": curriculum_pathway_id, "status": "active"}
946949
]
947950
}
948951
discipline_assoc.update()
@@ -973,12 +976,12 @@ def test_add_instructor_positive_2(mocker, clean_firestore):
973976
Add Instructor for various curriculum pathway
974977
"""
975978
# Create curriculum pathway
976-
pathway_id, pathway_id_1, pathway_id_2, program_id = \
977-
create_disciplines_and_programs()
979+
pathway_id, pathway_id_1, pathway_id_2, program_id = (
980+
create_disciplines_and_programs())
978981

979982
mocker.patch(
980983
"routes.learner_association_group.get_all_discipline_for_given_program",
981-
return_value=[pathway_id,pathway_id_1, pathway_id_2])
984+
return_value=[pathway_id, pathway_id_1, pathway_id_2])
982985

983986
# Create User as type faculty
984987
user = {**BASIC_USER_MODEL_EXAMPLE, "user_type": "instructor"}
@@ -1000,7 +1003,7 @@ def test_add_instructor_positive_2(mocker, clean_firestore):
10001003
}]
10011004
discipline_assoc.associations = {
10021005
"curriculum_pathways": [
1003-
{"curriculum_pathway_id": pathway_id, "status": "active"}
1006+
{"curriculum_pathway_id": pathway_id, "status": "active"}
10041007
]
10051008
}
10061009
discipline_assoc.update()
@@ -1041,8 +1044,8 @@ def test_add_instructor_positive_3(mocker, clean_firestore):
10411044
Add Instructor for existing removed instructor curriculum pathway
10421045
"""
10431046
# Create curriculum pathway
1044-
curriculum_pathway_id, _, pathway_id_2, program_id = \
1045-
create_disciplines_and_programs()
1047+
curriculum_pathway_id, _, pathway_id_2, program_id = (
1048+
create_disciplines_and_programs())
10461049

10471050
mocker.patch(
10481051
"routes.learner_association_group.get_all_discipline_for_given_program",
@@ -1068,7 +1071,7 @@ def test_add_instructor_positive_3(mocker, clean_firestore):
10681071
}]
10691072
discipline_assoc.associations = {
10701073
"curriculum_pathways": [
1071-
{"curriculum_pathway_id": curriculum_pathway_id, "status": "active"}
1074+
{"curriculum_pathway_id": curriculum_pathway_id, "status": "active"}
10721075
]
10731076
}
10741077
discipline_assoc.update()
@@ -1215,8 +1218,8 @@ def test_add_instructor_negative_6(mocker, clean_firestore):
12151218
"""
12161219

12171220
# Create curriculum pathway
1218-
curriculum_pathway_id, _, pathway_id_2, program_id = \
1219-
create_disciplines_and_programs()
1221+
curriculum_pathway_id, _, pathway_id_2, program_id = (
1222+
create_disciplines_and_programs())
12201223

12211224
mocker.patch(
12221225
"routes.learner_association_group.get_all_discipline_for_given_program",
@@ -1242,7 +1245,7 @@ def test_add_instructor_negative_6(mocker, clean_firestore):
12421245
}]
12431246
discipline_assoc.associations = {
12441247
"curriculum_pathways": [
1245-
{"curriculum_pathway_id": curriculum_pathway_id, "status": "active"}
1248+
{"curriculum_pathway_id": curriculum_pathway_id, "status": "active"}
12461249
]
12471250
}
12481251
discipline_assoc.update()
@@ -1270,8 +1273,8 @@ def test_remove_instructor_positive_1(mocker, clean_firestore):
12701273
Remove Instructor with correct payload
12711274
"""
12721275
# Create curriculum pathway
1273-
curriculum_pathway_id, _, pathway_id_2, program_id = \
1274-
create_disciplines_and_programs()
1276+
curriculum_pathway_id, _, pathway_id_2, program_id = (
1277+
create_disciplines_and_programs())
12751278

12761279
mocker.patch(
12771280
"routes.learner_association_group.get_all_discipline_for_given_program",
@@ -1297,7 +1300,7 @@ def test_remove_instructor_positive_1(mocker, clean_firestore):
12971300
}]
12981301
discipline_assoc.associations = {
12991302
"curriculum_pathways": [
1300-
{"curriculum_pathway_id": curriculum_pathway_id, "status": "active"}
1303+
{"curriculum_pathway_id": curriculum_pathway_id, "status": "active"}
13011304
]
13021305
}
13031306
discipline_assoc.update()
@@ -1328,8 +1331,8 @@ def test_remove_instructor_positive_2(mocker, clean_firestore):
13281331
Remove Instructor from multiple instructors
13291332
"""
13301333
# Create curriculum pathway
1331-
pathway_id, pathway_id_1, pathway_id_2, program_id = \
1332-
create_disciplines_and_programs()
1334+
pathway_id, pathway_id_1, pathway_id_2, program_id = (
1335+
create_disciplines_and_programs())
13331336

13341337
mocker.patch(
13351338
"routes.learner_association_group.get_all_discipline_for_given_program",
@@ -1355,7 +1358,7 @@ def test_remove_instructor_positive_2(mocker, clean_firestore):
13551358
}]
13561359
discipline_assoc.associations = {
13571360
"curriculum_pathways": [
1358-
{"curriculum_pathway_id": pathway_id_1, "status": "active"}
1361+
{"curriculum_pathway_id": pathway_id_1, "status": "active"}
13591362
]
13601363
}
13611364
discipline_assoc.update()
@@ -1522,7 +1525,7 @@ def test_remove_instructor_negative_6(mocker, clean_firestore):
15221525
}]
15231526
discipline_assoc.associations = {
15241527
"curriculum_pathways": [
1525-
{"curriculum_pathway_id": curriculum_pathway_id, "status": "active"}
1528+
{"curriculum_pathway_id": curriculum_pathway_id, "status": "active"}
15261529
]
15271530
}
15281531
discipline_assoc.update()
@@ -1589,8 +1592,8 @@ def test_remove_instructor_negative_8(mocker, clean_firestore):
15891592
"""
15901593
Remove instructor wrong curriculum pathway ID
15911594
"""
1592-
curriculum_pathway_id, pathway_id_1, pathway_2, program_id = \
1593-
create_disciplines_and_programs()
1595+
curriculum_pathway_id, pathway_id_1, pathway_2, program_id = (
1596+
create_disciplines_and_programs())
15941597

15951598
mocker.patch(
15961599
"routes.learner_association_group.get_all_discipline_for_given_program",
@@ -1687,8 +1690,8 @@ def test_get_all_the_learner_for_instructor(clean_firestore):
16871690
res_data = res.json()
16881691
assert res.status_code == 200
16891692
assert res_data["success"] is True
1690-
assert res_data["message"] == "Successfully fetched the learners "\
1691-
"for the given instructor"
1693+
assert (res_data["message"] == "Successfully fetched the learners "
1694+
"for the given instructor")
16921695
assert user_1.user_id in res_data["data"]
16931696

16941697
def test_get_all_the_learner_for_coach(clean_firestore):
@@ -1730,8 +1733,8 @@ def test_get_all_the_learner_for_coach(clean_firestore):
17301733
res_data = res.json()
17311734
assert res.status_code == 200
17321735
assert res_data["success"] is True
1733-
assert res_data["message"] == "Successfully fetched the learners "\
1734-
"for the given coach"
1736+
assert (res_data["message"] ==
1737+
"Successfully fetched the learners for the given coach")
17351738
assert user_1.user_id in res_data["data"]
17361739

17371740
def test_get_all_the_learner_for_coach_and_instructor_negative(clean_firestore):

0 commit comments

Comments
 (0)