Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email application url #1491

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<mj-spacer />
<mj-text>{{ view_booking_at_label | safe }}:</mj-text>
{% for series in cancelled_reservation_series %}
<mj-text>{{ series.weekday | safe }}: {{ series.time | safe }}</mj-text>
<mj-text>{{ series.weekday_value | safe }}: {{ series.time_value | safe }}</mj-text>
<mj-text><a href="{{ series.url | safe }}">{{ series.url | safe }}</a></mj-text>
{% endfor %}
{% endblock %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

{{ view_booking_at_label | safe }}:

{% for series in cancelled_reservation_series %}{{ series.weekday | safe }} {{ series.time | safe }}
{% for series in cancelled_reservation_series %}{{ series.weekday_value | safe }} {{ series.time_value | safe }}
{{ series.url | safe }}
{% endfor %}
{% include "email/text/partials/closing_staff.jinja" %}
8 changes: 4 additions & 4 deletions tests/factories/reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ class Meta:
created_at = None

# Pricing details
price = 0
non_subsidised_price = 0
unit_price = 0
tax_percentage_value = 0
price = Decimal(0)
non_subsidised_price = Decimal(0)
unit_price = Decimal(0)
tax_percentage_value = Decimal(0)

# Free of charge information
applying_for_free_of_charge = False
Expand Down
82 changes: 82 additions & 0 deletions tests/test_integrations/test_email/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from __future__ import annotations

import datetime
from typing import TYPE_CHECKING

import pytest

from tilavarauspalvelu.enums import WeekdayChoice
from utils.date_utils import local_datetime

from tests.factories import (
ApplicationSectionFactory,
RecurringReservationFactory,
ReservationFactory,
ReservationUnitFactory,
)

if TYPE_CHECKING:
from tilavarauspalvelu.models import Reservation


@pytest.fixture
def email_reservation() -> Reservation:
reservation_unit = ReservationUnitFactory.create(
name_en="Test reservation unit",
unit__name_en="Test unit",
unit__location__address_street_en="Test Street",
unit__location__address_zip="",
unit__location__address_city_en="City",
reservation_confirmed_instructions_en="[HYVÄKSYTYN VARAUKSEN OHJEET]",
reservation_cancelled_instructions_en="[PERUUTETUN VARAUKSEN OHJEET]",
reservation_pending_instructions_en="[KÄSITELTÄVÄN VARAUKSEN OHJEET]",
pricings__lowest_price=0,
pricings__highest_price=0,
)
application_section = ApplicationSectionFactory.create(
name="[HAKEMUKSEN OSAN NIMI]",
application__application_round__name_en="[KAUSIVARAUSKIERROKSEN NIMI]",
application__organisation__name_en="[SÄHKÖPOSTIN VASTAANOTTAJAN NIMI]",
)
recurring_reservation = RecurringReservationFactory.create(
weekdays=f"{WeekdayChoice.MONDAY}",
begin_date=datetime.date(2024, 1, 1),
begin_time=datetime.time(12),
end_time=datetime.time(14),
allocated_time_slot__reservation_unit_option__reservation_unit=reservation_unit,
allocated_time_slot__reservation_unit_option__application_section=application_section,
)
reservation = ReservationFactory.create_for_reservation_unit(
name="Test reservation",
reservation_unit=reservation_unit,
user=application_section.application.user,
reservee_first_name="[SÄHKÖPOSTIN VASTAANOTTAJAN NIMI]",
reservee_last_name="",
cancel_reason__reason_en="[PERUUTUKSEN SYY]",
deny_reason__reason_en="[HYLKÄYKSEN SYY]",
begin=local_datetime(2024, 1, 1, 12, 0),
end=local_datetime(2024, 1, 1, 14, 0),
recurring_reservation=recurring_reservation,
)

recurring_reservation_2 = RecurringReservationFactory.create(
weekdays=f"{WeekdayChoice.TUESDAY}",
begin_date=datetime.date(2024, 1, 2),
begin_time=datetime.time(21),
end_time=datetime.time(22),
allocated_time_slot__reservation_unit_option__reservation_unit=reservation_unit,
allocated_time_slot__reservation_unit_option__application_section=application_section,
)
ReservationFactory.create_for_reservation_unit(
reservation_unit=reservation_unit,
user=application_section.application.user,
reservee_first_name="[SÄHKÖPOSTIN VASTAANOTTAJAN NIMI]",
reservee_last_name="",
cancel_reason__reason_en="[PERUUTUKSEN SYY]",
deny_reason__reason_en="[HYLKÄYKSEN SYY]",
begin=local_datetime(2024, 1, 2, 12, 0),
end=local_datetime(2024, 1, 2, 14, 0),
recurring_reservation=recurring_reservation_2,
)

return reservation
6 changes: 3 additions & 3 deletions tests/test_integrations/test_email/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
RESERVATION_BASIC_INFO_CONTEXT_EN = {
"reservation_unit_name": "Test reservation unit",
"unit_name": "Test unit",
"unit_location": "Test location",
"unit_location": "Test Street, City",
"begins_label": "From",
"begin_date": "1.1.2024",
"begin_time": "12:00",
Expand All @@ -120,7 +120,7 @@
RESERVATION_BASIC_INFO_CONTEXT_FI = {
"reservation_unit_name": "Test reservation unit",
"unit_name": "Test unit",
"unit_location": "Test location",
"unit_location": "Test Street, City",
"begins_label": "Alkamisaika",
"begin_date": "1.1.2024",
"begin_time": "12:00",
Expand All @@ -132,7 +132,7 @@
RESERVATION_BASIC_INFO_CONTEXT_SV = {
"reservation_unit_name": "Test reservation unit",
"unit_name": "Test unit",
"unit_location": "Test location",
"unit_location": "Test Street, City",
"begins_label": "Börjar",
"begin_date": "1.1.2024",
"begin_time": "12:00",
Expand Down
107 changes: 68 additions & 39 deletions tests/test_integrations/test_email/test_application_context.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# ruff: noqa: RUF001
from __future__ import annotations

import pytest
from freezegun import freeze_time

from tilavarauspalvelu.enums import WeekdayChoice
Expand All @@ -14,6 +15,7 @@
get_context_for_staff_notification_application_section_cancelled,
)
from tilavarauspalvelu.integrations.email.template_context.common import get_staff_reservations_ext_link
from tilavarauspalvelu.models import Reservation

from tests.helpers import TranslationsFromPOFiles
from tests.test_integrations.test_email.helpers import (
Expand All @@ -37,6 +39,11 @@
SEASONAL_RESERVATION_CHECK_BOOKING_DETAILS_LINK_SV,
)

# Applied to all tests
pytestmark = [
pytest.mark.django_db,
]

Comment on lines +42 to +46
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't add this on the top level in this case, since most of the tests in this file don't need database access. It just makes them run slower.

# type: EmailType.APPLICATION_HANDLED ##################################################################################


Expand Down Expand Up @@ -272,7 +279,7 @@ def test_get_context__application_received__sv():


@freeze_time("2024-01-01")
def test_get_context_for_application_section_cancelled__en():
def test_get_context_for_application_section_cancelled__en(email_reservation):
with TranslationsFromPOFiles():
context = get_context_for_application_section_cancelled(
email_recipient_name="[SÄHKÖPOSTIN VASTAANOTTAJAN NIMI]",
Expand All @@ -299,6 +306,19 @@ def test_get_context_for_application_section_cancelled__en():
**AUTOMATIC_REPLY_CONTEXT_EN,
}

with TranslationsFromPOFiles():
# Add application and section ID to the url, which are always taken from actual instances to the context
section = email_reservation.actions.get_application_section()
old_url = context["check_booking_details_url"]
new_url = f"{old_url}/{section.application_id}/view?tab=reservations&section={section.id}"
context["check_booking_details_url"] = context["check_booking_details_url"].replace(old_url, new_url)
context["check_booking_details_url_html"] = context["check_booking_details_url_html"].replace(old_url, new_url)

assert context == get_context_for_application_section_cancelled(
application_section=email_reservation.actions.get_application_section(),
language="en",
)


@freeze_time("2024-01-01")
def test_get_context_for_application_section_cancelled__fi():
Expand Down Expand Up @@ -362,25 +382,28 @@ def test_get_context_for_application_section_cancelled_sv():


@freeze_time("2024-01-01")
def test_get_context_for_staff_notification_application_section_cancelled__en():
def test_get_context_for_staff_notification_application_section_cancelled__en(email_reservation):
reservation_id_1 = email_reservation.id
reservation_id_2 = Reservation.objects.exclude(id=reservation_id_1).first().id

with TranslationsFromPOFiles():
context = get_context_for_staff_notification_application_section_cancelled(
application_section_name="[HAKEMUKSEN OSAN NIMI]",
application_round_name="[KAUSIVARAUSKIERROKSEN NIMI]",
cancel_reason="[PERUUTUKSEN SYY]",
language="en",
cancelled_reservation_series=[
{
"weekday": WeekdayChoice.MONDAY.label,
"time": "13:00-15:00",
"url": get_staff_reservations_ext_link(reservation_id=1234),
"weekday_value": "Monday",
"time_value": "12:00:00-14:00:00",
"reservation_url": get_staff_reservations_ext_link(reservation_id=reservation_id_1),
},
{
"weekday": WeekdayChoice.TUESDAY.label,
"time": "21:00-22:00",
"url": get_staff_reservations_ext_link(reservation_id=5678),
"weekday_value": "Tuesday",
"time_value": "21:00:00-22:00:00",
"reservation_url": get_staff_reservations_ext_link(reservation_id=reservation_id_2),
},
],
language="en",
)

assert context == {
Expand All @@ -397,21 +420,27 @@ def test_get_context_for_staff_notification_application_section_cancelled__en():
"view_booking_at_label": "You can view the booking at",
"cancelled_reservation_series": [
{
"weekday": "Monday",
"time": "13:00-15:00",
"url": "https://fake.varaamo.hel.fi/kasittely/reservations/1234",
"weekday_value": "Monday",
"time_value": "12:00:00-14:00:00",
"reservation_url": f"https://fake.varaamo.hel.fi/kasittely/reservations/{reservation_id_1}",
},
{
"weekday": "Tuesday",
"time": "21:00-22:00",
"url": "https://fake.varaamo.hel.fi/kasittely/reservations/5678",
"weekday_value": "Tuesday",
"time_value": "21:00:00-22:00:00",
"reservation_url": f"https://fake.varaamo.hel.fi/kasittely/reservations/{reservation_id_2}",
},
],
**BASE_TEMPLATE_CONTEXT_EN,
**CLOSING_CONTEXT_EN,
**CLOSING_STAFF_CONTEXT_EN,
}

with TranslationsFromPOFiles():
assert context == get_context_for_staff_notification_application_section_cancelled(
application_section=email_reservation.actions.get_application_section(),
language="en",
)


@freeze_time("2024-01-01")
def test_get_context_for_staff_notification_application_section_cancelled__fi():
Expand All @@ -423,14 +452,14 @@ def test_get_context_for_staff_notification_application_section_cancelled__fi():
language="fi",
cancelled_reservation_series=[
{
"weekday": WeekdayChoice.MONDAY.label,
"time": "13:00-15:00",
"url": get_staff_reservations_ext_link(reservation_id=1234),
"weekday_value": WeekdayChoice.MONDAY.label,
"time_value": "12:00:00-14:00:00",
"reservation_url": get_staff_reservations_ext_link(reservation_id=1234),
},
{
"weekday": WeekdayChoice.TUESDAY.label,
"time": "21:00-22:00",
"url": get_staff_reservations_ext_link(reservation_id=5678),
"weekday_value": WeekdayChoice.TUESDAY.label,
"time_value": "21:00:00-22:00:00",
"reservation_url": get_staff_reservations_ext_link(reservation_id=5678),
},
],
)
Expand All @@ -447,14 +476,14 @@ def test_get_context_for_staff_notification_application_section_cancelled__fi():
"view_booking_at_label": "Voit tarkistaa varauksen tiedot osoitteessa",
"cancelled_reservation_series": [
{
"weekday": "Monday",
"time": "13:00-15:00",
"url": "https://fake.varaamo.hel.fi/kasittely/reservations/1234",
"weekday_value": "Monday",
"time_value": "12:00:00-14:00:00",
"reservation_url": "https://fake.varaamo.hel.fi/kasittely/reservations/1234",
},
{
"weekday": "Tuesday",
"time": "21:00-22:00",
"url": "https://fake.varaamo.hel.fi/kasittely/reservations/5678",
"weekday_value": "Tuesday",
"time_value": "21:00:00-22:00:00",
"reservation_url": "https://fake.varaamo.hel.fi/kasittely/reservations/5678",
},
],
**BASE_TEMPLATE_CONTEXT_FI,
Expand All @@ -473,14 +502,14 @@ def test_get_context_for_staff_notification_application_section_cancelled_sv():
language="sv",
cancelled_reservation_series=[
{
"weekday": WeekdayChoice.MONDAY.label,
"time": "13:00-15:00",
"url": get_staff_reservations_ext_link(reservation_id=1234),
"weekday_value": WeekdayChoice.MONDAY.label,
"time_value": "12:00:00-14:00:00",
"reservation_url": get_staff_reservations_ext_link(reservation_id=1234),
},
{
"weekday": WeekdayChoice.TUESDAY.label,
"time": "21:00-22:00",
"url": get_staff_reservations_ext_link(reservation_id=5678),
"weekday_value": WeekdayChoice.TUESDAY.label,
"time_value": "21:00:00-22:00:00",
"reservation_url": get_staff_reservations_ext_link(reservation_id=5678),
},
],
)
Expand All @@ -497,14 +526,14 @@ def test_get_context_for_staff_notification_application_section_cancelled_sv():
"view_booking_at_label": "Du kan se bokningen på",
"cancelled_reservation_series": [
{
"weekday": "Monday",
"time": "13:00-15:00",
"url": "https://fake.varaamo.hel.fi/kasittely/reservations/1234",
"weekday_value": "Monday",
"time_value": "12:00:00-14:00:00",
"reservation_url": "https://fake.varaamo.hel.fi/kasittely/reservations/1234",
},
{
"weekday": "Tuesday",
"time": "21:00-22:00",
"url": "https://fake.varaamo.hel.fi/kasittely/reservations/5678",
"weekday_value": "Tuesday",
"time_value": "21:00:00-22:00:00",
"reservation_url": "https://fake.varaamo.hel.fi/kasittely/reservations/5678",
},
],
**BASE_TEMPLATE_CONTEXT_SV,
Expand Down
Loading
Loading