Skip to content

Commit

Permalink
feat(kesaseteli): update target groups for year 2024, update tests
Browse files Browse the repository at this point in the history
also:
 - remove dead code & inapplicable test cases after target group update

refs YJDH-670
  • Loading branch information
karisal-anders committed Jan 23, 2024
1 parent 9135157 commit 6a527ba
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 155 deletions.
25 changes: 1 addition & 24 deletions backend/kesaseteli/applications/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,30 +409,7 @@ def activate(self, request, *args, **kwargs) -> HttpResponse: # noqa: C901
elif youth_application.has_activation_link_expired:
return HttpResponseRedirect(youth_application.expired_page_url())
elif youth_application.activate():
if settings.NEXT_PUBLIC_DISABLE_VTJ:
if youth_application.need_additional_info:
return self._set_application_needs_additional_info(
youth_application=youth_application
)
LOGGER.info(
f"Activated youth application {youth_application.pk}: "
"VTJ is disabled, sending application to be processed by a handler"
)
youth_application.status = (
YouthApplicationStatus.AWAITING_MANUAL_PROCESSING
)
youth_application.save()
was_email_sent = youth_application.send_processing_email_to_handler(
request
)
if not was_email_sent:
transaction.set_rollback(True)
with translation.override(youth_application.language):
return HttpResponse(
_("Failed to send manual processing email to handler"),
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
)
elif youth_application.accept_automatically():
if youth_application.accept_automatically():
LOGGER.info(
f"Activated youth application {youth_application.pk}: "
"Youth application was accepted automatically using data from VTJ"
Expand Down
8 changes: 2 additions & 6 deletions backend/kesaseteli/applications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,11 +748,7 @@ def is_last_name_as_in_vtj(self) -> bool:

@property
def is_applicant_in_target_group(self) -> bool:
if self.is_9th_grader_age:
return self.is_helsinkian or self.attends_helsinkian_school
elif self.is_upper_secondary_education_1st_year_student_age:
return self.is_helsinkian
return False
return self.is_9th_grader_age and self.is_helsinkian

@property
def can_accept_automatically(self) -> bool:
Expand All @@ -773,7 +769,7 @@ def need_additional_info(self) -> bool:
additional info has been provided or not.
"""
if settings.NEXT_PUBLIC_DISABLE_VTJ:
return not (self.is_9th_grader_age and self.attends_helsinkian_school)
return True

return (
self.is_applicant_dead_according_to_vtj
Expand Down
128 changes: 23 additions & 105 deletions backend/kesaseteli/applications/tests/test_youth_applications_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ def test_youth_applications_activate_unexpired_inactive_with_rejection(

@pytest.mark.django_db
@override_settings(NEXT_PUBLIC_DISABLE_VTJ=False)
@pytest.mark.parametrize("application_year", [2022, 2023])
@pytest.mark.parametrize("application_year", [2022, 2023, 2024])
@pytest.mark.parametrize("applicant_age", [15, 16, 17, 18])
@pytest.mark.parametrize("is_helsinkian", [False, True])
@pytest.mark.parametrize("attends_helsinkian_school", [False, True])
Expand Down Expand Up @@ -794,10 +794,7 @@ def test_youth_applications_activate_unexpired_inactive__vtj_enabled(
assert response.status_code == status.HTTP_302_FOUND
app.refresh_from_db()

if is_alive and (
(applicant_age == 16 and (is_helsinkian or attends_helsinkian_school))
or (applicant_age == 17 and is_helsinkian)
):
if is_alive and is_helsinkian and applicant_age == 16:
assert response.url == app.accepted_page_url()
assert app.status == YouthApplicationStatus.ACCEPTED
else:
Expand All @@ -807,7 +804,7 @@ def test_youth_applications_activate_unexpired_inactive__vtj_enabled(

@pytest.mark.django_db
@override_settings(NEXT_PUBLIC_DISABLE_VTJ=True)
@pytest.mark.parametrize("application_year", [2022, 2023])
@pytest.mark.parametrize("application_year", [2022, 2023, 2024])
@pytest.mark.parametrize("applicant_age", [15, 16, 17, 18])
@pytest.mark.parametrize("is_helsinkian", [False, True])
@pytest.mark.parametrize("attends_helsinkian_school", [False, True])
Expand Down Expand Up @@ -850,12 +847,8 @@ def test_youth_applications_activate_unexpired_inactive__vtj_disabled(
assert response.status_code == status.HTTP_302_FOUND
app.refresh_from_db()

if applicant_age == 16 and attends_helsinkian_school:
assert response.url == app.activated_page_url()
assert app.status == YouthApplicationStatus.AWAITING_MANUAL_PROCESSING
else:
assert response.url == app.additional_info_page_url(app.pk)
assert app.status == YouthApplicationStatus.ADDITIONAL_INFORMATION_REQUESTED
assert response.url == app.additional_info_page_url(app.pk)
assert app.status == YouthApplicationStatus.ADDITIONAL_INFORMATION_REQUESTED

assert app.encrypted_original_vtj_json is None
assert app.encrypted_handler_vtj_json is None
Expand Down Expand Up @@ -925,36 +918,24 @@ def test_youth_applications_activate_unexpired_active(


@pytest.mark.django_db
@override_settings(NEXT_PUBLIC_DISABLE_VTJ=False)
@pytest.mark.parametrize("language", get_supported_languages())
@pytest.mark.parametrize("rejected_application_exists", [False, True])
@pytest.mark.parametrize(
"language,disable_vtj,rejected_application_exists,youth_application_factory,need_additional_info",
"youth_application_factory,need_additional_info",
[
(
language,
disable_vtj,
rejected_application_exists,
youth_application_factory,
need_additional_info,
)
for language in get_supported_languages()
for disable_vtj in [True]
for rejected_application_exists in [False, True]
for youth_application_factory, need_additional_info in [
(InactiveNoNeedAdditionalInfoYouthApplicationFactory, False),
(InactiveNeedAdditionalInfoYouthApplicationFactory, True),
]
(InactiveNoNeedAdditionalInfoYouthApplicationFactory, False),
(InactiveNeedAdditionalInfoYouthApplicationFactory, True),
],
)
def test_youth_applications_activate_expired_inactive(
api_client,
make_youth_application_activation_link_expired,
settings,
language,
disable_vtj,
rejected_application_exists,
youth_application_factory,
need_additional_info,
):
settings.NEXT_PUBLIC_DISABLE_VTJ = disable_vtj
inactive_youth_application = youth_application_factory(language=language)
create_same_person_previous_year_accepted_application(inactive_youth_application)

Expand Down Expand Up @@ -1050,7 +1031,7 @@ def test_youth_applications_activate_expired_active(


@pytest.mark.django_db
@override_settings(NEXT_PUBLIC_DISABLE_VTJ=True)
@override_settings(NEXT_PUBLIC_DISABLE_VTJ=False)
def test_youth_applications_dual_activate_unexpired_inactive(
api_client,
make_youth_application_activation_link_unexpired,
Expand All @@ -1077,11 +1058,11 @@ def test_youth_applications_dual_activate_unexpired_inactive(
app_1.refresh_from_db()
app_2.refresh_from_db()

assert not app_1.has_youth_summer_voucher
assert app_1.has_youth_summer_voucher
assert app_1.is_active
assert app_1.status == YouthApplicationStatus.AWAITING_MANUAL_PROCESSING
assert app_1.status == YouthApplicationStatus.ACCEPTED
assert response_1.status_code == status.HTTP_302_FOUND
assert response_1.url == app_1.activated_page_url()
assert response_1.url == app_1.accepted_page_url()

assert not app_2.has_youth_summer_voucher
assert not app_2.is_active
Expand All @@ -1096,34 +1077,30 @@ def test_youth_applications_dual_activate_unexpired_inactive(
[
(
InactiveNoNeedAdditionalInfoYouthApplicationFactory,
YouthApplicationStatus.AWAITING_MANUAL_PROCESSING,
YouthApplicationStatus.ACCEPTED,
),
(
InactiveNeedAdditionalInfoYouthApplicationFactory,
YouthApplicationStatus.ADDITIONAL_INFORMATION_REQUESTED,
),
],
)
@override_settings(NEXT_PUBLIC_DISABLE_VTJ=True)
def test_youth_applications_reactivate_unexpired_inactive__vtj_disabled(
@override_settings(NEXT_PUBLIC_DISABLE_VTJ=False)
def test_youth_applications_reactivate_unexpired_inactive(
app_factory,
expected_status,
api_client,
make_youth_application_activation_link_unexpired,
):
"""
When user tries to activate and reactivate an application, he/she should
When user tries to activate and then reactivate an application, they should
get redirected to the correct url.
- Application should get the expected status on the first activation
- User should get redirected correctly when trying to reactivate the
application.
"""
app = app_factory(
# Disabled VTJ means there's no VTJ data
encrypted_original_vtj_json=None,
encrypted_handler_vtj_json=None,
)
app = app_factory()

# Activate and reactivate
for i in range(2):
Expand All @@ -1133,16 +1110,13 @@ def test_youth_applications_reactivate_unexpired_inactive__vtj_disabled(

assert response.status_code == status.HTTP_302_FOUND

if i == 0 and app.status == YouthApplicationStatus.AWAITING_MANUAL_PROCESSING:
assert response.url == app.activated_page_url()
elif app.status == YouthApplicationStatus.AWAITING_MANUAL_PROCESSING:
if i == 0 and app.status == YouthApplicationStatus.ACCEPTED:
assert response.url == app.accepted_page_url()
elif app.status == YouthApplicationStatus.ACCEPTED:
assert response.url == app.already_activated_page_url()
else:
assert response.url == app.additional_info_page_url(pk=app.pk)

assert app.encrypted_original_vtj_json is None
assert app.encrypted_handler_vtj_json is None


@override_settings(
NEXT_PUBLIC_MOCK_FLAG=False,
Expand Down Expand Up @@ -1526,32 +1500,6 @@ def test_youth_application_additional_info_request_email_link_path(api_client):
assert activation_url_with_path_only in additional_info_request_email.body


@pytest.mark.django_db
@override_settings(
EMAIL_BACKEND="django.core.mail.backends.locmem.EmailBackend",
DEFAULT_FROM_EMAIL="Test sender <testsender@hel.fi>",
HANDLER_EMAIL="Test handler <testhandler@hel.fi>",
NEXT_PUBLIC_DISABLE_VTJ=True,
)
def test_youth_application_processing_email_sending_on_activate__vtj_disabled(
settings,
api_client,
make_youth_application_activation_link_unexpired,
):
youth_application = InactiveNoNeedAdditionalInfoYouthApplicationFactory()
assert not youth_application.is_active
assert not youth_application.has_activation_link_expired
assert not youth_application.need_additional_info
start_mail_count = len(mail.outbox)
api_client.get(get_activation_url(youth_application.pk))

assert len(mail.outbox) == start_mail_count + 1
processing_email = mail.outbox[-1]
assert processing_email.subject == youth_application.processing_email_subject()
assert processing_email.from_email == "Test sender <testsender@hel.fi>"
assert processing_email.to == ["Test handler <testhandler@hel.fi>"]


@pytest.mark.django_db
@override_settings(
EMAIL_BACKEND="django.core.mail.backends.locmem.EmailBackend",
Expand Down Expand Up @@ -1581,36 +1529,6 @@ def test_youth_application_processing_email_sending_after_additional_info(
assert processing_email.to == ["Test handler <testhandler@hel.fi>"]


@pytest.mark.django_db
@override_settings(
EMAIL_BACKEND="django.core.mail.backends.locmem.EmailBackend",
NEXT_PUBLIC_DISABLE_VTJ=True,
)
@pytest.mark.parametrize(
"youth_application_language,expected_email_language",
[(language, "fi") for language in get_supported_languages()],
)
def test_youth_application_processing_email_language_on_activate__vtj_disabled(
settings,
api_client,
make_youth_application_activation_link_unexpired,
youth_application_language,
expected_email_language,
):
youth_application = InactiveNoNeedAdditionalInfoYouthApplicationFactory(
language=youth_application_language
)
assert not youth_application.is_active
assert not youth_application.has_activation_link_expired
assert not youth_application.need_additional_info
start_mail_count = len(mail.outbox)
api_client.get(get_activation_url(youth_application.pk))
assert len(mail.outbox) == start_mail_count + 1
processing_email = mail.outbox[-1]
assert_email_subject_language(processing_email.subject, expected_email_language)
assert_email_body_language(processing_email.body, expected_email_language)


@pytest.mark.django_db
@override_settings(EMAIL_BACKEND="django.core.mail.backends.locmem.EmailBackend")
@pytest.mark.parametrize("disable_vtj", [False, True])
Expand Down
44 changes: 34 additions & 10 deletions backend/kesaseteli/common/tests/test_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,15 @@ def test_youth_application_factory( # noqa: C901


@pytest.mark.django_db
@override_settings(NEXT_PUBLIC_MOCK_FLAG=True)
@pytest.mark.parametrize(
"youth_application_factory,expected_need_additional_info",
"youth_application_factory",
[
(AdditionalInfoRequestedYouthApplicationFactory, True),
(AdditionalInfoProvidedYouthApplicationFactory, True),
(InactiveNoNeedAdditionalInfoYouthApplicationFactory, False),
(InactiveNeedAdditionalInfoYouthApplicationFactory, True),
AdditionalInfoRequestedYouthApplicationFactory,
AdditionalInfoProvidedYouthApplicationFactory,
InactiveNeedAdditionalInfoYouthApplicationFactory,
],
)
@pytest.mark.parametrize("next_public_mock_flag", [False, True])
@pytest.mark.parametrize("next_public_disable_vtj", [False, True])
@pytest.mark.parametrize(
"freeze_date", ["2021-01-01", "2021-06-15", "2021-12-31", "2023-07-16"]
Expand All @@ -209,17 +208,42 @@ def test_need_additional_info(
settings,
make_youth_application_activation_link_unexpired,
youth_application_factory,
expected_need_additional_info: bool,
next_public_mock_flag: bool,
next_public_disable_vtj: bool,
freeze_date: str,
):
settings.NEXT_PUBLIC_MOCK_FLAG = next_public_mock_flag
settings.NEXT_PUBLIC_DISABLE_VTJ = next_public_disable_vtj
for _ in range(10): # Run more than once because factories generate random data
with freeze_time(freeze_date):
youth_application: YouthApplication = youth_application_factory()
assert (
youth_application.need_additional_info == expected_need_additional_info
)
assert youth_application.need_additional_info


@pytest.mark.django_db
@pytest.mark.parametrize(
"youth_application_factory", [InactiveNoNeedAdditionalInfoYouthApplicationFactory]
)
@pytest.mark.parametrize("next_public_mock_flag", [False, True])
@pytest.mark.parametrize("next_public_disable_vtj", [False, True])
@pytest.mark.parametrize(
"freeze_date", ["2021-01-01", "2021-06-15", "2021-12-31", "2023-07-16"]
)
def test_no_need_additional_info(
settings,
make_youth_application_activation_link_unexpired,
youth_application_factory,
next_public_mock_flag: bool,
next_public_disable_vtj: bool,
freeze_date: str,
):
settings.NEXT_PUBLIC_MOCK_FLAG = next_public_mock_flag
settings.NEXT_PUBLIC_DISABLE_VTJ = next_public_disable_vtj
for _ in range(10): # Run more than once because factories generate random data
with freeze_time(freeze_date):
youth_application: YouthApplication = youth_application_factory()
# If VTJ is disabled, additional info is always needed, otherwise not
assert youth_application.need_additional_info == next_public_disable_vtj


@pytest.mark.django_db
Expand Down
4 changes: 2 additions & 2 deletions frontend/kesaseteli/employer/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
"form": {
"selectionGroups": {
"target_group": {
"primary_target_group": "9th grader, 10th grader or Valma grader",
"secondary_target_group": "\t\nOther age group"
"primary_target_group": "9th grader or TUVA grader",
"secondary_target_group": "Other age group"
},
"hired_without_voucher_assessment": {
"yes": "Yes",
Expand Down
2 changes: 1 addition & 1 deletion frontend/kesaseteli/employer/public/locales/fi/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"form": {
"selectionGroups": {
"target_group": {
"primary_target_group": "9. luokkalainen, 10. luokkalainen tai Valma-luokkalainen",
"primary_target_group": "9. luokkalainen tai TUVA-luokkalainen",
"secondary_target_group": "Jokin muu ikäryhmä"
},
"hired_without_voucher_assessment": {
Expand Down
2 changes: 1 addition & 1 deletion frontend/kesaseteli/employer/public/locales/sv/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"form": {
"selectionGroups": {
"target_group": {
"primary_target_group": "Niondeklassist, tiondeklassist eller Valmaklassist",
"primary_target_group": "Niondeklassist eller TUVAklassist",
"secondary_target_group": "Annan åldersgrupp"
},
"hired_without_voucher_assessment": {
Expand Down
Loading

0 comments on commit 6a527ba

Please sign in to comment.