Skip to content

Commit

Permalink
Fix up the Recipient query
Browse files Browse the repository at this point in the history
Makes sure we're not accidentally doubling up somewhere
  • Loading branch information
Henry Walshaw committed Sep 10, 2024
1 parent cfeba33 commit 48ff5f7
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from resourceauth import ResourceAuth
import result


TEST_DIR = os.path.dirname(os.path.abspath(__file__))


Expand Down Expand Up @@ -95,26 +96,30 @@ def testRunResoures(self):
(resource.url, str(resource.runs[0])))

def testNotificationsApi(self):
Rcp = Recipient
test_emails = ['test@test.com', 'other@test.com', 'unused@test.com']
invalid_emails = ['invalid', None, object()]

# invalid values should raise exception
for email in invalid_emails:
with self.assertRaises(ValueError):
Rcp.get_or_create('email', email)
Recipient.get_or_create('email', email)

for email in test_emails:
Rcp.get_or_create('email', email)
from_db = set(r[0] for r in DB.session.query(Rcp.location).all())
Recipient.get_or_create('email', email)
from_db = {
r[0]
for r in DB.session.query(Recipient.location).filter(
Recipient.channel == 'email'
)
}
self.assertEqual(from_db, set(test_emails))

r = Resource.query.first()
r.set_recipients('email', test_emails[:2])

# unused email should be removed
self.assertEqual(set(r.get_recipients('email')), set(test_emails[:2]))
q = Rcp.query.filter(Rcp.location == test_emails[-1])
q = Recipient.query.filter(Recipient.location == test_emails[-1])
self.assertEqual(q.count(), 0)

def testWebhookNotifications(self):
Expand Down

0 comments on commit 48ff5f7

Please sign in to comment.