Skip to content

Commit

Permalink
[#3283] Fixed/removed/updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vaszig committed Dec 2, 2024
1 parent 49e7538 commit 011defa
Show file tree
Hide file tree
Showing 19 changed files with 85 additions and 1,649 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_times_list(self):

self.assertEqual(response.status_code, status.HTTP_200_OK)
times = response.json()
self.assertEqual(len(times), 3)
self.assertEqual(len(times), 4)

def test_required_customer_fields_list(self):
endpoint = reverse("api:appointments-customer-fields")
Expand Down
16 changes: 10 additions & 6 deletions src/openforms/appointments/contrib/jcc/tests/test_api_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def test_get_locations_multiple_products(self, m):
def test_get_locations_returns_400_when_no_product_id_is_given(self):
response = self.client.get(self.endpoint)

self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), [])
self.assertEqual(response.status_code, 400)
self.assertEqual(response.json()["invalidParams"][0]["code"], "required")

def test_get_locations_returns_403_when_no_active_sessions(self):
self._clear_session()
Expand Down Expand Up @@ -165,8 +165,10 @@ def test_get_dates_returns_400_when_missing_query_params(self):
for query_param in [{}, {"product_id": 79}, {"location_id": 1}]:
with self.subTest(query_param=query_param):
response = self.client.get(self.endpoint, query_param)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), [])
self.assertEqual(response.status_code, 400)
self.assertEqual(
response.json()["invalidParams"][0]["code"], "required"
)

def test_get_dates_returns_403_when_no_active_sessions(self):
self._clear_session()
Expand Down Expand Up @@ -242,8 +244,10 @@ def test_get_times_returns_400_when_missing_query_params(self):
]:
with self.subTest(query_param=query_param):
response = self.client.get(self.endpoint, query_param)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), [])
self.assertEqual(response.status_code, 400)
self.assertEqual(
response.json()["invalidParams"][0]["code"], "required"
)

def test_get_times_returns_403_when_no_active_sessions(self):
self._clear_session()
Expand Down
23 changes: 19 additions & 4 deletions src/openforms/appointments/contrib/jcc/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from openforms.utils.xml import fromstring
from soap.tests.factories import SoapServiceFactory

from ....base import AppointmentDetails, Customer, CustomerDetails, Location, Product
from ....base import AppointmentDetails, CustomerDetails, Location, Product
from ....core import book
from ....exceptions import (
AppointmentCreateFailed,
Expand Down Expand Up @@ -251,7 +251,12 @@ def test_get_required_customer_fields(self, m):
def test_create_appointment(self, m):
product = Product(identifier="1", code="PASAAN", name="Paspoort aanvraag")
location = Location(identifier="1", name="Maykin Media")
client = Customer(last_name="Doe", birthdate=date(1980, 1, 1))
client = CustomerDetails(
details={
CustomerFields.last_name: "Doe",
CustomerFields.birthday: "1980-01-01",
}
)

m.post(
"http://example.com/soap11",
Expand Down Expand Up @@ -665,7 +670,12 @@ def test_get_times_unexpected_exception(self, m):
def test_create_appointment_failure(self, m):
product = Product(identifier="1", code="PASAAN", name="Paspoort aanvraag")
location = Location(identifier="1", name="Maykin Media")
client = Customer(last_name="Doe", birthdate=date(1980, 1, 1))
client = CustomerDetails(
details={
CustomerFields.last_name: "Doe",
CustomerFields.birthday: "1980-01-01",
}
)
start_at = datetime(2021, 8, 23, 6, 0, 0).replace(tzinfo=timezone.utc)
m.post(
"http://example.com/soap11",
Expand All @@ -681,7 +691,12 @@ def test_create_appointment_failure(self, m):
def test_create_appointment_unexpected_exception(self, m):
product = Product(identifier="1", code="PASAAN", name="Paspoort aanvraag")
location = Location(identifier="1", name="Maykin Media")
client = Customer(last_name="Doe", birthdate=date(1980, 1, 1))
client = CustomerDetails(
details={
CustomerFields.last_name: "Doe",
CustomerFields.birthday: "1980-01-01",
}
)
start_at = datetime(2021, 8, 23, 6, 0, 0).replace(tzinfo=timezone.utc)
m.post(requests_mock.ANY, exc=IOError("tubes are closed"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def test_get_locations_returns_all_locations_for_a_product(self, m):
def test_get_locations_returns_400_when_no_product_id_is_given(self):
response = self.client.get(self.endpoint)

self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), [])
self.assertEqual(response.status_code, 400)
self.assertEqual(response.json()["invalidParams"][0]["code"], "required")

def test_get_locations_returns_403_when_no_active_sessions(self):
self._clear_session()
Expand Down Expand Up @@ -156,8 +156,10 @@ def test_get_dates_returns_400_when_missing_query_params(self):
for query_param in [{}, {"product_id": 79}, {"location_id": 1}]:
with self.subTest(query_param=query_param):
response = self.client.get(self.endpoint, query_param)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), [])
self.assertEqual(response.status_code, 400)
self.assertEqual(
response.json()["invalidParams"][0]["code"], "required"
)

def test_get_dates_returns_403_when_no_active_sessions(self):
self._clear_session()
Expand Down Expand Up @@ -232,8 +234,10 @@ def test_get_times_returns_400_when_missing_query_params(self):
]:
with self.subTest(query_param=query_param):
response = self.client.get(self.endpoint, query_param)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), [])
self.assertEqual(response.status_code, 400)
self.assertEqual(
response.json()["invalidParams"][0]["code"], "required"
)

