Skip to content

Commit

Permalink
Filter advice by team not user.team
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincarrogan committed Apr 15, 2024
1 parent 6744fa4 commit c1bd748
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 78 deletions.
6 changes: 3 additions & 3 deletions caseworker/advice/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ def filter_advice_by_user(all_advice, caseworker):


def filter_advice_by_users_team(all_advice, caseworker):
return [advice for advice in all_advice if advice["user"]["team"]["id"] == caseworker["team"]["id"]]
return [advice for advice in all_advice if advice["team"]["id"] == caseworker["team"]["id"]]


def filter_advice_by_team(all_advice, team_alias):
return [advice for advice in all_advice if advice["user"]["team"]["alias"] == team_alias]
return [advice for advice in all_advice if advice["team"]["alias"] == team_alias]


def filter_advice_by_teams(all_advice, teams_list):
Expand Down Expand Up @@ -175,7 +175,7 @@ def group_advice_by_team(advice):
result = defaultdict(list)
for item in advice:
if not item.get("good"):
result[item["user"]["team"]["id"]].append(item)
result[item["team"]["id"]].append(item)
return result


Expand Down
2 changes: 1 addition & 1 deletion caseworker/advice/templatetags/advice_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def group_advice(context):
case = context.get("case")
advice_by_team = services.group_advice_by_team(case["advice"])
teams = sorted(
{advice["user"]["team"]["id"]: advice["user"]["team"] for advice in case["advice"]}.values(),
{advice["team"]["id"]: advice["team"] for advice in case["advice"]}.values(),
key=lambda a: a["name"],
)

Expand Down
2 changes: 1 addition & 1 deletion caseworker/advice/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def queue(self):
@property
def teams(self):
return sorted(
{advice["user"]["team"]["id"]: advice["user"]["team"] for advice in self.case["advice"]}.values(),
{advice["team"]["id"]: advice["team"] for advice in self.case["advice"]}.values(),
key=lambda a: a["name"],
)

Expand Down
28 changes: 21 additions & 7 deletions unit_tests/caseworker/advice/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,50 @@ def advice_base_fields():


@pytest.fixture
def consolidated_advice(current_user, team1_user, LU_team_user):
def consolidated_advice(
current_user,
team1_user,
team1,
LU_team_user,
lu_team,
):
current_user["team"]["id"] = "2132131d-2432-423424"
current_user["team"]["alias"] = LICENSING_UNIT_TEAM
return [
{
**advice_base_fields(),
"id": "4f146dd1-a454-49ad-8c78-214552a45207",
"id": "4f146dd1-a454-49ad-8c78-214552a45207", # /PS-IGNORE
"text": "Issue from Team M",
"note": "No additional instructions",
"type": {"key": "approve", "value": "Approve"},
"level": "user",
"footnote": "firearms product for military use",
"user": team1_user,
"team": team1,
"end_user": "94540537-d5e9-40c9-9d8e-8e28792665e1",
},
{
**advice_base_fields(),
"id": "ac914a37-ae50-4a8e-8ebb-0c31b98cfbd2",
"id": "ac914a37-ae50-4a8e-8ebb-0c31b98cfbd2", # /PS-IGNORE
"text": "Issue from Team M",
"note": "No additional instructions",
"type": {"key": "approve", "value": "Approve"},
"level": "user",
"footnote": "firearms product for military use",
"user": team1_user,
"team": team1,
"consignee": "09d08d89-f2f4-4203-a465-11e7c597191c",
},
{
**advice_base_fields(),
"id": "deb3e4f7-3704-4dad-aaa5-855a076bb16f",
"id": "deb3e4f7-3704-4dad-aaa5-855a076bb16f", # /PS-IGNORE
"text": "Issue from Team M",
"note": "No additional instructions",
"type": {"key": "approve", "value": "Approve"},
"level": "user",
"footnote": "firearms product for military use",
"user": team1_user,
"team": team1,
"good": "21f9f169-606d-40a6-91b4-88652d64167e",
},
{
Expand All @@ -68,6 +77,7 @@ def consolidated_advice(current_user, team1_user, LU_team_user):
"proviso": "no other conditions",
"footnote": "",
"user": LU_team_user,
"team": lu_team,
"end_user": "94540537-d5e9-40c9-9d8e-8e28792665e1",
},
{
Expand All @@ -80,40 +90,44 @@ def consolidated_advice(current_user, team1_user, LU_team_user):
"proviso": "no other conditions",
"footnote": "",
"user": LU_team_user,
"team": lu_team,
"consignee": "09d08d89-f2f4-4203-a465-11e7c597191c",
},
{
**advice_base_fields(),
"id": "2f580ac6-07ec-46f0-836c-0bbb282e6886",
"id": "2f580ac6-07ec-46f0-836c-0bbb282e6886", # /PS-IGNORE
"text": "Issue from LU",
"note": "",
"type": {"key": "proviso", "value": "Proviso"},
"level": "final",
"proviso": "no other conditions",
"footnote": "",
"user": LU_team_user,
"team": lu_team,
"good": "21f9f169-606d-40a6-91b4-88652d64167e",
"third_party": "95c2d6b7-5cfd-47e8-b3c8-dc76e1ac9747",
},
{
**advice_base_fields(),
"id": "2f580ac6-07ec-46f0-836c-0bbb282e6886",
"id": "2f580ac6-07ec-46f0-836c-0bbb282e6886", # /PS-IGNORE
"text": "Issue from LU",
"note": "",
"type": {"key": "proviso", "value": "Proviso"},
"level": "team",
"proviso": "no other conditions",
"footnote": "",
"user": LU_team_user,
"team": lu_team,
"good": "21f9f169-606d-40a6-91b4-88652d64167e",
},
]


