-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add recurring reservation deny mutation endpoint
Also fix issues related to reservee being able to modify other user's reservations.
- Loading branch information
1 parent
e566359
commit 8f4d410
Showing
15 changed files
with
462 additions
and
20 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
108 changes: 108 additions & 0 deletions
108
tests/test_graphql_api/test_recurring_reservation/test_deny_series.py
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 |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import pytest | ||
from freezegun import freeze_time | ||
|
||
from tests.factories import ReservationDenyReasonFactory | ||
from tilavarauspalvelu.enums import ReservationStateChoice | ||
from utils.date_utils import local_datetime | ||
|
||
from .helpers import DENY_SERIES_MUTATION, create_reservation_series | ||
|
||
# Applied to all tests | ||
pytestmark = [ | ||
pytest.mark.django_db, | ||
] | ||
|
||
|
||
@freeze_time(local_datetime(year=2024, month=1, day=1)) | ||
def test_recurring_reservations__deny_series(graphql): | ||
reason = ReservationDenyReasonFactory.create() | ||
|
||
reservation_series = create_reservation_series() | ||
|
||
data = { | ||
"pk": reservation_series.pk, | ||
"denyReason": reason.pk, | ||
"handlingDetails": "Handling details", | ||
} | ||
|
||
graphql.login_with_superuser() | ||
response = graphql(DENY_SERIES_MUTATION, input_data=data) | ||
|
||
assert response.has_errors is False, response.errors | ||
|
||
assert response.first_query_object == {"denied": 5, "future": 5} | ||
assert reservation_series.reservations.count() == 9 | ||
|
||
future_reservations = reservation_series.reservations.filter(begin__gt=local_datetime()) | ||
past_reservations = reservation_series.reservations.filter(begin__lte=local_datetime()) | ||
|
||
assert all(reservation.state == ReservationStateChoice.DENIED for reservation in future_reservations) | ||
assert all(reservation.deny_reason == reason for reservation in future_reservations) | ||
assert all(reservation.handling_details == "Handling details" for reservation in future_reservations) | ||
assert all(reservation.handled_at == local_datetime() for reservation in future_reservations) | ||
|
||
assert all(reservation.state != ReservationStateChoice.DENIED for reservation in past_reservations) | ||
assert all(reservation.deny_reason != reason for reservation in past_reservations) | ||
assert all(reservation.handling_details != "Handling details" for reservation in past_reservations) | ||
assert all(reservation.handled_at is None for reservation in past_reservations) | ||
|
||
|
||
@freeze_time(local_datetime(year=2024, month=1, day=1)) | ||
def test_recurring_reservations__deny_series__dont_need_handling_details(graphql): | ||
reason = ReservationDenyReasonFactory.create() | ||
|
||
reservation_series = create_reservation_series() | ||
|
||
data = { | ||
"pk": reservation_series.pk, | ||
"denyReason": reason.pk, | ||
} | ||
|
||
graphql.login_with_superuser() | ||
response = graphql(DENY_SERIES_MUTATION, input_data=data) | ||
|
||
assert response.has_errors is False, response.errors | ||
|
||
assert response.first_query_object == {"denied": 5, "future": 5} | ||
|
||
|
||
@freeze_time(local_datetime(year=2024, month=1, day=1)) | ||
def test_recurring_reservations__deny_series__reason_missing(graphql): | ||
reservation_series = create_reservation_series() | ||
|
||
data = { | ||
"pk": reservation_series.pk, | ||
"denyReason": 1, | ||
"handlingDetails": "Handling details", | ||
} | ||
|
||
graphql.login_with_superuser() | ||
response = graphql(DENY_SERIES_MUTATION, input_data=data) | ||
|
||
assert response.error_message() == "Mutation was unsuccessful." | ||
assert response.field_error_messages("denyReason") == ["Deny reason with pk 1 does not exist."] | ||
|
||
|
||
@freeze_time(local_datetime(year=2024, month=1, day=1)) | ||
def test_recurring_reservations__deny_series__only_deny_certain_states(graphql): | ||
reason = ReservationDenyReasonFactory.create() | ||
|
||
reservation_series = create_reservation_series() | ||
|
||
last_reservation = reservation_series.reservations.order_by("begin").last() | ||
last_reservation.state = ReservationStateChoice.WAITING_FOR_PAYMENT | ||
last_reservation.save() | ||
|
||
data = { | ||
"pk": reservation_series.pk, | ||
"denyReason": reason.pk, | ||
"handlingDetails": "Handling details", | ||
} | ||
|
||
graphql.login_with_superuser() | ||
response = graphql(DENY_SERIES_MUTATION, input_data=data) | ||
|
||
assert response.has_errors is False, response.errors | ||
|
||
# Last reservation is denied since it's waiting for payment | ||
assert response.first_query_object == {"denied": 4, "future": 5} |
131 changes: 131 additions & 0 deletions
131
tests/test_graphql_api/test_recurring_reservation/test_deny_series_permissions.py
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 |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import pytest | ||
from freezegun import freeze_time | ||
|
||
from tests.factories import ReservationDenyReasonFactory, UnitRoleFactory, UserFactory | ||
from tilavarauspalvelu.enums import UserRoleChoice | ||
from utils.date_utils import local_datetime | ||
|
||
from .helpers import DENY_SERIES_MUTATION, create_reservation_series | ||
|
||
pytestmark = [ | ||
pytest.mark.django_db, | ||
] | ||
|
||
|
||
@freeze_time(local_datetime(year=2024, month=1, day=1)) | ||
def test_recurring_reservations__deny_series__regular_user(graphql): | ||
reason = ReservationDenyReasonFactory.create() | ||
|
||
reservation_series = create_reservation_series() | ||
|
||
data = { | ||
"pk": reservation_series.pk, | ||
"denyReason": reason.pk, | ||
} | ||
|
||
graphql.login_with_regular_user() | ||
|
||
response = graphql(DENY_SERIES_MUTATION, input_data=data) | ||
|
||
assert response.error_message() == "No permission to update." | ||
|
||
|
||
@freeze_time(local_datetime(year=2024, month=1, day=1)) | ||
def test_recurring_reservations__deny_series__general_admin(graphql): | ||
reason = ReservationDenyReasonFactory.create() | ||
|
||
reservation_series = create_reservation_series() | ||
|
||
data = { | ||
"pk": reservation_series.pk, | ||
"denyReason": reason.pk, | ||
} | ||
|
||
graphql.login_user_with_role(role=UserRoleChoice.ADMIN) | ||
|
||
response = graphql(DENY_SERIES_MUTATION, input_data=data) | ||
|
||
assert response.has_errors is False, response.errors | ||
|
||
|
||
@freeze_time(local_datetime(year=2024, month=1, day=1)) | ||
def test_recurring_reservations__deny_series__unit_admin(graphql): | ||
reason = ReservationDenyReasonFactory.create() | ||
|
||
reservation_series = create_reservation_series() | ||
|
||
data = { | ||
"pk": reservation_series.pk, | ||
"denyReason": reason.pk, | ||
} | ||
|
||
unit = reservation_series.reservation_unit.unit | ||
user = UserFactory.create_with_unit_role(role=UserRoleChoice.ADMIN, units=[unit]) | ||
graphql.force_login(user) | ||
|
||
response = graphql(DENY_SERIES_MUTATION, input_data=data) | ||
|
||
assert response.has_errors is False, response.errors | ||
|
||
|
||
@freeze_time(local_datetime(year=2024, month=1, day=1)) | ||
def test_recurring_reservations__deny_series__unit_handler(graphql): | ||
reason = ReservationDenyReasonFactory.create() | ||
|
||
reservation_series = create_reservation_series() | ||
|
||
data = { | ||
"pk": reservation_series.pk, | ||
"denyReason": reason.pk, | ||
} | ||
|
||
unit = reservation_series.reservation_unit.unit | ||
user = UserFactory.create_with_unit_role(role=UserRoleChoice.HANDLER, units=[unit]) | ||
graphql.force_login(user) | ||
|
||
response = graphql(DENY_SERIES_MUTATION, input_data=data) | ||
|
||
assert response.has_errors is False, response.errors | ||
|
||
|
||
@freeze_time(local_datetime(year=2024, month=1, day=1)) | ||
def test_recurring_reservations__deny_series__unit_reserver__own_reservation(graphql): | ||
reason = ReservationDenyReasonFactory.create() | ||
|
||
user = UserFactory.create() | ||
|
||
reservation_series = create_reservation_series(user=user) | ||
|
||
unit = reservation_series.reservation_unit.unit | ||
UnitRoleFactory.create(user=user, role=UserRoleChoice.RESERVER, units=[unit]) | ||
|
||
data = { | ||
"pk": reservation_series.pk, | ||
"denyReason": reason.pk, | ||
} | ||
|
||
graphql.force_login(user) | ||
|
||
response = graphql(DENY_SERIES_MUTATION, input_data=data) | ||
|
||
assert response.has_errors is False, response.errors | ||
|
||
|
||
@freeze_time(local_datetime(year=2024, month=1, day=1)) | ||
def test_recurring_reservations__deny_series__unit_reserver__other_user_reservation(graphql): | ||
reason = ReservationDenyReasonFactory.create() | ||
|
||
reservation_series = create_reservation_series() | ||
|
||
data = { | ||
"pk": reservation_series.pk, | ||
"denyReason": reason.pk, | ||
} | ||
|
||
unit = reservation_series.reservation_unit.unit | ||
user = UserFactory.create_with_unit_role(role=UserRoleChoice.RESERVER, units=[unit]) | ||
graphql.force_login(user) | ||
|
||
response = graphql(DENY_SERIES_MUTATION, input_data=data) | ||
|
||
assert response.error_message() == "No permission to update." |
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.