Skip to content

Commit 48ff5f7

Browse files
author
Henry Walshaw
committed
Fix up the Recipient query
Makes sure we're not accidentally doubling up somewhere
1 parent cfeba33 commit 48ff5f7

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

tests/test_resources.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
from resourceauth import ResourceAuth
4343
import result
4444

45+
4546
TEST_DIR = os.path.dirname(os.path.abspath(__file__))
4647

4748

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

9798
def testNotificationsApi(self):
98-
Rcp = Recipient
9999
100100
invalid_emails = ['invalid', None, object()]
101101

102102
# invalid values should raise exception
103103
for email in invalid_emails:
104104
with self.assertRaises(ValueError):
105-
Rcp.get_or_create('email', email)
105+
Recipient.get_or_create('email', email)
106106

107107
for email in test_emails:
108-
Rcp.get_or_create('email', email)
109-
from_db = set(r[0] for r in DB.session.query(Rcp.location).all())
108+
Recipient.get_or_create('email', email)
109+
from_db = {
110+
r[0]
111+
for r in DB.session.query(Recipient.location).filter(
112+
Recipient.channel == 'email'
113+
)
114+
}
110115
self.assertEqual(from_db, set(test_emails))
111116

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

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

120125
def testWebhookNotifications(self):

0 commit comments

Comments
 (0)