示例#1
0
    def create(self, request):
        if (Rank.URL_TAG in request.POST) and (ApiDataProvider.MEDIA_ID
                                               in request.POST):
            myRank = None
            myMid = None

            # check input is integer
            try:
                myRank = int(request.POST[Rank.URL_TAG])
                myMid = int(request.POST[ApiDataProvider.MEDIA_ID])
            except Exception:
                return ApiDataProvider.returnError(RankHandler._TAG +
                                                   'bad input')

                # check if input is within bounds
            if not (myRank in Rank.RANK_TYPES):
                return ApiDataProvider.returnError(RankHandler._TAG +
                                                   'input out of bounds')

            # save guard
            #try:
            return ApiDataProvider.rateContent(myMid, myRank)
            #except Exception:
            #return ApiDataProvider.returnError('unexpected error')
        else:
            return ApiDataProvider.returnError(RankHandler._TAG +
                                               'bad request')
示例#2
0
 def test_rateContent_normalsituation_up_twice(self):
     json_str = ApiDataProvider.rateContent(self.m1.id, Rank.THUMBS_UP)
     self.assertTrue(ApiDataProvider.STATUS_SUCCESS in json_str)
     json_str = ApiDataProvider.rateContent(self.m1.id, Rank.THUMBS_UP)
     self.assertTrue(ApiDataProvider.STATUS_SUCCESS in json_str)
      
     content0 = Rank.objects.get(media = self.m1)
     self.assertEqual(2, content0.thumbs_up)
     self.assertEqual(0, content0.thumbs_down)
 def update(self, request):
     print request.POST
     if ('uid' in request.POST & 'mid' in request.POST):
         try: 
             user_id = int(request.GET['uid'])
             media_id = int(request.GET['mid'])
             return ApiDataProvider.addFavorite(user_id, media_id)
         except Exception:
             return ApiDataProvider.returnError('bad input')
     else:
         return ApiDataProvider.returnError('bad request')
示例#4
0
 def update(self, request):
     print request.POST
     if ('uid' in request.POST & 'mid' in request.POST):
         try:
             user_id = int(request.GET['uid'])
             media_id = int(request.GET['mid'])
             return ApiDataProvider.addFavorite(user_id, media_id)
         except Exception:
             return ApiDataProvider.returnError('bad input')
     else:
         return ApiDataProvider.returnError('bad request')
 def read(self, request):
     print request.GET
     if ('uid' in request.GET):
         user_id = NONE;
         
         # check if input is integer
         try:
             user_id = int(request.GET["uid"])
             return ApiDataProvider.getFavorites(user_id)
         except Exception:
             return ApiDataProvider.returnError('bad input')
     else :
         return ApiDataProvider.returnError('bad request')
