Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix seeding bugs add missing tests #335

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/waffles/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
docopt==0.6.2
Flask==2.3.3
markupsafe==2.1.5
git+https://github.com/cds-snc/[email protected].7#egg=notifications-utils
git+https://github.com/cds-snc/[email protected].8#egg=notifications-utils
5 changes: 3 additions & 2 deletions notifications_utils/clients/redis/annual_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def decode_byte_dict(dict: dict, value_type=str):
# Check if expected_value_type is one of the allowed types
if value_type not in {int, float, str}:
raise ValueError("expected_value_type must be int, float, or str")
return {key.decode("utf-8"): value_type(value.decode("utf-8")) for key, value in dict.items()}
return {key.decode("utf-8"): value_type(value.decode("utf-8")) for key, value in dict.items() if dict.items()}


class RedisAnnualLimit:
Expand Down Expand Up @@ -110,7 +110,8 @@ def was_seeded_today(self, service_id):
return last_seeded_time == datetime.utcnow().strftime("%Y-%m-%d") if last_seeded_time else False

def get_seeded_at(self, service_id: str):
return self._redis_client.get_hash_field(annual_limit_status_key(service_id), SEEDED_AT).decode("utf-8")
seeded_at = self._redis_client.get_hash_field(annual_limit_status_key(service_id), SEEDED_AT)
return seeded_at and seeded_at.decode("utf-8")

def set_seeded_at(self, service_id):
self._redis_client.set_hash_value(annual_limit_status_key(service_id), SEEDED_AT, datetime.utcnow().strftime("%Y-%m-%d"))
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "notifications-utils"
version = "52.3.7"
version = "52.3.8"
description = "Shared python code for Notification - Provides logging utils etc."
authors = ["Canadian Digital Service"]
license = "MIT license"
Expand Down
23 changes: 23 additions & 0 deletions tests/test_annual_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,29 @@ def test_clear_annual_limit_statuses(mock_annual_limit_client, mock_annual_limit
assert len(mock_annual_limit_client.get_all_annual_limit_statuses(mocked_service_id)) == 0


@freeze_time("2024-10-25 12:00:00.000000")
@pytest.mark.parametrize("seeded_at_value, expected_value", [(b"2024-10-25", True), (None, False)])
def test_was_seeded_today(mock_annual_limit_client, seeded_at_value, expected_value, mocked_service_id, mocker):
mocker.patch.object(mock_annual_limit_client._redis_client, "get_hash_field", return_value=seeded_at_value)
result = mock_annual_limit_client.was_seeded_today(mocked_service_id)
assert result == expected_value


@freeze_time("2024-10-25 12:00:00.000000")
def test_set_seeded_at(mock_annual_limit_client, mocked_service_id):
mock_annual_limit_client.set_seeded_at(mocked_service_id)
result = mock_annual_limit_client.get_seeded_at(mocked_service_id)
assert result == datetime.utcnow().strftime("%Y-%m-%d")


@freeze_time("2024-10-25 12:00:00.000000")
@pytest.mark.parametrize("seeded_at_value, expected_value", [(b"2024-10-25", "2024-10-25"), (None, None)])
def test_get_seeded_at(mock_annual_limit_client, seeded_at_value, expected_value, mocked_service_id, mocker):
mocker.patch.object(mock_annual_limit_client._redis_client, "get_hash_field", return_value=seeded_at_value)
result = mock_annual_limit_client.get_seeded_at(mocked_service_id)
assert result == expected_value


@freeze_time("2024-10-25 12:00:00.000000")
def test_set_nearing_sms_limit(mock_annual_limit_client, mocked_service_id):
mock_annual_limit_client.set_nearing_sms_limit(mocked_service_id)
Expand Down
Loading