Skip to content

Commit

Permalink
Rename _check_if_sent to _has_been_sent
Browse files Browse the repository at this point in the history
  • Loading branch information
TheByronHimes committed Mar 4, 2024
1 parent b3a8640 commit a89b095
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/ns/core/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _create_notification_record(
hash_sum = sha256(notification.model_dump_json().encode("utf-8")).hexdigest()
return models.NotificationRecord(hash_sum=hash_sum, sent=False)

async def _check_if_sent(self, *, hash_sum: str) -> bool:
async def _has_been_sent(self, *, hash_sum: str) -> bool:
"""Check whether the notification has been sent already.
Returns:
Expand All @@ -100,7 +100,7 @@ async def send_notification(self, *, notification: event_schemas.Notification):
)

# Abort if the notification has been sent already
if await self._check_if_sent(hash_sum=notification_record.hash_sum):
if await self._has_been_sent(hash_sum=notification_record.hash_sum):
log.info("Notification already sent, skipping.")
return

Expand Down
16 changes: 8 additions & 8 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ async def test_consume_thru_send(joint_fixture: JointFixture):

@pytest.mark.asyncio(scope="session")
async def test_helper_functions(joint_fixture: JointFixture):
"""Unit test for the _check_if_sent function, _create_notification_record,
"""Unit test for the _has_been_sent function, _create_notification_record,
and _register_new_notification function.
"""
# Cast notifier type
Expand All @@ -161,8 +161,8 @@ async def test_helper_functions(joint_fixture: JointFixture):

assert actual_record.model_dump() == expected_record.model_dump()

# Now check the _check_if_sent function before the record has been inserted
assert not await joint_fixture.notifier._check_if_sent(
# Now check the _has_been_sent function before the record has been inserted
assert not await joint_fixture.notifier._has_been_sent(
hash_sum=actual_record.hash_sum
)

Expand All @@ -180,16 +180,16 @@ async def test_helper_functions(joint_fixture: JointFixture):
assert record_in_db.model_dump() == actual_record.model_dump()

# Record still has not been sent, but now it's in the database. Do another check
assert not await joint_fixture.notifier._check_if_sent(
assert not await joint_fixture.notifier._has_been_sent(
hash_sum=actual_record.hash_sum
)

# Now mark the record as sent
actual_record.sent = True
await joint_fixture.notifier._notification_record_dao.update(dto=actual_record)

# Now the record has been marked as sent, so _check_if_sent should return False
assert await joint_fixture.notifier._check_if_sent(hash_sum=actual_record.hash_sum)
# Now the record has been marked as sent, so _has_been_sent should return False
assert await joint_fixture.notifier._has_been_sent(hash_sum=actual_record.hash_sum)


@pytest.mark.asyncio(scope="session")
Expand All @@ -211,7 +211,7 @@ async def test_idempotence_and_transmission(joint_fixture: JointFixture):
)

# the record hasn't been sent, so this should return False
assert not await joint_fixture.notifier._check_if_sent(hash_sum=record.hash_sum)
assert not await joint_fixture.notifier._has_been_sent(hash_sum=record.hash_sum)

server = DummyServer(config=joint_fixture.config)
expected_email = joint_fixture.notifier._construct_email(
Expand All @@ -224,7 +224,7 @@ async def test_idempotence_and_transmission(joint_fixture: JointFixture):
await joint_fixture.event_subscriber.run(forever=False)

# Verify that the notification has now been marked as sent
assert await joint_fixture.notifier._check_if_sent(hash_sum=record.hash_sum)
assert await joint_fixture.notifier._has_been_sent(hash_sum=record.hash_sum)

# Now publish the same event again
await joint_fixture.kafka.publish_event(
Expand Down

0 comments on commit a89b095

Please sign in to comment.