def test_get_nearby_checkpoints(self): """ unit tests get_nearby_checkpoints """ #group a a_user1 = self.create_saved_test_user() a_user2 = self.create_saved_test_user() self.befriend_test_user(a_user1, [a_user2]) #anon users anon_user1 = self.create_saved_test_user() #create checkpoints in group a checkpoint_a_data = CheckpointTests.mock_checkpoint_data(a_user1.user_obj.id, (999.9, 999.9)) a1_checkpoint = add_checkpoint(*checkpoint_a_data) a1_ucp = add_checkpoint_to_user(a_user1.user_obj, a1_checkpoint) checkpoint_b_data = CheckpointTests.mock_checkpoint_data(a_user2.user_obj.id, (-999.9, -999.9)) a2_checkpoint = add_checkpoint(*checkpoint_b_data) a2_ucp = add_checkpoint_to_user(a_user2.user_obj, a2_checkpoint) checkpoint_c_data = CheckpointTests.mock_checkpoint_data(anon_user1.user_obj.id, (999.9, 999.9)) a3_checkpoint = add_checkpoint(*checkpoint_c_data) a3_ucp = add_checkpoint_to_user(anon_user1.user_obj, a3_checkpoint) #verification friends_ucp, anon_ucp = get_nearby_checkpoints(a_user1.user_obj, (999.9, 999.9), 0.1) assert a1_ucp in friends_ucp assert not a2_ucp in friends_ucp assert a3_ucp in anon_ucp
def test_get_checkpoint_near(self): """ test the nearby-checkpoints functionality of (get:checkpoint) api """ # group a a_user1 = self.create_saved_test_user() a_user2 = self.create_saved_test_user() self.befriend_test_user(a_user1, [a_user2]) # anon users anon_user1 = self.create_saved_test_user() # create checkpoints in group a checkpoint_a_data = CheckpointTests.mock_checkpoint_data(a_user1.user_obj.id, (999.9, 999.9)) a1_checkpoint = add_checkpoint(*checkpoint_a_data) a1_ucp = add_checkpoint_to_user(a_user1.user_obj, a1_checkpoint) checkpoint_b_data = CheckpointTests.mock_checkpoint_data(a_user2.user_obj.id, (-999.9, -999.9)) a2_checkpoint = add_checkpoint(*checkpoint_b_data) a2_ucp = add_checkpoint_to_user(a_user2.user_obj, a2_checkpoint) checkpoint_c_data = CheckpointTests.mock_checkpoint_data(anon_user1.user_obj.id, (999.9, 999.9)) a3_checkpoint = add_checkpoint(*checkpoint_c_data) a3_ucp = add_checkpoint_to_user(anon_user1.user_obj, a3_checkpoint) # build data data = { "user_id": a_user1.user_obj.id, "signature": gen_signature( "get", "checkpoint", gen_api_key(a_user1.user_obj.access_token, a_user1.user_obj.id) ), "type": "near", "latitude": 999.9, "longitude": 999.9, "radius": 0.1, } response = self.client.get("/checkpoint/?" + urllib.urlencode(data)) json_response = simplejson.loads(response.data) assert json_response["status"] == "ok" # in friend_ucp assert a1_ucp.checkpoint.name in simplejson.dumps((json_response["friends_checkpoints"])) assert not a2_ucp.checkpoint.name in simplejson.dumps((json_response["friends_checkpoints"])) assert not a3_ucp.checkpoint.name in simplejson.dumps((json_response["friends_checkpoints"])) # in recent activity assert a2_ucp.checkpoint.name in simplejson.dumps(json_response["recent_checkpoints"]) # in anon ucp assert a3_ucp.checkpoint.name in simplejson.dumps(json_response["anon_checkpoints"]) assert not a2_ucp.checkpoint.name in simplejson.dumps(json_response["anon_checkpoints"]) assert not a1_ucp.checkpoint.name in simplejson.dumps(json_response["anon_checkpoints"])
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 create_saved_test_user_with_checkpoint(self): """ Creates a test user, user1_idwith a checkpoint """ from tests.action.test_checkpoint import CheckpointTests from action.checkpoint import add_checkpoint from action.user_checkpoint import add_checkpoint_to_user user = self.create_saved_test_user() #create user checkpoint mock_cp_data = CheckpointTests.mock_checkpoint_data(user.user_obj.id) checkpoint = add_checkpoint(*mock_cp_data) user_checkpoint = add_checkpoint_to_user(user.user_obj, checkpoint) return self.User(user.authcode, user.fb_test_user, user.fb_info, user.user_obj, checkpoint, user_checkpoint)
def test_share(self): """ Tests the share function in the share layer if it does work as expected """ #create and save facebook (test) user_a and user_b test_user_a = self.create_facebook_test_user() test_user_b = self.create_facebook_test_user() fb_user_info_a, user_a = save_user(test_user_a["access_token"], "someauthcode") fb_user_info_b, user_b = save_user(test_user_b["access_token"], "someauthcode") make_friend_connection(user_a.facebook_user.id, user_b.facebook_user.id, user_a.access_token, user_b.access_token) #create mock checkpoint and add it to user_a checkpoint = add_checkpoint(*CheckpointTests.mock_checkpoint_data(user_a.id)) user_checkpoint = add_checkpoint_to_user(user_a, checkpoint) #share checkpoint from user_a to user_b share(user_a, user_b, user_checkpoint) #assert print test_user_a