Skip to content

Commit

Permalink
💚 Fix test suite now that it's DST
Browse files Browse the repository at this point in the history
Classic test suite failures after going from summer to winter time...
  • Loading branch information
sergei-maertens committed Oct 30, 2023
1 parent 313cda3 commit b2924fa
Showing 1 changed file with 37 additions and 13 deletions.
50 changes: 37 additions & 13 deletions src/openforms/appointments/tests/test_api_appointment_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ def setUp(self):
self._add_submission_to_session(self.submission)

def test_appointment_data_is_recorded(self):
appointment_datetime = timezone.make_aware(
datetime.combine(TODAY, time(15, 15))
)
data = {
"submission": reverse(
"api:submission-detail", kwargs={"uuid": self.submission.uuid}
Expand All @@ -73,7 +76,7 @@ def test_appointment_data_is_recorded(self):
],
"location": "1",
"date": TODAY.isoformat(),
"datetime": f"{TODAY.isoformat()}T13:15:00Z",
"datetime": appointment_datetime.isoformat(),
"contactDetails": {
"lastName": "Periwinkle",
},
Expand All @@ -87,10 +90,7 @@ def test_appointment_data_is_recorded(self):
self.assertEqual(appointment.submission, self.submission)
self.assertEqual(appointment.plugin, "demo")
self.assertEqual(appointment.location, "1")
self.assertEqual(
appointment.datetime,
datetime.combine(TODAY, time(13, 15, 0)).replace(tzinfo=timezone.utc),
)
self.assertEqual(appointment.datetime, appointment_datetime)
self.assertEqual(
appointment.contact_details_meta,
[
Expand All @@ -116,6 +116,9 @@ def test_appointment_data_is_recorded(self):

@patch("openforms.submissions.api.mixins.on_completion")
def test_submission_is_completed(self, mock_on_completion):
appointment_datetime = timezone.make_aware(
datetime.combine(TODAY, time(15, 15))
)
data = {
"submission": reverse(
"api:submission-detail", kwargs={"uuid": self.submission.uuid}
Expand All @@ -128,7 +131,7 @@ def test_submission_is_completed(self, mock_on_completion):
],
"location": "1",
"date": TODAY,
"datetime": f"{TODAY}T13:15:00Z",
"datetime": appointment_datetime.isoformat(),
"contactDetails": {
"lastName": "Periwinkle",
},
Expand All @@ -150,14 +153,17 @@ def test_retry_does_not_cause_integrity_error(self):
# When there are on_completion processing errors, the client will re-post the
# same state. This must update the existing appointment rather than trying to
# create a new one.
appointment_datetime = timezone.make_aware(
datetime.combine(TODAY, time(15, 15))
)
data = {
"submission": reverse(
"api:submission-detail", kwargs={"uuid": self.submission.uuid}
),
"products": [{"productId": "2", "amount": 1}],
"location": "1",
"date": TODAY,
"datetime": f"{TODAY}T13:15:00Z",
"datetime": appointment_datetime.isoformat(),
"contactDetails": {
"lastName": "Periwinkle",
},
Expand Down Expand Up @@ -193,6 +199,9 @@ def test_retry_does_not_cause_integrity_error(self):

def test_privacy_policy_not_required(self):
self.global_configuration.ask_privacy_consent = False
appointment_datetime = timezone.make_aware(
datetime.combine(TODAY, time(15, 15))
)
data = {
"submission": reverse(
"api:submission-detail", kwargs={"uuid": self.submission.uuid}
Expand All @@ -205,7 +214,7 @@ def test_privacy_policy_not_required(self):
],
"location": "1",
"date": TODAY.isoformat(),
"datetime": f"{TODAY.isoformat()}T13:15:00Z",
"datetime": appointment_datetime.isoformat(),
"contactDetails": {
"lastName": "Periwinkle",
},
Expand Down Expand Up @@ -331,13 +340,16 @@ def test_required_privacy_policy_accept_missing(self):
self.assertEqual(invalid_params[0]["name"], "privacyPolicyAccepted")

def test_invalid_products(self):
appointment_datetime = timezone.make_aware(
datetime.combine(TODAY, time(15, 15))
)
base = {
"submission": reverse(
"api:submission-detail", kwargs={"uuid": self.submission.uuid}
),
"location": "1",
"date": TODAY.isoformat(),
"datetime": f"{TODAY.isoformat()}T13:15:00Z",
"datetime": appointment_datetime.isoformat(),
"contactDetails": {
"lastName": "Periwinkle",
},
Expand Down Expand Up @@ -407,14 +419,17 @@ def test_invalid_products(self):
def test_invalid_location_with_fixed_location_in_config(self):
# made up, but you can assume this is valid via the admin validation
self.config.limit_to_location = "2"
appointment_datetime = timezone.make_aware(
datetime.combine(TODAY, time(15, 15))
)
data = {
"submission": reverse(
"api:submission-detail", kwargs={"uuid": self.submission.uuid}
),
"products": [{"productId": "1", "amount": 1}],
"location": "1",
"date": TODAY.isoformat(),
"datetime": f"{TODAY.isoformat()}T13:15:00Z",
"datetime": appointment_datetime.isoformat(),
"contactDetails": {
"lastName": "Periwinkle",
},
Expand All @@ -431,14 +446,17 @@ def test_invalid_location_with_fixed_location_in_config(self):
def test_invalid_location_from_plugins_available_locations(self):
# made up, but you can assume this is valid via the admin validation
self.config.limit_to_location = ""
appointment_datetime = timezone.make_aware(
datetime.combine(TODAY, time(15, 15))
)
data = {
"submission": reverse(
"api:submission-detail", kwargs={"uuid": self.submission.uuid}
),
"products": [{"productId": "1", "amount": 1}],
"location": "123",
"date": TODAY.isoformat(),
"datetime": f"{TODAY.isoformat()}T13:15:00Z",
"datetime": appointment_datetime.isoformat(),
"contactDetails": {
"lastName": "Periwinkle",
},
Expand All @@ -453,13 +471,16 @@ def test_invalid_location_from_plugins_available_locations(self):
self.assertEqual(invalid_params[0]["name"], "location")

def test_invalid_date(self):
appointment_datetime = timezone.make_aware(
datetime.combine(TODAY, time(15, 15))
)
base = {
"submission": reverse(
"api:submission-detail", kwargs={"uuid": self.submission.uuid}
),
"products": [{"productId": "1", "amount": 1}],
"location": "1",
"datetime": f"{TODAY.isoformat()}T13:15:00Z",
"datetime": appointment_datetime.isoformat(),
"contactDetails": {
"lastName": "Periwinkle",
},
Expand Down Expand Up @@ -544,14 +565,17 @@ def test_invalid_datetime(self):
self.assertEqual(invalid_params[0]["name"], "datetime")

def test_invalid_contact_details(self):
appointment_datetime = timezone.make_aware(
datetime.combine(TODAY, time(15, 15))
)
base = {
"submission": reverse(
"api:submission-detail", kwargs={"uuid": self.submission.uuid}
),
"products": [{"productId": "1", "amount": 1}],
"location": "1",
"date": TODAY.isoformat(),
"datetime": f"{TODAY.isoformat()}T13:15:00Z",
"datetime": appointment_datetime.isoformat(),
"privacyPolicyAccepted": True,
}

Expand Down

0 comments on commit b2924fa

Please sign in to comment.