def test_get_times_returns_403_when_no_active_sessions(self):
self._clear_session()
Expand Down
23 changes: 19 additions & 4 deletions src/openforms/appointments/contrib/qmatic/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)
from openforms.utils.tests.logging import disable_logging

from ....base import AppointmentDetails, Customer, Location, Product
from ....base import AppointmentDetails, CustomerDetails, Location, Product
from ....core import book
from ....exceptions import (
AppointmentCreateFailed,
Expand Down Expand Up @@ -247,7 +247,12 @@ def test_create_appointment(self, m):
location = Location(
identifier="f364d92b7fa07a48c4ecc862de30c47", name="Branch 1"
)
client = Customer(last_name="Doe", birthdate=date(1980, 1, 1))
client = CustomerDetails(
details={
CustomerFields.last_name: "Doe",
CustomerFields.birthday: "1980-01-01",
}
)
day = datetime(2016, 12, 6, 9, 0, 0)

m.get(
Expand Down Expand Up @@ -529,7 +534,12 @@ def test_get_times_unexpected_exception(self, m):
def test_create_appointment_failure(self, m):
product = Product(identifier="1", code="PASAAN", name="Paspoort aanvraag")
location = Location(identifier="1", name="Maykin Media")
client = Customer(last_name="Doe", birthdate=date(1980, 1, 1))
client = CustomerDetails(
details={
CustomerFields.last_name: "Doe",
CustomerFields.birthday: "1980-01-01",
}
)
start_at = timezone.make_aware(datetime(2021, 8, 23, 6, 0, 0))
m.get(
f"{self.api_root}v1/branches/1",
Expand Down Expand Up @@ -576,7 +586,12 @@ def test_create_appointment_failure(self, m):
def test_create_appointment_unexpected_exception(self, m):
product = Product(identifier="1", code="PASAAN", name="Paspoort aanvraag")
location = Location(identifier="1", name="Maykin Media")
client = Customer(last_name="Doe", birthdate=date(1980, 1, 1))
client = CustomerDetails(
details={
CustomerFields.last_name: "Doe",
CustomerFields.birthday: "1980-01-01",
}
)
start_at = datetime(2021, 8, 23, 6, 0, 0).replace(tzinfo=timezone.utc)
m.get(
f"{self.api_root}v1/branches/1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.core.management.base import CommandError
from django.db.models import Q

from openforms.appointments.base import CustomerDetails
from openforms.submissions.models import Submission

from ...base import CustomerDetails
Expand Down
31 changes: 2 additions & 29 deletions src/openforms/appointments/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class TestPlugin(DemoAppointment):
@disable_admin_mfa()
class AppointmentInfoAdminTests(WebTest):
@freeze_time("2021-11-26T17:00:00+01:00")
def test_cancel_and_change_links_only_for_superuser(self):
def test_cancel_link_only_for_superuser(self):
normal, staff = [
UserFactory.create(user_permissions=["view_appointmentinfo"]),
StaffUserFactory.create(user_permissions=["view_appointmentinfo"]),
Expand Down Expand Up @@ -84,34 +84,7 @@ def test_cancel_and_change_links_only_for_superuser(self):
self.assertFalse(object_actions_col)

@freeze_time("2021-11-26T17:00:00+01:00")
def test_cancel_and_change_links_legacy(self):
user = SuperUserFactory.create()
# appointment in the past
AppointmentInfoFactory.create(
registration_ok=True, start_time="2021-11-01T17:00:00+01:00"
)
# appointment in the future
AppointmentInfoFactory.create(
registration_ok=True, start_time="2021-11-30T17:00:00+01:00"
)

changelist = self.app.get(
reverse("admin:appointments_appointmentinfo_changelist"), user=user
)

self.assertEqual(changelist.status_code, 200)
object_actions_col = changelist.pyquery(".field-get_object_actions")

# future appointment
app1_links = object_actions_col.eq(0).find("a")
self.assertEqual(len(app1_links), 2)

# past appointment
app2_links = object_actions_col.eq(1).find("a")
self.assertEqual(len(app2_links), 0)

@freeze_time("2021-11-26T17:00:00+01:00")
def test_cancel_and_change_links(self):
def test_cancel_link(self):

user = SuperUserFactory.create()
# appointment in the past
Expand Down
5 changes: 2 additions & 3 deletions src/openforms/appointments/tests/test_api_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,5 @@ def test_list_products_with_existing_product_invalid_query_param(self):

response = self.client.get(self.endpoint, {"product_id": [""]})

# XXX in 3.0, this will become HTTP 400
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), [])
self.assertEqual(response.status_code, 400)
self.assertEqual(response.json()["invalidParams"][0]["code"], "blank")
17 changes: 0 additions & 17 deletions src/openforms/appointments/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,3 @@ def test_get_cancel_link(self):
)
cancel_url = f"https://example.com{cancel_path}"
self.assertEqual(cancel_url, result)

@override_settings(BASE_URL="https://example.com/")
def test_get_change_link(self):
submission = SubmissionFactory.create(completed=True)
AppointmentInfoFactory.create(submission=submission, registration_ok=True)

result = self.plugin.get_change_link(submission)

change_path = reverse(
"appointments:appointments-verify-change-appointment-link",
kwargs={
"token": submission_appointment_token_generator.make_token(submission),
"submission_uuid": submission.uuid,
},
)
change_url = f"https://example.com{change_path}"
self.assertEqual(change_url, result)
53 changes: 2 additions & 51 deletions src/openforms/appointments/tests/test_booking_appointment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import sys
from datetime import datetime, timedelta
from datetime import datetime
from unittest.mock import patch

from django.test import TestCase
Expand All @@ -21,11 +21,7 @@
)
from ..models import AppointmentInfo
from ..registry import Registry
from .factories import (
AppointmentFactory,
AppointmentInfoFactory,
AppointmentProductFactory,
)
from .factories import AppointmentFactory, AppointmentProductFactory

register = Registry()
register("demo")(DemoAppointment)
Expand Down Expand Up @@ -155,48 +151,3 @@ def test_plugin_invocation(self):
),
remarks="",
)

