Skip to content

Commit

Permalink
Make notification IDs unique
Browse files Browse the repository at this point in the history
  • Loading branch information
quis committed Dec 13, 2024
1 parent 03fd3cf commit a67425b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import uuid
from datetime import UTC, datetime, timedelta
from itertools import repeat
from unittest.mock import patch
from urllib.parse import parse_qs, urlparse

Expand Down Expand Up @@ -552,10 +553,17 @@ def notification_json( # noqa: C901
if job:
job_payload = {"id": job["id"], "original_file_name": job["original_file_name"]}

def _get_notification_id(index):
if index < 16:
return "{}{}{}{}{}{}{}{}-{}{}{}{}-{}{}{}{}-{}{}{}{}-{}{}{}{}{}{}{}{}{}{}{}{}".format(
*repeat(hex(index)[2:], 32)
)
return str(uuid.uuid4())

data = {
"notifications": [
{
"id": sample_uuid(),
"id": _get_notification_id(i),
"to": to,
"template": template,
"job": job_payload,
Expand Down
4 changes: 2 additions & 2 deletions tests/app/main/views/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from freezegun import freeze_time

from app.main.views.jobs import get_time_left
from tests import NotifyBeautifulSoup, job_json, notification_json, sample_uuid, user_json
from tests import NotifyBeautifulSoup, job_json, notification_json, user_json
from tests.conftest import (
SERVICE_ONE_ID,
create_active_caseworking_user,
Expand Down Expand Up @@ -117,7 +117,7 @@ def test_should_show_page_for_one_job(
assert page.select_one("tbody tr a")["href"] == url_for(
"main.view_notification",
service_id=SERVICE_ONE_ID,
notification_id=sample_uuid(),
notification_id="00000000-0000-0000-0000-000000000000",
from_job=fake_uuid,
)

Expand Down

0 comments on commit a67425b

Please sign in to comment.