Пример #1
0
 def test_delete_ad(self):
     """
     Tests the API call to create an ad, then to delete it.        
     """
     data = {
             "long": randint(-360000000,360000000),
             "lat": randint(-360000000,360000000),
             "category": 5,
             "email": "*****@*****.**",
             "title": "Test Item " + random_string(),
             "price": str(randint(0,1000)),
             "image": open_file("sample_upload_pic.jpg"),
             "description": " ".join([random_string() for i in range(10)]),
             }
     
     #create it
     create_response  = self.app.post("/ad/create", data=data)
     response_dict = json.loads(create_response.data)
     ad_id = response_dict["res"]
     
     res = self.app.post("/ad/get", data={"id": ad_id})
     assert "id" in res.data
     
     self.app.post("/ad/delete", data={"id": ad_id})
     
     res = self.app.post("/ad/get", data={"id": ad_id})
     assert not "id" in res.data
Пример #2
0
    def test_new_invalid_checkpoint(self):
        """
        test the new_checkpoint API, with an invalid checkpoint (without expiry/price)
        """

        # create/save user
        authcode = "someauthcode"
        test_user = self.create_facebook_test_user()
        fb_info, user = save_user(test_user["access_token"], authcode)

        # prep image file
        image_path = join(get_resources_abs_path(), "test/images/timbre.jpg")
        image_file = open(image_path, "r")
        image = base64.encodestring(image_file.read())

        # craft request params
        data = {
            "user_id": user.id,
            "signature": gen_signature("put", "checkpoint", gen_api_key(user.access_token, user.id)),
            "name": random_string(),
            "longitude": 2.0,
            "latitude": 1.0,
            "description": random_string(),
            "image": image,
            "type:": "play",
        }

        # send it
        response = self.client.put("/checkpoint/", data=data)
        assert "Requires at least a price or expiry." in response.data
Пример #3
0
 def mock_checkpoint_data(creator_user_id, point_coord = (2.0, 3.0)):
     name = random_string()
     desc = random_string()
     price = 1.0
     expiry = datetime.datetime.now()
     type = "play"
     image = "bla_image"
     return (creator_user_id, name, type, image, point_coord[1], point_coord[0], desc, price, expiry)    
Пример #4
0
 def create_saved_test_user(self):
     from action.user import save_user
     
     #create and save fb user
     authcode = random_string()
     test_user = self.create_facebook_test_user()
     fb_info, user = save_user(test_user["access_token"], authcode)
     
     return self.User(authcode, test_user, fb_info, user, None, None)
Пример #5
0
def mock_ads():
    all_cat = Category.query.all() 
    for i in range(100):
        posn = GPSPosition(randint(-360000000,360000000), randint(-360000000,360000000))
        rand_cat = all_cat[randint(0, len(all_cat)-1)]
        location = Location(
                            longitude=posn.longitude,
                            latitude=posn.latitude
                            )
        Ad.create(location, "*****@*****.**", "Random Mock App" + random_string(), str(randint(0,1000)), "sample_upload_pic.jpg", rand_cat," ".join([random_string() for i in range(10)]))
    db.session.commit()
Пример #6
0
    def test_my_ads_list(self):
        """
        """
        random_email = random_string() 
        data = {
                "long": randint(-360000000,360000000),
                "lat": randint(-360000000,360000000),
                "category": 5,
                "email": random_email,
                "title": "Test Item " + random_string(),
                "price": str(randint(0,1000)),
                "image": open_file("sample_upload_pic.jpg"),
                "description": " ".join([random_string() for i in range(10)]),
                }
             
        res = self.app.post("/ad/create", data=data)
        
        #ensure there are at least some ads
        assert not "False" in res.data
        
        #now ensure that all the ads are of that category
        self.app.post("/ad/create", data=data)
        
        data = {
                "long": randint(-360000000,360000000),
                "lat": randint(-360000000,360000000),
                "total": 25,
                "type": "my_ad",
                "email": random_email,
                }

        res = self.app.post("/ad/list", data=data)
        
        #ensure there are at least some ads
        assert not "False" in res.data
        
        response_dict = json.loads(res.data)
        for ad in response_dict["ads"]:
            assert ad["contact_email"] == random_email
Пример #7
0
 def test_ad_creation(self):
     """
     Tests the API to create ads. Conveniently, also tests get ad api call.
     """
     data = {
             "long": randint(-360000000,360000000),
             "lat": randint(-360000000,360000000),
             "category": 5,
             "email": "*****@*****.**",
             "title": "Test Item " + random_string(),
             "price": str(randint(0,1000)),
             "image": open_file("sample_upload_pic.jpg"),
             "description": " ".join([random_string() for i in range(10)]),
             }
     
     #create it
     create_response  = self.app.post("/ad/create", data=data)
     response_dict = json.loads(create_response.data)
     ad_id = response_dict["res"]
     
     #retrieve it
     res = self.app.post("/ad/get", data={"id": ad_id})
     assert "id" in res.data
Пример #8
0
    def test_new_comment(self):
        """
        Unit Test API for instantiating a new Comment (comment/put)
        """
        test_user_with_checkpoint = self.create_saved_test_user_with_checkpoint()
        annoying_user_that_likes_everything = self.create_saved_test_user()

        # prep api call
        data = {
            "user_id": annoying_user_that_likes_everything.user_obj.id,
            "signature": gen_signature(
                "put",
                "comment",
                gen_api_key(
                    annoying_user_that_likes_everything.user_obj.access_token,
                    annoying_user_that_likes_everything.user_obj.id,
                ),
            ),
            "user_checkpoint_id": test_user_with_checkpoint.user_checkpoint_obj.id,
            "comment": random_string(),
        }

        resp = self.client.put("/comment/", data=data)
        assert "comment_id" in resp.data