|
| 1 | +import pytest |
| 2 | + |
| 3 | +from applications.choices import Weekday |
| 4 | +from tests.factories import ApplicationFactory, UserFactory |
| 5 | + |
| 6 | +from .helpers import REJECT_MUTATION |
| 7 | + |
| 8 | +# Applied to all tests |
| 9 | +pytestmark = [ |
| 10 | + pytest.mark.django_db, |
| 11 | +] |
| 12 | + |
| 13 | + |
| 14 | +def test_application__reject_all_options(graphql): |
| 15 | + application = ApplicationFactory.create_in_status_in_allocation() |
| 16 | + section = application.application_sections.first() |
| 17 | + option = section.reservation_unit_options.first() |
| 18 | + assert option.rejected is False |
| 19 | + |
| 20 | + graphql.login_with_superuser() |
| 21 | + response = graphql(REJECT_MUTATION, input_data={"pk": application.pk}) |
| 22 | + |
| 23 | + assert response.has_errors is False, response |
| 24 | + |
| 25 | + option.refresh_from_db() |
| 26 | + assert option.rejected is True |
| 27 | + |
| 28 | + |
| 29 | +def test_application__reject_all_options__has_allocations(graphql): |
| 30 | + application = ApplicationFactory.create_in_status_in_allocation( |
| 31 | + application_sections__reservation_unit_options__rejected=False, |
| 32 | + application_sections__reservation_unit_options__allocated_time_slots__day_of_the_week=Weekday.MONDAY, |
| 33 | + ) |
| 34 | + section = application.application_sections.first() |
| 35 | + option = section.reservation_unit_options.first() |
| 36 | + assert option.rejected is False |
| 37 | + assert option.allocated_time_slots.exists() |
| 38 | + |
| 39 | + graphql.login_with_superuser() |
| 40 | + response = graphql(REJECT_MUTATION, input_data={"pk": application.pk}) |
| 41 | + |
| 42 | + assert response.error_message() == "Mutation was unsuccessful.", response |
| 43 | + assert response.field_error_messages() == [ |
| 44 | + "Application has allocated time slots and cannot be rejected.", |
| 45 | + ] |
| 46 | + |
| 47 | + |
| 48 | +def test_application__reject_all_options__general_admin(graphql): |
| 49 | + application = ApplicationFactory.create_in_status_in_allocation() |
| 50 | + |
| 51 | + admin = UserFactory.create_with_general_permissions(perms=["can_handle_applications"]) |
| 52 | + graphql.force_login(admin) |
| 53 | + |
| 54 | + response = graphql(REJECT_MUTATION, input_data={"pk": application.pk}) |
| 55 | + |
| 56 | + assert response.has_errors is False |
| 57 | + |
| 58 | + |
| 59 | +def test_application__reject_all_options__unit_admin(graphql): |
| 60 | + application = ApplicationFactory.create_in_status_in_allocation() |
| 61 | + |
| 62 | + section = application.application_sections.first() |
| 63 | + unit = section.reservation_unit_options.first().reservation_unit.unit |
| 64 | + admin = UserFactory.create_with_unit_permissions(unit=unit, perms=["can_handle_applications"]) |
| 65 | + graphql.force_login(admin) |
| 66 | + |
| 67 | + response = graphql(REJECT_MUTATION, input_data={"pk": application.pk}) |
| 68 | + |
| 69 | + assert response.has_errors is False |
0 commit comments