Skip to content

Commit

Permalink
fix search of last notification
Browse files Browse the repository at this point in the history
  • Loading branch information
diegorubin committed Aug 2, 2021
1 parent 9f3e812 commit 27c4454
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
9 changes: 7 additions & 2 deletions lifeguard_mongodb/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ def __init__(self):
def save_last_notification_for_a_validation(self, notification):
save_or_update(
self.collection,
{"validation_name": notification.validation_name},
{
"validation_name": notification.validation_name,
"is_opened": notification.is_opened,
},
{
"validation_name": notification.validation_name,
"thread_ids": notification.thread_ids,
Expand All @@ -82,7 +85,9 @@ def save_last_notification_for_a_validation(self, notification):
)

def fetch_last_notification_for_a_validation(self, validation_name):
result = self.collection.find_one({"validation_name": validation_name})
result = self.collection.find_one(
{"validation_name": validation_name, "is_opened": True}
)
if result:
last_notification_status = NotificationStatus(
validation_name, result["thread_ids"], result["options"]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="lifeguard-mongodb",
version="0.0.5",
version="0.0.6",
url="https://github.com/LifeguardSystem/lifeguard-mongodb",
author="Diego Rubin",
author_email="[email protected]",
Expand Down
6 changes: 3 additions & 3 deletions tests/test_repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def test_fetch_last_notification_for_a_validation_is_none(self):

self.assertIsNone(result)
self.collection.find_one.assert_called_with(
{"validation_name": validation_name}
{"validation_name": validation_name, "is_opened": True}
)

def test_fetch_last_notification_for_a_validation_not_none(self):
Expand All @@ -142,7 +142,7 @@ def test_fetch_last_notification_for_a_validation_not_none(self):
self.assertEqual(result.options, {})
self.assertEqual(result.last_notification, datetime(2020, 11, 19))
self.collection.find_one.assert_called_with(
{"validation_name": validation_name}
{"validation_name": validation_name, "is_opened": True}
)

@patch("lifeguard.notifications.datetime")
Expand Down Expand Up @@ -174,7 +174,7 @@ def test_save_last_notification_for_a_validation_update(self, mock_datetime):
self.repository.save_last_notification_for_a_validation(notification_status)

self.collection.update_many.assert_called_with(
{"validation_name": "name"},
{"validation_name": "name", "is_opened": True},
{
"$set": {
"validation_name": "name",
Expand Down

0 comments on commit 27c4454

Please sign in to comment.