def test_get_recent_friend_user_checkpoints(self): """ unit test for get_recent_friend_user_checkpoints() """ user_a = self.create_saved_test_user() user_b = self.create_saved_test_user_with_checkpoint() user_c = self.create_saved_test_user_with_checkpoint() user_d = self.create_saved_test_user_with_checkpoint() user_e = self.create_saved_test_user_with_checkpoint() self.befriend_test_user(user_a, [user_b, user_c, user_d]) recent_ucp = get_recent_friend_user_checkpoints(user_a.user_obj, 2) assert len(recent_ucp) == 2 recent_ucp = get_recent_friend_user_checkpoints(user_a.user_obj) for ucp in recent_ucp: assert user_e.user_checkpoint_obj.id != ucp.id
def get_checkpoint(): """ (GET: checkpoint) """ type = request.args.get("type") user_id = request.args.get("user_id") signature = request.args.get("signature") if not authorize("get", "checkpoint", user_id, signature): return authorization_fail() if type == "search": user_checkpoints = _search_checkpoints() return jsonify({"checkpoints": user_checkpoint_sanify(user_checkpoints), "status": "ok", }) elif type == "near": friends_ucp, anon_ucp, notifications = _checkpoints_near_me() recent_checkpoints = get_recent_friend_user_checkpoints(get_user(user_id)) lon = request.args.get("longitude") lat = request.args.get("latitude") dic = {"recent_checkpoints": [ucp.serialize for ucp in recent_checkpoints], "friends_checkpoints": user_checkpoint_sanify(friends_ucp), "anon_checkpoints": user_checkpoint_sanify(anon_ucp), "notifications": notification_sanify(notifications), "friends_proximity": checkpoint_proximity(friends_ucp, lat, lon), "anon_proximity": checkpoint_proximity(anon_ucp, lat, lon), "status": "ok", } return jsonify(dic) elif type == "mine": user_checkpoints = _my_checkpoints() dic = {"checkpoints": user_checkpoint_sanify(user_checkpoints), "status": "ok"} _build_proximity(user_checkpoints, dic) return jsonify(dic) else: #single checkpoint info res = _checkpoint_details() return jsonify({ "total_likes": res.total_likes, "total_shares": res.total_shares, "current_user_like": res.current_user_like, "comments": comment_sanify(res.comments), "user": res.user, "checkpoint": res.user_checkpoint_obj.serialize, "status": "ok", })