Skip to content

Commit b92cb3f

Browse files
committed
Add some missing information to generated reservations
1 parent 431857f commit b92cb3f

6 files changed

Lines changed: 35 additions & 15 deletions

File tree

applications/tasks.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ def generate_reservation_series_from_allocations(application_round_id: int) -> N
111111

112112
reservation_details = ReservationDetails(
113113
name=recurring_reservation.name,
114-
description=application.additional_information,
115114
type=ReservationTypeChoice.SEASONAL,
116115
state=ReservationStateChoice.CONFIRMED,
117116
user=recurring_reservation.user,
@@ -126,6 +125,8 @@ def generate_reservation_series_from_allocations(application_round_id: int) -> N
126125
billing_address_street=billing_address_street,
127126
billing_address_city=billing_address_city,
128127
billing_address_zip=billing_address_zip,
128+
purpose=application_section.purpose,
129+
home_city=application.home_city,
129130
)
130131

131132
reservation_details["reservee_type"] = (
@@ -136,6 +137,16 @@ def generate_reservation_series_from_allocations(application_round_id: int) -> N
136137
else CustomerTypeChoice.NONPROFIT
137138
)
138139

140+
reservation_details["description"] = (
141+
application.additional_information
142+
if reservation_details["reservee_type"] == CustomerTypeChoice.INDIVIDUAL
143+
else (
144+
translate_for_user(_("Core business"), application.user)
145+
+ ": "
146+
+ application.organisation.core_business
147+
)
148+
)
149+
139150
if reservation_details["reservee_type"] == CustomerTypeChoice.INDIVIDUAL:
140151
reservation_details["reservee_address_street"] = billing_address_street
141152
reservation_details["reservee_address_city"] = billing_address_city

locale/fi/LC_MESSAGES/django.po

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,8 @@ msgstr "Teksti, joka näytetään hakijoille heidän täyttäessään hakemuksia
502502
msgid "Application this section is in."
503503
msgstr "Hakemus jolle tämä osa kuuluu."
504504

505+
#: applications/admin/forms/application_section.py
506+
#, python-format
505507
msgid ""
506508
"%(unallocated)s: Section has been created, but application round is still "
507509
"open. <br>%(in_allocation)s: Application round has closed, but the section "
@@ -514,8 +516,8 @@ msgstr ""
514516
"on vielä auki. <br>%(in_allocation)s: Hakuaika on sulkeutunut, mutta osaa ei "
515517
"ole vielä kokonaan käsitelty. <br>%(handled)s: Kausivarauskierros on "
516518
"käsitelty, tai osan toistokerrat on täytetty, tai kaikki varausyksikkö-"
517-
"vaihtoehdot on hylätty tai lukittu. <br>%(rejected)s: Kaikki "
518-
"haetut toistokerrat tälle hakemuksen osalle ovat lukittu tai hylätty. <br>"
519+
"vaihtoehdot on hylätty tai lukittu. <br>%(rejected)s: Kaikki haetut "
520+
"toistokerrat tälle hakemuksen osalle ovat lukittu tai hylätty. <br>"
519521

520522
#: applications/admin/forms/application_section.py reservations/admin.py
521523
#: reservations/models/reservation_statistic.py
@@ -1018,6 +1020,10 @@ msgstr "Sopivat aikavälit"
10181020
msgid "Begin and end times must be a multiples of 60 minutes."
10191021
msgstr "Alku- ja lopetusaikojen tulee olla 60 minuutin monikertoja."
10201022

1023+
#: applications/tasks.py
1024+
msgid "Core business"
1025+
msgstr "Ydinliiketoiminta"
1026+
10211027
#: applications/validators.py
10221028
msgid "This field is required."
10231029
msgstr "Tämä kenttä on pakollinen."

tests/test_helauth/test_pipeline_additions.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
from datetime import date
23
from typing import Any, NamedTuple
34

@@ -8,6 +9,7 @@
89
from users.helauth.clients import HelsinkiProfileClient
910
from users.helauth.parsers import ssn_to_date
1011
from users.helauth.pipeline import update_user_from_profile
12+
from utils.external_service.errors import ExternalServiceError
1113
from utils.sentry import SentryLogger
1214

