def test_notify(self): data = {'query_text': '', 'label': 'Test Alert'} alert = Alert.create(data, self.role_email) alert.notified_at = datetime.utcnow() + timedelta(hours=72) db.session.commit() with mail.record_messages() as outbox: check_alerts() assert len(outbox) == 0, outbox db.session.refresh(alert) alert.notified_at = datetime.utcnow() - timedelta(hours=72) db.session.add(alert) db.session.commit() with mail.record_messages() as outbox: check_alerts() assert len(outbox) == 1, outbox msg = outbox[0] assert 'Test Alert' in msg.subject, msg assert '*****@*****.**' in msg.recipients, msg with mail.record_messages() as outbox: check_alerts() assert len(outbox) == 0, outbox
def test_publish_event(self): role = self.create_user() email = '*****@*****.**' label = 'So public' recipient = self.create_user(foreign_id='rolex', email=email) update_role(recipient) collection = self.create_collection(foreign_id='NoNoNo', label=label) event = Events.PUBLISH_COLLECTION publish(event, role.id, params={'collection': collection}, channels=[Notification.GLOBAL]) db.session.commit() notifications = Notification.all().all() assert 1 == len(notifications), notifications not0 = notifications[0] assert not0._event == event.name, not0._event assert not0.params['collection'] == collection.id, not0.params with mail.record_messages() as outbox: assert len(outbox) == 0, outbox generate_digest() assert len(outbox) == 1, outbox msg = outbox[0] assert email in msg.recipients, msg.recipients assert label in msg.html, msg.html
def test_code_has_email(self): email = self.fake.email() with mail.record_messages() as outbox: res = self.client.post("/api/2/roles/code", data=dict(email=email)) assert res.status_code == 200, res assert len(outbox) == 1, outbox assert email in outbox[0].recipients, outbox[0]
def test_publish_event(self): role = self.create_user() email = '*****@*****.**' label = 'So public' recipient = self.create_user(foreign_id='rolex', email=email) update_role(recipient) collection = self.create_collection(foreign_id='NoNoNo', label=label) event = Events.PUBLISH_COLLECTION publish(event, role.id, params={'collection': collection}, channels=[GLOBAL]) db.session.commit() result = get_notifications(recipient) notifications = result.get('hits', {}) assert 1 == notifications['total']['value'], notifications not0 = notifications['hits'][0]['_source'] assert not0['event'] == event.name, not0['event'] assert not0['params']['collection'] == str( collection.id), not0['params'] # noqa with mail.record_messages() as outbox: assert len(outbox) == 0, outbox generate_digest() assert len(outbox) == 1, outbox msg = outbox[0] assert email in msg.recipients, msg.recipients assert label in msg.html, msg.html
def test_publish_event(self): role = self.create_user() email = "*****@*****.**" label = "So public" recipient = self.create_user(foreign_id="rolex", email=email) update_role(recipient) collection = self.create_collection(foreign_id="NoNoNo", label=label) event = Events.PUBLISH_COLLECTION publish(event, role.id, params={"collection": collection}, channels=[GLOBAL]) db.session.commit() result = get_notifications(recipient) notifications = result.get("hits", {}) assert 1 == notifications["total"]["value"], notifications not0 = notifications["hits"][0]["_source"] assert not0["event"] == event.name, not0["event"] params = not0["params"] assert params["collection"] == str(collection.id), params with mail.record_messages() as outbox: assert len(outbox) == 0, outbox generate_digest() assert len(outbox) == 1, outbox msg = outbox[0] assert email in msg.recipients, msg.recipients assert label in msg.html, msg.html
def test_publish_event(self): role = self.create_user() email = '*****@*****.**' label = 'So public' recipient = self.create_user(foreign_id='rolex', email=email) update_role(recipient) collection = self.create_collection(foreign_id='NoNoNo', label=label) event = Events.PUBLISH_COLLECTION publish(event, role.id, params={'collection': collection}, channels=[Notification.GLOBAL]) db.session.commit() notifications = Notification.all().all() assert 1 == len(notifications), notifications not0 = notifications[0] assert not0._event == event.name, not0._event assert not0.params['collection'] == str(collection.id), not0.params with mail.record_messages() as outbox: assert len(outbox) == 0, outbox generate_digest() assert len(outbox) == 1, outbox msg = outbox[0] assert email in msg.recipients, msg.recipients assert label in msg.html, msg.html
def test_notify_no_email(self): data = {'query': {}, 'custom_label': 'Test Alert'} assert self.role_no_email.email is None, self.role_no_email.email alert = Alert.create(data, self.role_no_email) alert.notified_at = datetime.utcnow() - timedelta(hours=72) db.session.commit() with mail.record_messages() as outbox: check_alerts() assert len(outbox) == 0, outbox
def test_code_has_email(self): email = self.fake.email() with mail.record_messages() as outbox: res = self.client.post( '/api/2/roles/code', data=dict(email=email) ) assert res.status_code == 200, res assert len(outbox) == 1, outbox assert email in outbox[0].recipients, outbox[0]
def test_code_when_no_email(self): with mail.record_messages() as outbox: res = self.client.post("/api/2/roles/code") assert res.status_code == 400, res assert len(outbox) == 0, outbox
def test_code_when_no_email(self): with mail.record_messages() as outbox: res = self.client.post('/api/2/roles/code') assert res.status_code == 400, res assert len(outbox) == 0, outbox