def test_get_stats(self): user = self.create_saved_test_user_with_checkpoint() other_user = self.create_saved_test_user() add_like(other_user.user_obj, user.user_checkpoint_obj) add_share(other_user.user_obj, user.user_obj, user.user_checkpoint_obj) data = {"user_id": user.user_obj.id, "signature": gen_signature("get", "stats", gen_api_key(user.user_obj.access_token, user.user_obj.id))} resp = self.client.get("/user/stats/?" + urllib.urlencode(data)) json_res = simplejson.loads(resp.data) assert json_res["total_likes"] == 1 assert json_res["total_reshares"] == 1
def new_like(): """ (PUT: like) Instantiates a new <<CheckpointLike>> from a user on a <<UserCheckpoint>> """ #req var user_id = request.form.get("user_id") signature = request.form.get("signature") user_checkpoint_id = request.form.get("user_checkpoint_id") #generated var verb = "put" noun = "like" user = get_user(user_id) user_checkpoint = get_user_checkpoint(user_checkpoint_id) access_token = user.access_token #authorization check if not is_api_key_validated(access_token, user_id, signature, verb, noun): return authorization_fail() like = add_like(user, user_checkpoint) return jsonify({ "status": "ok", "result": { "like_id": like.id, } })
def test_sort_checkpoints(self): """ tests sort_checkpoints() method """ user = self.create_saved_test_user() liker = self.create_saved_test_user() demo_cp = get_my_checkpoints(user.user_obj) #create various checkpoints (mocked data) for sorting cp_a_data = CheckpointTests.mock_checkpoint_data(user.user_obj.id, (0.0,0.0)) cp_b_data = CheckpointTests.mock_checkpoint_data(user.user_obj.id, (1.0,1.0)) cp_c_data = CheckpointTests.mock_checkpoint_data(user.user_obj.id, (2.0,2.0)) #create them cp_a = add_checkpoint(*cp_a_data) time.sleep(1) #have to sleep since datetime doesnt seem to register millisecond differences cp_b = add_checkpoint(*cp_b_data) time.sleep(1) cp_c = add_checkpoint(*cp_c_data) ucp_a = add_checkpoint_to_user(user.user_obj, cp_a) ucp_b = add_checkpoint_to_user(user.user_obj, cp_b) ucp_c = add_checkpoint_to_user(user.user_obj, cp_c) #get all ucp ucp_lis = get_my_checkpoints(user.user_obj) assert len(ucp_lis) == 3 + len(demo_cp) #like checkpoints add_like(liker.user_obj, ucp_b) #sort nearest nearest_ucp = sort_checkpoints(ucp_lis, "nearest", longitude = 0.0, latitude = 0.0) assert nearest_ucp[0].id == ucp_a.id assert nearest_ucp[1].id == ucp_b.id assert nearest_ucp[2].id == ucp_c.id #sort newest newest_ucp = sort_checkpoints(ucp_lis, "newest") assert newest_ucp[0].id == ucp_c.id assert newest_ucp[1].id == ucp_b.id assert newest_ucp[2].id == ucp_a.id #sort popularity popular_ucp = sort_checkpoints(ucp_lis, "popular") assert popular_ucp[0].id == ucp_b.id
def test_get_checkpoint_details(self): """ tests checkpoint detail api """ user_a = self.create_saved_test_user_with_checkpoint() user_b = self.create_saved_test_user() add_like(user_a.user_obj, user_a.user_checkpoint_obj) data = { "user_id": user_a.user_obj.id, "signature": gen_signature( "get", "checkpoint", gen_api_key(user_a.user_obj.access_token, user_a.user_obj.id) ), "user_checkpoint_id": user_a.user_checkpoint_obj.id, } response = self.client.get("/checkpoint/?" + urllib.urlencode(data)) json_res = simplejson.loads(response.data) assert json_res["current_user_like"] == True assert json_res["status"] == "ok"