def follow(user_id): user = get_requested_record(User, user_id) current_user = User.get(request.user_id) Follower.follow(current_user, user) create_follower_notification(user, current_user) db.session.commit() return jsonify()
def follow(user_id): user = get_requested_record(User, user_id) current_user = User.get(request.user_id) Follower.follow(current_user, user) create_follower_notification(user, current_user) db.session.commit() return jsonify()
def test_clear_all(db_session, client): john = users.john() jane = users.jane() max = users.max() create_follower_notification(john, jane) create_follower_notification(john, max) create_follower_notification(jane, max) db_session.commit() res = client.post('/notifications/clear', headers=auth_for(john)) assert res.status_code == 200 assert res.json == {} johns_notifications = db_session.query(Notification).filter_by( recipient=john).all() assert len(johns_notifications) == 2 assert johns_notifications[0].event.actor_id == jane.id assert johns_notifications[0].time_read is not None assert johns_notifications[1].event.actor_id == max.id assert johns_notifications[1].time_read is not None janes_notifications = db_session.query(Notification).filter_by( recipient=jane).all() assert len(janes_notifications) == 1 assert janes_notifications[0].event.actor_id == max.id assert janes_notifications[0].time_read is None
def test_clear_all(db_session, client): john = users.john() jane = users.jane() max = users.max() create_follower_notification(john, jane) create_follower_notification(john, max) create_follower_notification(jane, max) db_session.commit() res = client.post("/notifications/clear", headers=auth_for(john)) assert res.status_code == 200 assert res.json == {} johns_notifications = db_session.query(Notification).filter_by(recipient=john).all() assert len(johns_notifications) == 2 assert johns_notifications[0].event.actor_id == jane.id assert johns_notifications[0].time_read is not None assert johns_notifications[1].event.actor_id == max.id assert johns_notifications[1].time_read is not None janes_notifications = db_session.query(Notification).filter_by(recipient=jane).all() assert len(janes_notifications) == 1 assert janes_notifications[0].event.actor_id == max.id assert janes_notifications[0].time_read is None
def test_list_all(db_session, client): john = users.john() jane = users.jane() max = users.max() create_follower_notification(john, jane) create_follower_notification(john, max) create_follower_notification(jane, max) db_session.commit() res = client.get("/notifications", headers=auth_for(john)) assert res.status_code == 200 assert res.json == S({ u"events": ExactSequence([ { u"actor": { u"id": int, u"name": u"Max Mustermann" }, u"id": int, u"time": Datetime("%Y-%m-%dT%H:%M:%S.%f+00:00"), u"type": u"follower", u"unread": True, u"user": { u"id": int, u"name": u"John Doe" }, }, { u"actor": { u"id": int, u"name": u"Jane Doe" }, u"id": int, u"time": Datetime("%Y-%m-%dT%H:%M:%S.%f+00:00"), u"type": u"follower", u"unread": True, u"user": { u"id": int, u"name": u"John Doe" }, }, ]) })
def test_list_all(db_session, client): john = users.john() jane = users.jane() max = users.max() create_follower_notification(john, jane) create_follower_notification(john, max) create_follower_notification(jane, max) db_session.commit() res = client.get("/notifications", headers=auth_for(john)) assert res.status_code == 200 assert res.json == S( { u"events": ExactSequence( [ { u"actor": {u"id": int, u"name": u"Max Mustermann"}, u"id": int, u"time": Datetime("%Y-%m-%dT%H:%M:%S.%f+00:00"), u"type": u"follower", u"unread": True, u"user": {u"id": int, u"name": u"John Doe"}, }, { u"actor": {u"id": int, u"name": u"Jane Doe"}, u"id": int, u"time": Datetime("%Y-%m-%dT%H:%M:%S.%f+00:00"), u"type": u"follower", u"unread": True, u"user": {u"id": int, u"name": u"John Doe"}, }, ] ) } )
def follow(self): Follower.follow(request.identity['user'], self.user) create_follower_notification(self.user, request.identity['user']) redirect('.')