@pytest.fixture
def advice_for_lu_countersign(consolidated_advice, LU_team_user):
def advice_for_lu_countersign(consolidated_advice, LU_team_user, lu_team):
final_advice = [item for item in consolidated_advice if item["level"] == "final"]
for item in final_advice:
item["user"] = LU_team_user
item["team"] = lu_team

return final_advice
4 changes: 4 additions & 0 deletions unit_tests/caseworker/advice/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ def advice_for_countersign(advice):
for item in advice:
item["user"]["team"]["id"] = "2132131d-2432-423424"
item["user"]["team"]["alias"] = LICENSING_UNIT_TEAM
item["team"] = {
"id": "2132131d-2432-423424",
"alias": LICENSING_UNIT_TEAM,
}
item["level"] = "final"
for_countersign.append(item)

Expand Down
18 changes: 16 additions & 2 deletions unit_tests/caseworker/advice/views/test_consolidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def view_consolidate_outcome_url(data_queue, data_standard_case):


@pytest.fixture
def advice(current_user):
def advice(current_user, admin_team):
return [
{
"consignee": "cd2263b4-a427-4f14-8552-505e1d192bb8",
Expand All @@ -80,6 +80,7 @@ def advice(current_user):
"type": {"key": "approve", "value": "Approve"},
"ultimate_end_user": None,
"user": current_user,
"team": admin_team,
}
for good_id in ("0bedd1c3-cf97-4aad-b711-d5c9a9f4586e", "6daad1c3-cf97-4aad-b711-d5c9a9f4586e")
]
Expand Down Expand Up @@ -157,7 +158,16 @@ def advice(current_user):


