def test_notify(self): data = {'query': 'Kashmir'} failed_alert = Alert.create(data, self.role_no_email.id) failed_alert.notified_at = datetime.utcnow() - timedelta(hours=72) alert = Alert.create(data, self.role_email.id) alert.notified_at = datetime.utcnow() + timedelta(hours=72) db.session.commit() res = get_notifications(self.role_email) notcount = res.get('hits').get('total').get('value') assert notcount == 0, notcount db.session.refresh(alert) alert.notified_at = datetime.utcnow() - timedelta(hours=72) db.session.add(alert) db.session.commit() check_alerts() res = get_notifications(self.role_email) notcount = res.get('hits').get('total').get('value') assert notcount == 1, res.get('hits') check_alerts() res = get_notifications(self.role_email) notcount = res.get('hits').get('total').get('value') assert notcount == 1, res.get('hits')
def index(): """ --- get: summary: Get notifications description: Get all the notifications for the user responses: '200': content: application/json: schema: type: object allOf: - $ref: '#/components/schemas/QueryResponse' properties: results: type: array items: $ref: '#/components/schemas/Notification' description: OK tags: - Notification """ require(request.authz.logged_in) role = Role.by_id(request.authz.id) parser = SearchQueryParser(request.args, request.authz) result = get_notifications(role, parser=parser) result = SearchQueryResult(request, parser, result) return NotificationSerializer.jsonify_result(result)
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_create(self): assert self.export1.content_hash is not None assert self.export1.content_hash == self.export2.content_hash assert archive.load_file(self.export1.content_hash) is not None assert archive.load_file( self.export1.content_hash) == archive.load_file( self.export2.content_hash) assert self.export1.file_name == self.export2.file_name == "experts.csv" res = get_notifications(self.role_email) notification_count = res.get("hits").get("total").get("value") assert notification_count == 3, notification_count