Skip to content

Commit

Permalink
Merge branch 'LTD-4839-duplicated-new-flow' of github.com:uktrade/lit…
Browse files Browse the repository at this point in the history
…e-frontend into LTD-4839-duplicated-new-flow
  • Loading branch information
Tllew committed Apr 24, 2024
2 parents 9fd18a8 + f5339b7 commit 9fa8687
Show file tree
Hide file tree
Showing 14 changed files with 312 additions and 108 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
6 changes: 1 addition & 5 deletions caseworker/external_data/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from django.urls import reverse
from django.views.generic import TemplateView
from django.views.generic.edit import FormView, CreateView
from django.http import Http404

from core.auth.views import LoginRequiredMixin

Expand All @@ -19,12 +18,9 @@
class DenialUploadView(LoginRequiredMixin, SuccessMessageMixin, CreateView):
template_name = "external_data/denial-upload.html"
form_class = forms.DenialUploadForm
success_message = "Denials created successfully"
success_message = "Denials created or updated successfully"
extra_context = {"base_64_csv": base_64_csv}

def dispatch(self, request, *args, **kwargs):
raise Http404("CSV denials uploads have been disabled")

def form_valid(self, form):
response = services.upload_denials(request=self.request, data=form.cleaned_data)
if not response.ok:
Expand Down
2 changes: 1 addition & 1 deletion conf/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

LOGIN_REDIRECT_URL = reverse_lazy("core:home")

FEATURE_FLAG_DJANGO_FORMS_REGISTRATION_ENABLED = env.bool("FEATURE_FLAG_DJANGO_FORMS_REGISTRATION_ENABLED", False)
FEATURE_FLAG_DJANGO_FORMS_REGISTRATION_ENABLED = env.bool("FEATURE_FLAG_DJANGO_FORMS_REGISTRATION_ENABLED", True)

LOGOUT_URL = urljoin(AUTHBROKER_URL, "logout")
AUTHBROKER_SCOPE = "openid,email,offline_access"
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
Loading

0 comments on commit 9fa8687

Please sign in to comment.