コード例 #1
0
 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
コード例 #2
0
    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"])
コード例 #3
0
 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
コード例 #4
0
ファイル: demo.py プロジェクト: nubela/spawt-backend
def _add_cp(user_obj, name, desc, img_path, type, img_file_name, price=None, expiry=None):
    from util.fileupload import save_to_s3
    from ctrleff import get_resources_abs_path
    from action.checkpoint import add_checkpoint
    
    creator_id = user_obj.id
    longitude, latitude = 103.8, 1.3667
    
    checkpoint = add_checkpoint(creator_id, name, type, img_file_name, longitude, latitude, desc, price=price, expiry=expiry, demo=True, img_location="s3")
    return checkpoint
コード例 #5
0
    def test_add_checkpoint(self):
        """
        Tests the add_checkpoint() functionality by creating a mock checkpoint and saving
        it to a mock user
        """
        #create test user
        test_fb_user = self.create_facebook_test_user()
        fb_user, user = save_user(test_fb_user["access_token"], "someauthcode")
        
        #create mock checkpoint
        mock_cp_data = CheckpointTests.mock_checkpoint_data(user.id)
        checkpoint = add_checkpoint(*mock_cp_data)

        #asserts
        assert not get_checkpoint(checkpoint.id) is None
コード例 #6
0
ファイル: test_base.py プロジェクト: nubela/spawt-backend
 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)
コード例 #7
0
ファイル: test_share.py プロジェクト: nubela/spawt-backend
 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
コード例 #8
0
ファイル: checkpoint.py プロジェクト: nubela/spawt-backend
def new_checkpoint():
    """
    (PUT: checkpoint) *requires authorization
    creates a barebone checkpoint (just location and image)
    this checkpoint is not complete yet.
    """
    
    #req vars
    user_id = request.form.get("user_id")
    signature = request.form.get("signature")
    name = request.form.get("name")
    longitude = request.form.get("longitude")
    latitude = request.form.get("latitude")
    description = request.form.get("description", None)
    price = request.form.get("price", None)
    expiry = request.form.get("expiry", None)
    image_encoded = request.form.get("image", None)
    type = request.form.get("type")
    share = request.form.get("share", None)
    facebook_post = request.form.get("facebook_post", False)
    image = None
    if image_encoded is None:
        image = request.files["image"]
    
    #generated vars
    verb = "put"
    noun = "checkpoint"
    user = get_user(user_id)
    expiry_datetime = None
    if expiry:
        expiry_datetime = unserialize_json_datetime(expiry)
    
    if not authorize(verb, noun, user_id, signature):
        print "fail"
        return authorization_fail()
    
    #save image
    from util.fileupload import save_to_s3
    tmp_folder = get_resources_abs_path()
    
    if image_encoded is None:
        img_file_name = save_to_s3(user_id, image, tmp_folder, encoded=False)
    else:
        img_file_name = save_to_s3(user_id, image_encoded, tmp_folder) 
    
    checkpoint = add_checkpoint(user_id, name, type, img_file_name, longitude, latitude, description, price, expiry_datetime, img_location="s3")
    user_checkpoint  = add_checkpoint_to_user(user, checkpoint)
    
    #dispatch shares
    if not share is None:
        user_ids_to_share = simplejson.loads(share)
        for uid in user_ids_to_share:
            user_to = get_user(uid)
            share_checkpoint(user, user_to, user_checkpoint)
    
    #return success
    return jsonify({
                    "status": "ok",
                    "result": {
                               "user_checkpoint_id": user_checkpoint.id,
                               },
                    })