示例#6
0
    def read(self, request):
        print request.GET
        if ('uid' in request.GET):
            user_id = NONE

            # check if input is integer
            try:
                user_id = int(request.GET["uid"])
                return ApiDataProvider.getFavorites(user_id)
            except Exception:
                return ApiDataProvider.returnError('bad input')
        else:
            return ApiDataProvider.returnError('bad request')
 def create(self, request):
     # check if post has secret parameter
     if not(DataNames.SECRET in request.POST) :
         return ApiDataProvider.returnError('no ' + DataNames.SECRET)
     
     # check if secret parameter is correct
     the_secret = request.POST[DataNames.SECRET]
     if the_secret != ApiKeys.GAE_PRIVATE_KEY:
         return ApiDataProvider.returnError('incorrect private key')
     
     try:
         ContentDataOrganizer.clearPhotoDatabase()
         return ApiDataProvider.returnSuccess('cleared database')
     except Exception:
         return ApiDataProvider.returnError('unexpected error')
    def create(self, request):
        # check if post has secret parameter
        if not (DataNames.SECRET in request.POST):
            return ApiDataProvider.returnError("no " + DataNames.SECRET)

        # check if secret parameter is correct
        the_secret = request.POST[DataNames.SECRET]
        if the_secret != ApiKeys.GAE_PRIVATE_KEY:
            return ApiDataProvider.returnError("incorrect private key")

        try:
            ContentDataOrganizer.clearPhotoDatabase()
            return ApiDataProvider.returnSuccess("cleared database")
        except Exception:
            return ApiDataProvider.returnError("unexpected error")
    def read(self, request):
        if (Media.URL_TAG in request.GET) and (Mood.URL_TAG in request.GET):
            # check if input is string
            myMood = request.GET[Mood.URL_TAG]
            myContent = request.GET[Media.URL_TAG]

            if not (myMood in Mood.MOOD_TYPES):
                return ApiDataProvider.returnError(ContentHandler._TAG +
                                                   'bad mood input')

            if not (myContent in Media.CONTENT_TYPES):
                return ApiDataProvider.returnError(ContentHandler._TAG +
                                                   'bad content input')

            # check if input is within bounds
            if not ((myMood in Mood.MOOD_TYPES) and
                    (myContent in Media.CONTENT_TYPES)):
                return ApiDataProvider.returnError(ContentHandler._TAG +
                                                   'input out of bounds')

            # save guard
            try:
                return ApiDataProvider.getContent(myMood, myContent)
            except Exception:
                return ApiDataProvider.returnError(ContentHandler._TAG +
                                                   'unexpected error')
        else:
            return ApiDataProvider.returnError(ContentHandler._TAG +
                                               'bad request')
 def create(self, request):
     if (Rank.URL_TAG in request.POST) and (ApiDataProvider.MEDIA_ID in request.POST):
         myRank = None
         myMid = None
         
         # check input is integer
         try:
             myRank = int(request.POST[Rank.URL_TAG ])
             myMid = int(request.POST[ApiDataProvider.MEDIA_ID])
         except Exception:
             return ApiDataProvider.returnError(RankHandler._TAG + 'bad input')
         
                     # check if input is within bounds
         if not(myRank in Rank.RANK_TYPES):
             return ApiDataProvider.returnError(RankHandler._TAG + 'input out of bounds')
         
         # save guard
         #try:
         return ApiDataProvider.rateContent(myMid, myRank)
         #except Exception:
             #return ApiDataProvider.returnError('unexpected error')
     else :
         return ApiDataProvider.returnError(RankHandler._TAG + 'bad request')
 def create(self, request):
     print request.POST
     # check if post has secret parameter
     if not(DataNames.SECRET in request.POST) :
         return ApiDataProvider.returnError(PictureCrawlingHandler._TAG + \
                                            'no ' + DataNames.SECRET)
     
     # check if secret parameter is correct
     the_secret = request.POST[DataNames.SECRET]
     if the_secret != ApiKeys.GAE_PRIVATE_KEY:
         return ApiDataProvider.returnError(PictureCrawlingHandler._TAG + \
                                            'incorrect private key')
     
     # Parameter short circuits
     if not(Mood.URL_TAG in request.POST):
         return ApiDataProvider.returnError('no mood param')
     
     # Parameter short circuits
     if not(Media.URL_TAG in request.POST):
         return ApiDataProvider.returnError('no media param')
     
     # get data
     mood = request.POST[Mood.URL_TAG]
     content = request.POST[Media.URL_TAG]
     
     # out of bounds short circuit
     if not(mood in Mood.MOOD_TYPES and content in Media.CONTENT_TYPES):
         return ApiDataProvider.returnError('parameter out of range')
     
     ContentDataOrganizer.collectContentCronJob(mood, content)
     return ApiDataProvider.returnSuccess('added some photo')
     
     
     
     
     
     
 def read(self, request):
     if (Media.URL_TAG in request.GET) and (Mood.URL_TAG in request.GET):            
         # check if input is string
         myMood = request.GET[Mood.URL_TAG]
         myContent = request.GET[Media.URL_TAG]
         
         if not (myMood in Mood.MOOD_TYPES):
             return ApiDataProvider.returnError(ContentHandler._TAG + 'bad mood input')
         
         if not (myContent in Media.CONTENT_TYPES):
             return ApiDataProvider.returnError(ContentHandler._TAG + 'bad content input')
         
         
         # check if input is within bounds
         if not((myMood in Mood.MOOD_TYPES) and (myContent in Media.CONTENT_TYPES)):
             return ApiDataProvider.returnError(ContentHandler._TAG + 'input out of bounds')
         
         # save guard
         try:
             return ApiDataProvider.getContent(myMood, myContent)
         except Exception:
             return ApiDataProvider.returnError(ContentHandler._TAG + 'unexpected error')
     else :
         return ApiDataProvider.returnError(ContentHandler._TAG + 'bad request')
