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 16, 2024
1 parent 6744fa4 commit b42f3fe
Show file tree
Hide file tree
Showing 11 changed files with 310 additions and 80 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
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Feature: I want to record my user advice and any comments and conditions relatin
When I click the application previously created
And I assign myself to the case
And I click the recommendations and decision tab
And I expand the details for "MOD-ECJU has approved with licence conditions"
And I expand the details for "MOD-CapProt has approved with licence conditions"
Then I see "reason for approving" as the reasons for approving
And I see "licence condition" as the licence condition
And I see "instruction for exporter" as the instructions for the exporter
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
123 changes: 122 additions & 1 deletion unit_tests/caseworker/advice/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
MOD_CONSOLIDATE_QUEUES,
MOD_CONSOLIDATE_TEAMS,
MOD_ECJU_TEAM,
filter_advice_by_users_team,
filter_advice_by_team,
filter_advice_by_teams,
get_advice_tab_context,
get_advice_to_countersign,
get_decision_advices_by_countersigner,
get_countersign_decision_advice_by_user,
update_countersign_decision_advice,
group_advice_by_team,
update_advice,
)
from caseworker.cases.objects import Case
Expand Down Expand Up @@ -75,6 +78,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 Expand Up @@ -294,3 +301,117 @@ def test_update_advice_not_supported_advice_type_raises_error(

with pytest.raises(NotImplementedError):
update_advice(requests_mock, case, current_user, "no_licence_required", {}, "final-advice")


@pytest.mark.parametrize(
"all_advice, caseworker, expected",
(
([], {}, []),
(
[{"id": "advice_1", "team": {"id": "team_1"}}, {"id": "advice_2", "team": {"id": "team_2"}}],
{"team": {"id": "team_1"}},
[{"id": "advice_1", "team": {"id": "team_1"}}],
),
(
[
{"id": "advice_1", "team": {"id": "team_1"}},
{"id": "advice_2", "team": {"id": "team_2"}},
{"id": "advice_3", "team": {"id": "team_2"}},
],
{"team": {"id": "team_2"}},
[{"id": "advice_2", "team": {"id": "team_2"}}, {"id": "advice_3", "team": {"id": "team_2"}}],
),
),
)
def test_filter_advice_by_users_team(all_advice, caseworker, expected):
assert filter_advice_by_users_team(all_advice, caseworker) == expected


@pytest.mark.parametrize(
"all_advice, team_alias, expected",
(
([], "", []),
(
[{"id": "advice_1", "team": {"alias": "team_1"}}, {"id": "advice_2", "team": {"alias": "team_2"}}],
"team_1",
[{"id": "advice_1", "team": {"alias": "team_1"}}],
),
(
[
{"id": "advice_1", "team": {"alias": "team_1"}},
{"id": "advice_2", "team": {"alias": "team_2"}},
{"id": "advice_3", "team": {"alias": "team_2"}},
],
"team_2",
[{"id": "advice_2", "team": {"alias": "team_2"}}, {"id": "advice_3", "team": {"alias": "team_2"}}],
),
),
)
def test_filter_advice_by_team(all_advice, team_alias, expected):
assert filter_advice_by_team(all_advice, team_alias) == expected


@pytest.mark.parametrize(
"all_advice, teams_list, expected",
(
([], [""], []),
(
[{"id": "advice_1", "team": {"alias": "team_1"}}, {"id": "advice_2", "team": {"alias": "team_2"}}],
["team_1"],
[{"id": "advice_1", "team": {"alias": "team_1"}}],
),
(
[
{"id": "advice_1", "team": {"alias": "team_1"}},
{"id": "advice_2", "team": {"alias": "team_2"}},
{"id": "advice_3", "team": {"alias": "team_2"}},
],
["team_2"],
[{"id": "advice_2", "team": {"alias": "team_2"}}, {"id": "advice_3", "team": {"alias": "team_2"}}],
),
(
[
{"id": "advice_1", "team": {"alias": "team_1"}},
{"id": "advice_2", "team": {"alias": "team_2"}},
{"id": "advice_3", "team": {"alias": "team_2"}},
],
["team_1", "team_2"],
[
{"id": "advice_1", "team": {"alias": "team_1"}},
{"id": "advice_2", "team": {"alias": "team_2"}},
{"id": "advice_3", "team": {"alias": "team_2"}},
],
),
),
)
def test_filter_advice_by_teams(all_advice, teams_list, expected):
assert filter_advice_by_teams(all_advice, teams_list) == expected


@pytest.mark.parametrize(
"advice, expected",
(
([], {}),
([{"id": "advice_1", "team": {"id": "team_1"}}], {"team_1": [{"id": "advice_1", "team": {"id": "team_1"}}]}),
(
[{"id": "advice_1", "team": {"id": "team_1"}}, {"id": "advice_2", "team": {"id": "team_2"}}],
{
"team_1": [{"id": "advice_1", "team": {"id": "team_1"}}],
"team_2": [{"id": "advice_2", "team": {"id": "team_2"}}],
},
),
(
[
{"id": "advice_1", "team": {"id": "team_1"}},
{"id": "advice_2", "team": {"id": "team_2"}},
{"id": "advice_3", "team": {"id": "team_1"}},
],
{
"team_1": [{"id": "advice_1", "team": {"id": "team_1"}}, {"id": "advice_3", "team": {"id": "team_1"}}],
"team_2": [{"id": "advice_2", "team": {"id": "team_2"}}],
},
),
),
)
def test_group_advice_by_team(advice, expected):
assert group_advice_by_team(advice) == expected
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
Loading

0 comments on commit b42f3fe

Please sign in to comment.