1315
from .helpers import mock_request
@@ -76,19 +78,13 @@ def test_update_user_from_profile_logs_to_sentry_if_unsuccessful():
7678
@patch_method(HelsinkiProfileClient.get_token, return_value="token")
7779
@patch_method(HelsinkiProfileClient.generic, return_value=ResponseMock(json_data={"errors": [{"message": "foo"}]}))
7880
def test_update_user_from_profile_logs_to_sentry_if_raises():
79-
# given:
80-
# - There is a user without profile info
8181
user = UserFactory.create(profile_id="", date_of_birth=None)
8282

83-
# when:
84-
# - This user's info is updated from profile
85-
update_user_from_profile(request=mock_request(user))
83+
msg = "Helsinki profile: Response contains errors."
84+
with pytest.raises(ExternalServiceError, match=re.escape(msg)):
85+
update_user_from_profile(request=mock_request(user))
8686

8787
assert SentryLogger.log_exception.call_count == 1
88-
log_message = SentryLogger.log_exception.mock_calls[0][1][1]
89-
assert log_message == "Helsinki profile: Failed to update user from profile"
90-
log_message = SentryLogger.log_exception.mock_calls[0][1][0].args[0]
91-
assert log_message == "Helsinki profile: Response contains errors."
9288

9389

9490
@pytest.mark.parametrize(

tests/test_utils/test_generate_reservations_from_allocations.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime
2+
import re
23

34
import freezegun
45
import pytest
@@ -199,9 +200,10 @@ def test_generate_reservation_series_from_allocations__error_handling():
199200
slot = AllocatedTimeSlotFactory.create_ready_for_reservation()
200201
application_round = slot.reservation_unit_option.application_section.application.application_round
201202

202-
# Errors are not raised, but logged to Sentry.
203-
generate_reservation_series_from_allocations(application_round_id=application_round.id)
203+
with pytest.raises(ValueError, match=re.escape("Test error")):
204+
generate_reservation_series_from_allocations(application_round_id=application_round.id)
204205

206+
# Errors are logged to Sentry.
205207
assert SentryLogger.log_exception.call_count == 1
206208

207209

tilavarauspalvelu/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ def SEARCH_SETTINGS(cls):
491491
TPREK_UNIT_URL = values.URLValue()
492492
GRAPHQL_CODEGEN_ENABLED = False
493493
UPDATE_RESERVATION_UNIT_HIERARCHY = True
494+
SENTRY_LOGGER_ALWAYS_RE_RAISE = False
494495

495496
PRUNE_RESERVATIONS_OLDER_THAN_MINUTES = 20
496497
REMOVE_RESERVATION_STATS_OLDER_THAN_YEARS = 5
@@ -629,6 +630,7 @@ def SEARCH_SETTINGS(cls):
629630

630631
# --- Misc settings-----------------------------------------------------------------------------------------------
631632

633+
SENTRY_LOGGER_ALWAYS_RE_RAISE = True
632634
GRAPHQL_CODEGEN_ENABLED = values.BooleanValue(default=False)
633635
ICAL_HASH_SECRET = values.StringValue(default="") # nosec # NOSONAR
634636

@@ -801,6 +803,7 @@ def SEARCH_SETTINGS(cls):
801803
# Turn off reservation unit hierarchy updates from signals during tests,
802804
# since they slow them down a lot in CI. Refresh should be called manually when needed.
803805
UPDATE_RESERVATION_UNIT_HIERARCHY = False
806+
SENTRY_LOGGER_ALWAYS_RE_RAISE = True
804807

805808

806809
class Build(EmptyDefaults, Common, use_environ=True):

utils/sentry.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from functools import wraps
33
from typing import Any, Literal
44

5+
from django.conf import settings
56
from sentry_sdk import capture_exception, capture_message, push_scope
67

78
LogLevelStr = Literal["fatal", "critical", "error", "warning", "info", "debug"]
@@ -47,7 +48,8 @@ def wrapper(*args: P.args, **kwargs: P.kwargs) -> None:
4748
raise
4849

4950
SentryLogger.log_exception(err, details)
50-
if re_raise:
51+
# For local development, we should always re-raise an error for better debugging.
52+
if re_raise or settings.SENTRY_LOGGER_ALWAYS_RE_RAISE:
5153
raise
5254

5355
return wrapper

0 commit comments

Comments
 (0)