示例#13
0
 def test_rateContent_illegalInput_wrongthumbing(self):
     with self.assertRaises(AssertionError) as err:
         ApiDataProvider.rateContent(0, 2)
示例#14
0
 def read(self, request):
     return ApiDataProvider.helloworld();
         
         
示例#15
0
 def read(self, request):
     return ApiDataProvider.helloworld()
示例#16
0
 def test_getContent_outofboundsinput(self):
     with self.assertRaises(AssertionError) as err:
         ApiDataProvider.getContent(4, Media.PICTURE)
     with self.assertRaises(AssertionError) as err:  
         ApiDataProvider.getContent(Mood.HAPPY, 4)
示例#17
0
 def test_getContent_baddatabase_nopictures(self):
     Picture.objects.all().delete()
     json_str = ApiDataProvider.getContent(Mood.HAPPY, Media.PICTURE)
     self.assertTrue(ApiDataProvider.STATUS_ERROR in json_str)
示例#18
0
 def test_getContent_emptyBoth(self):
     json_str = ApiDataProvider.getContent(Mood.HAPPY, Media.TEXT)
     self.assertTrue(ApiDataProvider.STATUS_ERROR in json_str)
示例#19
0
 def test_getContent_emptyMood(self):
     json_str = ApiDataProvider.getContent(Mood.EXCITED, Media.PICTURE)
     self.assertTrue(ApiDataProvider.STATUS_ERROR in json_str)
 def create(self, request):
     # check if post has secret parameter
     print request.POST
     if not(DataNames.SECRET in request.POST) :
         return ApiDataProvider.returnError(FilterCronHandler._TAG + 'no ' + DataNames.SECRET)
     
     # check if secret parameter is correct
     the_secret = request.POST[DataNames.SECRET]
     if the_secret != ApiKeys.GAE_PRIVATE_KEY:
         return ApiDataProvider.returnError(FilterCronHandler._TAG + 'incorrect private key')
     
     # check if mood in post request
     if not (Mood.URL_TAG in request.POST):
         return ApiDataProvider.returnError(FilterCronHandler._TAG + 'no ' + Mood.URL_TAG)
     
     # check if parameter is correct
     mood = request.POST[Mood.URL_TAG]
     if not (mood in Mood.MOOD_TYPES) :
         return ApiDataProvider.returnError('mood input outofbounds')
     
     # check if content in post request
     if not (Media.URL_TAG in request.POST) :
         return ApiDataProvider.returnError(FilterCronHandler._TAG + 'no ' + Media.URL_TAG)
     
     # check if parameter is correct
     content = request.POST[Media.URL_TAG]
     if not (content in Media.CONTENT_TYPES) :
         return ApiDataProvider.returnError('content input outofbounds')
     
     # check if type is defined
     if not (FilterCronHandler.FILTER_TYPE in request.POST):
         return ApiDataProvider.returnError(FilterCronHandler._TAG + 'no ' + FilterCronHandler.FILTER_TYPE)
     
     # check if parameter is correect
     type = request.POST[FilterCronHandler.FILTER_TYPE]
     if not (type in FilterCronHandler.ALL_FILTER) :
         return ApiDataProvider.returnError('filter type input outofbounds')
     
     # perform cron job
     if type == FilterCronHandler.CONTENT_FILTER:
         #deprecated
         if ContentDataOrganizer.filterContentCronJob(mood):
             return ApiDataProvider.returnSuccess('success filtered data')
         else:
             return ApiDataProvider.returnError(FilterCronHandler._TAG + 'error filtering data')
         
     elif type == FilterCronHandler.SCORE_FILTER:
         res = ContentDataOrganizer.scoreThresholdFilterCronJob(mood, content)
         if res > 0:
             print 'filtered ' + str(res)
             return ApiDataProvider.returnSuccess('filtered ' + str(res) + ' contents')
         elif res == ScoreFilter.NO_FINAL_SCORE:
             return ApiDataProvider.returnSuccess('no data need to be filtered')
         elif res == ScoreFilter.EMPTY_DB:
             return ApiDataProvider.returnError('nothing in database')
         
     elif type == FilterCronHandler.URL_FILTER:
         print 'Broken Filter'
         if ContentDataOrganizer.brokenURLFilterCronJob(mood, content) :
             # done
             return ApiDataProvider.returnSuccess('1')
         else:
             # still have more to do
             return ApiDataProvider.returnSuccess('0')