@pytest.fixture
def advice_to_consolidate(MOD_team1_user, MOD_team2_user, MOD_ECJU_team_user, FCDO_team_user):
def advice_to_consolidate(
MOD_team1_user,
MOD_team1,
MOD_team2_user,
MOD_team2,
MOD_ECJU_team_user,
MOD_ECJU_team,
FCDO_team_user,
fcdo_team,
):
return [
{
"consignee": None,
Expand All @@ -178,6 +188,7 @@ def advice_to_consolidate(MOD_team1_user, MOD_team2_user, MOD_ECJU_team_user, FC
"type": {"key": "proviso", "value": "Proviso"},
"ultimate_end_user": None,
"user": MOD_team1_user,
"team": MOD_team1,
},
{
"consignee": None,
Expand All @@ -199,6 +210,7 @@ def advice_to_consolidate(MOD_team1_user, MOD_team2_user, MOD_ECJU_team_user, FC
"type": {"key": "proviso", "value": "Proviso"},
"ultimate_end_user": None,
"user": MOD_team2_user,
"team": MOD_team2,
},
{
"consignee": None,
Expand All @@ -220,6 +232,7 @@ def advice_to_consolidate(MOD_team1_user, MOD_team2_user, MOD_ECJU_team_user, FC
"type": {"key": "proviso", "value": "Proviso"},
"ultimate_end_user": None,
"user": MOD_ECJU_team_user,
"team": MOD_ECJU_team,
},
{
"consignee": None,
Expand Down Expand Up @@ -254,6 +267,7 @@ def advice_to_consolidate(MOD_team1_user, MOD_team2_user, MOD_ECJU_team_user, FC
"type": {"key": "approve", "value": "Approve"},
"ultimate_end_user": None,
"user": FCDO_team_user,
"team": fcdo_team,
},
]

Expand Down
13 changes: 7 additions & 6 deletions unit_tests/caseworker/advice/views/test_consolidate_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ def get_advice_subjects(case):


@pytest.fixture
def consolidated_advice(data_standard_case, current_user):
current_user["team"]["id"] = "2132131d-2432-423424"
current_user["team"]["alias"] = services.LICENSING_UNIT_TEAM
def consolidated_advice(data_standard_case, current_user, lu_team):
current_user["team"] = lu_team
subjects = get_advice_subjects(data_standard_case)

return [
{
"id": str(uuid4()),
"user": current_user,
"team": lu_team,
"type": {"key": "approve", "value": "Approve"},
"text": "meets the requirements",
"note": "",
Expand Down Expand Up @@ -423,15 +423,16 @@ def test_edit_advice_get_displays_correct_counteradvice(
mod_countersigned_advice,
advice_type,
expected_title,
lu_team,
):
team = services.LICENSING_UNIT_TEAM
mock_get_gov_user.return_value = ({"user": {"team": {"id": TEAM_ID, "alias": team}}}, None)
mock_get_gov_user.return_value = ({"user": {"team": lu_team}}, None)
case_data = data_standard_case
case_data["case"]["data"]["goods"] = standard_case_with_advice["data"]["goods"]
# Add final advice
for advice in standard_case_with_advice["advice"]:
advice["level"] = "final"
advice["user"]["team"]["alias"] = team
advice["user"]["team"] = lu_team
advice["team"] = lu_team
more_advice = copy.deepcopy(standard_case_with_advice["advice"])
more_advice[0]["id"] = "d8cbfd81-290d-4c98-958b-621c0876dffc"
case_data["case"]["advice"] += more_advice
Expand Down
1 change: 1 addition & 0 deletions unit_tests/caseworker/advice/views/test_view_ogd_advice.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def test_fcdo_cannot_advice_when_all_destinations_covered(
"id": "2a43805b-c082-47e7-9188-c8b3e1a83cb0",
"team": {"id": "67b9a4a3-6f3d-4511-8a19-23ccff221a74", "name": "FCDO", "alias": services.FCDO_TEAM},
},
"team": {"id": "67b9a4a3-6f3d-4511-8a19-23ccff221a74", "name": "FCDO", "alias": services.FCDO_TEAM},
"type": {"value": "Approve"},
},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ def setup(mock_queue, mock_denial_reasons, mock_approval_reason, mock_proviso, m


@pytest.fixture
def group_advice(MOD_team1_user, MOD_team2_user, MOD_ECJU_team_user, FCDO_team_user, LU_team_user):
def group_advice(
MOD_team1_user,
MOD_team1,
MOD_team2_user,
MOD_team2,
MOD_ECJU_team_user,
MOD_ECJU_team,
FCDO_team_user,
fcdo_team,
LU_team_user,
lu_team,
):
return [
{
"consignee": None,
Expand All @@ -30,6 +41,7 @@ def group_advice(MOD_team1_user, MOD_team2_user, MOD_ECJU_team_user, FCDO_team_u
"type": {"key": "proviso", "value": "Proviso"},
"ultimate_end_user": None,
"user": MOD_team1_user,
"team": MOD_team1,
},
{
"consignee": None,
Expand All @@ -51,6 +63,7 @@ def group_advice(MOD_team1_user, MOD_team2_user, MOD_ECJU_team_user, FCDO_team_u
"type": {"key": "proviso", "value": "Proviso"},
"ultimate_end_user": None,
"user": MOD_team2_user,
"team": MOD_team2,
},
{
"consignee": None,
Expand All @@ -72,6 +85,7 @@ def group_advice(MOD_team1_user, MOD_team2_user, MOD_ECJU_team_user, FCDO_team_u
"type": {"key": "proviso", "value": "Proviso"},
"ultimate_end_user": None,
"user": MOD_ECJU_team_user,
"team": MOD_ECJU_team,
},
{
"consignee": None,
Expand Down Expand Up @@ -106,6 +120,7 @@ def group_advice(MOD_team1_user, MOD_team2_user, MOD_ECJU_team_user, FCDO_team_u
"type": {"key": "refuse", "value": "Refuse"},
"ultimate_end_user": None,
"user": FCDO_team_user,
"team": fcdo_team,
},
{
"consignee": None,
Expand Down Expand Up @@ -140,6 +155,7 @@ def group_advice(MOD_team1_user, MOD_team2_user, MOD_ECJU_team_user, FCDO_team_u
"type": {"key": "refuse", "value": "Refuse"},
"ultimate_end_user": None,
"user": LU_team_user,
"team": lu_team,
},
]

Expand Down
Loading

0 comments on commit c1bd748

Please sign in to comment.