Skip to content

Commit

Permalink
adds possibility to add signalering to sigmax description if specific… (
Browse files Browse the repository at this point in the history
#1487)

* adds possibility to add signalering to sigmax description if specific source is provided

* remove unnecessary whitespace
  • Loading branch information
ramonavic authored Jan 27, 2025
1 parent 18ec013 commit 1db11a5
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
from datetime import timedelta

from django.conf import settings
from django.template.loader import render_to_string

from signals.apps.sigmax.stuf_protocol.outgoing.stuf import _send_stuf_message
Expand Down Expand Up @@ -55,6 +56,11 @@ def _generate_omschrijving(signal, seq_no):
urgent = 'URGENT'
else:
urgent = None
if (settings.SIGMAX_TRANSFORM_DESCRIPTION_BASED_ON_SOURCE is not None
and signal.source == settings.SIGMAX_TRANSFORM_DESCRIPTION_BASED_ON_SOURCE):
extra_description = 'Signalering'
else:
extra_description = None

category = signal.category_assignment.category.name if signal.category_assignment else 'Categorie Onbekend'

Expand All @@ -72,11 +78,12 @@ def _generate_omschrijving(signal, seq_no):

area = _determine_area_for_omschrijving(signal, buurt, stadsdeel_code_sigmax)

return '{} SIA-{}.{}{} {}{}'.format(
return '{} SIA-{}.{}{}{} {}{}'.format(
category,
signal.id,
seq_no,
f" {urgent}" if urgent else '',
f" {extra_description}" if extra_description else '',
signal.location.short_address_text,
f" {area}" if area else ''
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from datetime import timedelta

from django.contrib.gis.geos import Point
from django.test import TestCase
from django.test import TestCase, override_settings
from django.utils import timezone
from lxml import etree
from xmlunittest import XmlTestMixin
Expand All @@ -21,7 +21,12 @@
_generate_creeerZaak_Lk01,
_generate_omschrijving
)
from signals.apps.signals.factories import BuurtFactory, SignalFactory, SignalFactoryValidLocation
from signals.apps.signals.factories import (
BuurtFactory,
SignalFactory,
SignalFactoryValidLocation,
SourceFactory
)
from signals.apps.signals.models import STADSDELEN, Priority, Signal
from signals.apps.signals.tests.valid_locations import STADHUIS

Expand Down Expand Up @@ -289,6 +294,113 @@ def test_generate_omschrijving_with_area_name_and_buurt_urgent(self) -> None:
seq_no = '01'
self.assertEqual(_generate_omschrijving(signal, seq_no), correct)

@override_settings(SIGMAX_TRANSFORM_DESCRIPTION_BASED_ON_SOURCE='Automatische Signalering')
def test_generate_omschrijving_with_extra_description(self) -> None:
signal = SignalFactoryValidLocation.create()
stadsdeel = signal.location.stadsdeel

source = SourceFactory.create(name='Automatische Signalering')
signal.source = source.name
signal.save()

correct = '{} SIA-{}.01 Signalering {} {}'.format(
signal.category_assignment.category.name,
signal.pk,
signal.location.short_address_text,
SIGMAX_STADSDEEL_MAPPING.get(stadsdeel),
)

seq_no = '01'
self.assertEqual(_generate_omschrijving(signal, seq_no), correct)

@override_settings(SIGMAX_TRANSFORM_DESCRIPTION_BASED_ON_SOURCE='Automatische Signalering')
def test_generate_omschrijving_with_area_name_and_buurt_and_extra_description(self) -> None:
# It should only show the buurt and not the area.
signal = SignalFactoryValidLocation.create(priority__priority=Priority.PRIORITY_LOW)
signal.location.stadsdeel = None
signal.location.area_name = 'Vondelpark'

source = SourceFactory.create(name='Automatische Signalering')
signal.source = source.name

buurt = BuurtFactory.create()
signal.location.buurt_code = buurt.vollcode
signal.location.save()

correct = '{} SIA-{}.01 Signalering {} {}'.format(
signal.category_assignment.category.name,
signal.pk,
signal.location.short_address_text,
buurt.naam
)

seq_no = '01'
self.assertEqual(_generate_omschrijving(signal, seq_no), correct)

@override_settings(SIGMAX_TRANSFORM_DESCRIPTION_BASED_ON_SOURCE='Automatische Signalering')
def test_generate_omschrijving_with_urgent_area_name_and_buurt_and_extra_description(self) -> None:
# It should only show the buurt and not the area.
signal = SignalFactoryValidLocation.create(priority__priority=Priority.PRIORITY_HIGH)
signal.location.stadsdeel = None
signal.location.area_name = 'Vondelpark'

source = SourceFactory.create(name='Automatische Signalering')
signal.source = source.name

buurt = BuurtFactory.create()
signal.location.buurt_code = buurt.vollcode
signal.location.save()

correct = '{} SIA-{}.01 URGENT Signalering {} {}'.format(
signal.category_assignment.category.name,
signal.pk,
signal.location.short_address_text,
buurt.naam
)

seq_no = '01'
self.assertEqual(_generate_omschrijving(signal, seq_no), correct)

@override_settings(SIGMAX_TRANSFORM_DESCRIPTION_BASED_ON_SOURCE='Automatische Signalering')
def test_generate_omschrijving_with_urgent_and_extra_description(self) -> None:
signal = SignalFactoryValidLocation.create(priority__priority=Priority.PRIORITY_HIGH)
stadsdeel = signal.location.stadsdeel

source = SourceFactory.create(name='Automatische Signalering')
source.save()
signal.source = source.name
signal.save()

correct = '{} SIA-{}.01 URGENT Signalering {} {}'.format(
signal.category_assignment.category.name,
signal.pk,
signal.location.short_address_text,
SIGMAX_STADSDEEL_MAPPING.get(stadsdeel),
)

seq_no = '01'
self.assertEqual(_generate_omschrijving(signal, seq_no), correct)

@override_settings(SIGMAX_TRANSFORM_DESCRIPTION_BASED_ON_SOURCE='Automatische Signalering')
def test_generate_omschrijving_with_urgent_and_extra_description_and_area_name(self) -> None:
signal = SignalFactoryValidLocation.create(priority__priority=Priority.PRIORITY_HIGH)
signal.location.stadsdeel = None
signal.location.area_name = 'Vondelpark'

source = SourceFactory.create(name='Automatische Signalering')
signal.source = source.name
signal.save()

correct = '{} SIA-{}.01 URGENT Signalering {} {}'.format(
signal.category_assignment.category.name,
signal.pk,
signal.location.short_address_text,
signal.location.area_name
)

seq_no = '01'
self.assertEqual(_generate_omschrijving(signal, seq_no), correct)


class TestAddressMatchesSigmaxExpectation(TestCase):
def setUp(self) -> None:
Expand Down
4 changes: 4 additions & 0 deletions app/signals/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ def is_super_user(user) -> bool:
SIGMAX_CLIENT_KEY: str | None = os.getenv('SIGMAX_CLIENT_KEY', None)
SIGMAX_SEND_FAIL_TIMEOUT_MINUTES: str | int = os.getenv('SIGMAX_SEND_FAIL_TIMEOUT_MINUTES', 60*24) # noqa Default is 24hrs.

SIGMAX_TRANSFORM_DESCRIPTION_BASED_ON_SOURCE: str | None = os.getenv(
'SIGMAX_TRANSFORM_DESCRIPTION_BASED_ON_SOURCE', None
) # If specific source is given the text Signalering will be added to the description to SIGMAX

# Child settings
SIGNAL_MAX_NUMBER_OF_CHILDREN: int = 10

Expand Down

0 comments on commit 1db11a5

Please sign in to comment.