示例#21
0
 def test_rateContent_illegalInput_wrongmid(self):
     with self.assertRaises(AssertionError) as err:
         ApiDataProvider.rateContent('0', Rank.THUMBS_DOWN)
     with self.assertRaises(AssertionError) as err:  
         ApiDataProvider.rateContent('abc', Rank.THUMBS_UP)
示例#22
0
 def test_rateContent_baddatabase_empty(self):
     json_str = ApiDataProvider.rateContent(-1, Rank.THUMBS_DOWN)
     self.assertTrue(ApiDataProvider.STATUS_ERROR in json_str)
    def create(self, request):
        # check if post has secret parameter
        print request.POST
        if not (DataNames.SECRET in request.POST):
            return ApiDataProvider.returnError(FilterCronHandler._TAG + 'no ' +
                                               DataNames.SECRET)

        # check if secret parameter is correct
        the_secret = request.POST[DataNames.SECRET]
        if the_secret != ApiKeys.GAE_PRIVATE_KEY:
            return ApiDataProvider.returnError(FilterCronHandler._TAG +
                                               'incorrect private key')

        # check if mood in post request
        if not (Mood.URL_TAG in request.POST):
            return ApiDataProvider.returnError(FilterCronHandler._TAG + 'no ' +
                                               Mood.URL_TAG)

        # check if parameter is correct
        mood = request.POST[Mood.URL_TAG]
        if not (mood in Mood.MOOD_TYPES):
            return ApiDataProvider.returnError('mood input outofbounds')

        # check if content in post request
        if not (Media.URL_TAG in request.POST):
            return ApiDataProvider.returnError(FilterCronHandler._TAG + 'no ' +
                                               Media.URL_TAG)

        # check if parameter is correct
        content = request.POST[Media.URL_TAG]
        if not (content in Media.CONTENT_TYPES):
            return ApiDataProvider.returnError('content input outofbounds')

        # check if type is defined
        if not (FilterCronHandler.FILTER_TYPE in request.POST):
            return ApiDataProvider.returnError(FilterCronHandler._TAG + 'no ' +
                                               FilterCronHandler.FILTER_TYPE)

        # check if parameter is correect
        type = request.POST[FilterCronHandler.FILTER_TYPE]
        if not (type in FilterCronHandler.ALL_FILTER):
            return ApiDataProvider.returnError('filter type input outofbounds')

        # perform cron job
        if type == FilterCronHandler.CONTENT_FILTER:
            #deprecated
            if ContentDataOrganizer.filterContentCronJob(mood):
                return ApiDataProvider.returnSuccess('success filtered data')
            else:
                return ApiDataProvider.returnError(FilterCronHandler._TAG +
                                                   'error filtering data')

        elif type == FilterCronHandler.SCORE_FILTER:
            res = ContentDataOrganizer.scoreThresholdFilterCronJob(
                mood, content)
            if res > 0:
                print 'filtered ' + str(res)
                return ApiDataProvider.returnSuccess('filtered ' + str(res) +
                                                     ' contents')
            elif res == ScoreFilter.NO_FINAL_SCORE:
                return ApiDataProvider.returnSuccess(
                    'no data need to be filtered')
            elif res == ScoreFilter.EMPTY_DB:
                return ApiDataProvider.returnError('nothing in database')

        elif type == FilterCronHandler.URL_FILTER:
            print 'Broken Filter'
            if ContentDataOrganizer.brokenURLFilterCronJob(mood, content):
                # done
                return ApiDataProvider.returnSuccess('1')
            else:
                # still have more to do
                return ApiDataProvider.returnSuccess('0')
示例#24
0
 def test_getContent_normalsituation(self):
     json_str = ApiDataProvider.getContent(Mood.HAPPY, Media.PICTURE)
     self.assertTrue(json_str[ApiDataProvider.PARAM_URL] in self.websites)
     mid_arr = [self.m1.id, self.m2.id, self.m3.id]
     self.assertTrue(json_str[ApiDataProvider.MEDIA_ID] in mid_arr)