def test_read_all_notification(self): user = User.query.get(2) notification1 = Notification(message='test 1', receiver=user) notification2 = Notification(message='test 2', receiver=user) db.session.add_all([notification1, notification2]) db.session.commit() self.login() response = self.client.post(url_for('main.read_all_notification'), follow_redirects=True) data = response.get_data(as_text=True) self.assertIn('All notifications archived.', data) self.assertTrue(Notification.query.get(1).is_read) self.assertTrue(Notification.query.get(2).is_read)
def test_notifications_hook(self): sensor_value = SensorValue( sensor_id=1, value=56, timestamp=datetime.now().replace(tzinfo=utc)) sensor_value.save() threshold = Threshold(sensor_id=1) threshold.save() response = self.client.get('/api/notifications/') self.assertEqual(response.status_code, 200) data = json.loads(response.content) self.assertEqual(data['total'], 0) self.assertEqual(len(data['notifications']), 0) notification = Notification(threshold=threshold, sensor_value=sensor_value, target=50) notification.save() response = self.client.get('/api/notifications/') self.assertEqual(response.status_code, 200) data = json.loads(response.content) self.assertEqual(data['total'], 1) self.assertEqual(len(data['notifications']), 1) self.assertEqual(data['notifications'][0]['threshold']['id'], threshold.id)
def push_collect_notification(collector, photo_id, receiver): message = 'User <a href="%s">%s</a> collected your <a href="%s">photo</a>' % \ (url_for('user.index', username=collector.username), collector.username, url_for('main.show_photo', photo_id=photo_id)) notification = Notification(message=message, receiver=receiver) db.session.add(notification) db.session.commit()
def fake_admin(): admin = User(name='Grey Li', username='******', email='*****@*****.**', bio=fake.sentence(), website='http://greyli.com', confirmed=True) admin.set_password('helloflask') notification = Notification(message='Hello, welcome to TA.', receiver=admin) db.session.add(notification) db.session.add(admin) db.session.commit()
def test_read_notification(self): user = User.query.get(2) notification1 = Notification(message='test 1', receiver=user) notification2 = Notification(message='test 2', receiver=user) db.session.add_all([notification1, notification2]) db.session.commit() self.login(email='*****@*****.**', password='******') response = self.client.post( url_for('main.read_notification', notification_id=1)) self.assertEqual(response.status_code, 403) self.logout() self.login() response = self.client.post(url_for('main.read_notification', notification_id=1), follow_redirects=True) data = response.get_data(as_text=True) self.assertIn('Notification archived.', data) self.assertTrue(Notification.query.get(1).is_read)
def test_show_notifications(self): user = User.query.get(2) notification1 = Notification(message='test 1', is_read=True, receiver=user) notification2 = Notification(message='test 2', is_read=False, receiver=user) db.session.add_all([notification1, notification2]) db.session.commit() self.login() response = self.client.get(url_for('main.show_notifications')) data = response.get_data(as_text=True) self.assertIn('test 1', data) self.assertIn('test 2', data) response = self.client.get( url_for('main.show_notifications', filter='unread')) data = response.get_data(as_text=True) self.assertNotIn('test 1', data) self.assertIn('test 2', data)
def getNotification(self, title=None, date=None, insertOnBd=False): payload = {'format': 'json', 'title': title, 'date': date} r = requests.get(self.baseUrlAPI + 'notification/', params=payload) print r.status_code aux = r.json()['objects'] if len(aux) == 0: stderr.write('Notification with title: \"' + title + '\" and date: \"' + str(date) + '\" doesn\'t exist in SIOrg+Pub') return None print aux data = aux[0] a = Notification(title=data['title'], description=data['description'], date=data['date']) if insertOnBd: a.save() return a
def push_comment_notification(photo_id, receiver, page=1): message = '<a href="%s#comments">This photo</a> has new comment/reply.' % \ (url_for('main.show_photo', photo_id=photo_id, page=page)) notification = Notification(message=message, receiver=receiver) db.session.add(notification) db.session.commit()
def push_follow_notification(follower, receiver): message = 'User <a href="%s">%s</a> followed you.' % \ (url_for('user.index', username=follower.username), follower.username) notification = Notification(message=message, receiver=receiver) db.session.add(notification) db.session.commit()