forked from City-of-Helsinki/respa
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #366 from City-of-Turku/develop
Release tku-v1.11
- Loading branch information
Showing
33 changed files
with
760 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -994,3 +994,119 @@ def test_reservation_waiting_for_payment_sent_only_once(resource_with_manual_con | |
assert response.status_code == 200 | ||
assert response.data['state'] == Reservation.READY_FOR_PAYMENT | ||
assert len(mail.outbox) == 0 | ||
|
||
|
||
@override_settings(RESPA_MAILS_ENABLED=True) | ||
@pytest.mark.django_db | ||
def test_reservation_waiting_for_cash_comments_dont_trigger_notification(resource_with_manual_confirmation, api_client, user, unit_manager_api_client, | ||
product_extra_manual_confirmation, reservation_waiting_for_payment_notification, | ||
reservation_requested_notification, reservation_confirmed_notification, | ||
customer_group): | ||
"""Tests that commenting to reservation waiting for cash payment does not trigger new reservation confirmed notifications for client""" | ||
resource_with_manual_confirmation.cash_payments_allowed = True | ||
resource_with_manual_confirmation.save() | ||
# client user makes a reservation with order which also requires manual confirmation | ||
reservation_data = build_reservation_data(resource_with_manual_confirmation) | ||
reservation_data['reserver_name'] = 'Nordea Demo' | ||
reservation_data['reserver_email_address'] = '[email protected]' | ||
reservation_data['billing_email_address'] = '[email protected]' | ||
reservation_data['preferred_language'] = 'fi' | ||
order_data = build_order_data(product_extra_manual_confirmation, customer_group=customer_group.id) | ||
order_data['payment_method'] = Order.CASH | ||
reservation_data['order'] = order_data | ||
|
||
api_client.force_authenticate(user=user) | ||
response = api_client.post(LIST_URL, data=reservation_data) | ||
assert response.status_code == 201 | ||
assert response.data['state'] == Reservation.REQUESTED | ||
assert len(mail.outbox) == 1 | ||
assert mail.outbox[0].subject == 'Reservation requested subject.' | ||
|
||
# staff approves reservation | ||
reservation_data['state'] = Reservation.CONFIRMED | ||
mail.outbox = [] | ||
new_reservation = Reservation.objects.last() | ||
response = unit_manager_api_client.put(get_detail_url(new_reservation), data=reservation_data, format='json') | ||
assert response.status_code == 200 | ||
assert response.data['state'] == Reservation.WAITING_FOR_CASH_PAYMENT | ||
assert len(mail.outbox) == 1 | ||
assert mail.outbox[0].subject == 'Reservation confirmed subject.' | ||
|
||
# staff writes comments | ||
reservation_data['comments'] = 'test comment' | ||
reservation_data['state'] = Reservation.WAITING_FOR_CASH_PAYMENT | ||
mail.outbox = [] | ||
response = unit_manager_api_client.put(get_detail_url(new_reservation), data=reservation_data, format='json') | ||
assert response.status_code == 200 | ||
assert response.data['state'] == Reservation.WAITING_FOR_CASH_PAYMENT | ||
assert len(mail.outbox) == 0 | ||
|
||
reservation_data['comments'] = 'other test comment' | ||
response = unit_manager_api_client.put(get_detail_url(new_reservation), data=reservation_data, format='json') | ||
assert response.status_code == 200 | ||
assert response.data['state'] == Reservation.WAITING_FOR_CASH_PAYMENT | ||
assert len(mail.outbox) == 0 | ||
|
||
|
||
@pytest.mark.parametrize('data_state, reservation_state, is_manager, is_superuser, expected', [ | ||
('confirmed', 'waiting_for_cash_payment', False, False, 403), | ||
('confirmed', 'waiting_for_cash_payment', True, False, 200), | ||
('confirmed', 'waiting_for_cash_payment', False, True, 200), | ||
('waiting_for_cash_payment', 'waiting_for_cash_payment', True, True, 400), | ||
('denied', 'waiting_for_cash_payment', True, True, 400), | ||
('confirmed', 'confirmed', True, False, 400), | ||
('confirmed', 'requested', True, False, 400), | ||
]) | ||
@pytest.mark.django_db | ||
def test_confirm_cash_payment_in_the_past(api_client, user, staff_user, resource_with_manual_confirmation, | ||
product_extra_manual_confirmation, customer_group, unit_manager_api_client, | ||
data_state, reservation_state, is_manager, is_superuser, expected): | ||
"""Tests that confirming cash payments works correctly for reservations in the past""" | ||
|
||
resource_with_manual_confirmation.cash_payments_allowed = True | ||
resource_with_manual_confirmation.save() | ||
# client user makes a reservation with order which also requires manual confirmation | ||
reservation_data = build_reservation_data(resource_with_manual_confirmation) | ||
reservation_data['reserver_name'] = 'Nordea Demo' | ||
reservation_data['reserver_email_address'] = '[email protected]' | ||
reservation_data['billing_email_address'] = '[email protected]' | ||
reservation_data['preferred_language'] = 'fi' | ||
order_data = build_order_data(product_extra_manual_confirmation, customer_group=customer_group.id) | ||
order_data['payment_method'] = Order.CASH | ||
reservation_data['order'] = order_data | ||
|
||
api_client.force_authenticate(user=user) | ||
response = api_client.post(LIST_URL, data=reservation_data) | ||
assert response.status_code == 201 | ||
assert response.data['state'] == Reservation.REQUESTED | ||
|
||
# staff approves reservation | ||
reservation_data['state'] = Reservation.CONFIRMED | ||
new_reservation = Reservation.objects.last() | ||
response = unit_manager_api_client.put(get_detail_url(new_reservation), data=reservation_data, format='json') | ||
assert response.status_code == 200 | ||
assert response.data['state'] == Reservation.WAITING_FOR_CASH_PAYMENT | ||
|
||
# set reservation to be in the past and test with given values | ||
new_reservation = Reservation.objects.last() | ||
new_reservation.begin = '2005-04-04T12:00:00+02:00' | ||
new_reservation.end = '2005-04-04T13:00:00+02:00' | ||
new_reservation.state = reservation_state | ||
new_reservation.save() | ||
new_reservation.refresh_from_db() | ||
reservation_data['state'] = data_state | ||
reservation_data['begin'] = '2005-04-04T12:00:00+02:00' | ||
reservation_data['end'] = '2005-04-04T13:00:00+02:00' | ||
if is_manager: | ||
UnitAuthorization.objects.create( | ||
subject=resource_with_manual_confirmation.unit, level=UnitAuthorizationLevel.manager, authorized=staff_user) | ||
if is_superuser: | ||
staff_user.is_superuser = True | ||
staff_user.save() | ||
api_client.force_authenticate(user=staff_user) | ||
response = api_client.put(get_detail_url(new_reservation), data=reservation_data, format='json') | ||
assert response.status_code == expected | ||
if expected == 400: | ||
assert response.data['non_field_errors'][0] == 'Varauksen teko menneisyyteen ei ole sallittua' | ||
if expected == 200: | ||
assert response.data['state'] == Reservation.CONFIRMED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.