mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-10 15:22:24 -05:00
Format sequential number into an 8 char long hex
As per Vodafone spec for ibag format message number
This commit is contained in:
@@ -9,6 +9,8 @@ from app.config import QueueNames
|
||||
from app.models import BroadcastEventMessageType, BroadcastProvider
|
||||
from app.dao.broadcast_message_dao import dao_get_broadcast_event_by_id, create_broadcast_provider_message
|
||||
|
||||
from app.utils import format_sequential_number
|
||||
|
||||
|
||||
@notify_celery.task(name="send-broadcast-event")
|
||||
@statsd(namespace="tasks")
|
||||
@@ -79,10 +81,11 @@ def send_broadcast_provider_message(broadcast_event_id, provider):
|
||||
@notify_celery.task(name='trigger-link-test')
|
||||
def trigger_link_test(provider):
|
||||
identifier = str(uuid.uuid4())
|
||||
sequential_number = None
|
||||
formatted_seq_number = None
|
||||
if provider == BroadcastProvider.VODAFONE:
|
||||
sequence = Sequence('broadcast_provider_message_number_seq')
|
||||
sequential_number = db.session.connection().execute(sequence)
|
||||
formatted_seq_number = format_sequential_number(sequential_number)
|
||||
message = f"Sending a link test to CBC proxy for provider {provider} with ID {identifier}"
|
||||
current_app.logger.info(message)
|
||||
cbc_proxy_client.get_proxy(provider).send_link_test(identifier, sequential_number)
|
||||
cbc_proxy_client.get_proxy(provider).send_link_test(identifier, formatted_seq_number)
|
||||
|
||||
@@ -146,3 +146,7 @@ def get_archived_db_column_value(column):
|
||||
|
||||
def get_dt_string_or_none(val):
|
||||
return val.strftime(DATETIME_FORMAT) if val else None
|
||||
|
||||
|
||||
def format_sequential_number(sequential_number):
|
||||
return format(sequential_number, "x").zfill(8)
|
||||
|
||||
@@ -303,6 +303,7 @@ def test_trigger_link_tests_invokes_cbc_proxy_client(
|
||||
|
||||
# testing sequential number:
|
||||
if provider == 'vodafone':
|
||||
assert type(mock_send_link_test.mock_calls[0][1][1]) is int
|
||||
assert type(mock_send_link_test.mock_calls[0][1][1]) is str
|
||||
assert len(mock_send_link_test.mock_calls[0][1][1]) == 8
|
||||
else:
|
||||
assert not mock_send_link_test.mock_calls[0][1][1]
|
||||
|
||||
@@ -4,10 +4,11 @@ import pytest
|
||||
from freezegun import freeze_time
|
||||
|
||||
from app.utils import (
|
||||
format_sequential_number,
|
||||
get_london_midnight_in_utc,
|
||||
get_midnight_for_day_before,
|
||||
midnight_n_days_ago,
|
||||
get_notification_table_to_use,
|
||||
midnight_n_days_ago
|
||||
)
|
||||
from app.models import Notification, NotificationHistory
|
||||
|
||||
@@ -99,3 +100,7 @@ def test_get_notification_table_to_use_checks_service_data_retention(sample_serv
|
||||
# falls back to 7 days if not specified
|
||||
assert get_notification_table_to_use(sample_service, 'sms', date(2019, 1, 1), False) == NotificationHistory
|
||||
assert get_notification_table_to_use(sample_service, 'sms', date(2019, 1, 2), False) == Notification
|
||||
|
||||
|
||||
def test_format_sequential_number():
|
||||
assert format_sequential_number(123) == '0000007b'
|
||||
|
||||
Reference in New Issue
Block a user