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 push_follow_notification(follower, receiver): """ 推送关注提醒 :param follower: :param receiver: :return: """ 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()
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 fake_admin(): admin = User(name='bowen', username='******', email='*****@*****.**', bio=fake.sentence(), website='http://ybw-zw.top', confirmed=True) admin.set_password('12345678') notification = Notification(message='Hello, welcome to Albumy.', receiver=admin) db.session.add(notification) db.session.add(admin) db.session.commit()
def push_comment_notification(photo_id, receiver, page=1): """ 推送评论提醒 :param photo_id: :param receiver: :param page: :return: """ 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_collect_notification(collector, photo_id, receiver): """ 推送收藏提醒 :param collector: :param photo_id: :param receiver: :return: """ 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()