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

Don't send notification on blocked reservation type #305

Merged
merged 2 commits into from
Dec 13, 2023
Merged
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
3 changes: 3 additions & 0 deletions resources/models/reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,9 @@ def send_reservation_mail(self, notification_type,
user=None, attachments=None,
staff_email=None,
extra_context={}, is_reminder = False):
if self.type == Reservation.TYPE_BLOCKED:
return

notification_template = self.get_notification_template(notification_type)
if self.user and not user: # If user isn't given use self.user.
user = self.user
Expand Down
28 changes: 28 additions & 0 deletions resources/tests/test_reservation_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,16 @@ def reservation_created_notification():
body='Normal reservation created body.',
)

@pytest.fixture
def reservation_created_by_official_notification():
with translation.override('fi'): # Staff user preferred language is always fallback. (fi)
return NotificationTemplate.objects.create(
type=NotificationType.RESERVATION_CREATED_BY_OFFICIAL,
is_default_template=True,
short_message = 'Virkailija on luonut varauksen lyhyt viesti.',
subject = 'Virkailija on luonut varauksen aihe.',
body = 'Virkailija on luonut varauksen viesti.'
)

@pytest.fixture
def reservation_modified_by_official_notification():
Expand Down Expand Up @@ -3314,3 +3324,21 @@ def test_reservation_reminder_create(
response = api_client.post(list_url, data=reservation_data, HTTP_ACCEPT_LANGUAGE='en')
assert response.status_code == 201
assert ReservationReminder.objects.count() == 1


@override_settings(RESPA_MAILS_ENABLED=True)
@pytest.mark.django_db
def test_no_notification_on_reservation_type_blocked(
resource_in_unit, reservation_data,
staff_api_client, staff_user, list_url,
reservation_created_by_official_notification):
UnitAuthorization.objects.create(subject=resource_in_unit.unit,
level=UnitAuthorizationLevel.manager, authorized=staff_user)

reservation_data['resource'] = resource_in_unit.pk
reservation_data['reserver_name'] = 'Staff reservation normal'
reservation_data['type'] = Reservation.TYPE_BLOCKED

response = staff_api_client.post(list_url, data=reservation_data, format='json')
assert response.status_code == 201
assert len(mail.outbox) == 0
Loading