def test_cancels_previous_appointment(self):
new_completed_on = timezone.now() - timedelta(hours=1)
# new submission, to replace the previous one
submission = SubmissionFactory.create(
form__is_appointment_form=True,
has_previous_submission=True,
previous_submission__completed=True,
previous_submission__completed_on=new_completed_on - timedelta(hours=12),
)
AppointmentFactory.create(submission=submission, plugin="demo")
# set the data of the previous submission
AppointmentFactory.create(
submission=submission.previous_submission, plugin="demo"
)
AppointmentInfoFactory.create(
submission=submission.previous_submission,
registration_ok=True,
appointment_id="98765",
)

with patch("openforms.appointments.core.register", new=register):
with supress_output(sys.stdout, os.devnull):
book_for_submission(submission)

info_by_id = {
info.appointment_id: info for info in AppointmentInfo.objects.all()
}
with self.subTest("New submissions/appointment"):
self.assertIn("test 1", info_by_id)
self.assertEqual(
info_by_id["test 1"].status, AppointmentDetailsStatus.success
)

with self.subTest("Cancelled submission/appointment"):
self.assertIn("98765", info_by_id)
self.assertEqual(
info_by_id["98765"].status, AppointmentDetailsStatus.cancelled
)

with self.subTest("Audit logging"):
log_records = TimelineLogProxy.objects.all()
events = {lr.event for lr in log_records}
self.assertIn("appointment_cancel_start", events)
self.assertIn("appointment_cancel_success", events)
5 changes: 1 addition & 4 deletions src/openforms/appointments/tests/test_confirmation_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def test_appointment_data_present_in_confirmation_email(self):
self.assertTagWithTextIn("td", "Email", message_html)
self.assertTagWithTextIn("td", "[email protected]", message_html)

def test_cancel_and_change_instructions(self):
def test_cancel_instructions(self):
appointment = AppointmentFactory.create(
plugin="with-email",
submission__language_code="nl",
Expand All @@ -293,12 +293,9 @@ def test_cancel_and_change_instructions(self):

plugin = register["with-email"]
cancel_link = plugin.get_cancel_link(appointment.submission)
change_link = plugin.get_change_link(appointment.submission)

with self.subTest(type="HTML"):
self.assertIn(cancel_link, message_html)
self.assertNotIn(change_link, message_html)

with self.subTest(type="plain text"):
self.assertIn(cancel_link, message_text)
self.assertNotIn(change_link, message_text)
Loading

0 comments on commit 011defa

Please sign in to comment.