Exemple #1
0
    def test_failed_sanitize_story_reaction(self):
        data_input = "not_a_story_reaction"
        assert data_input not in ALLOWED_STORY_REACTIONS

        with self.assertRaises(InvalidFormatException) as context:
            InputSanitizer.sanitize_integer(data_input)
        exception = context.exception
        self.assertEqual(exception.error_code, 400)
Exemple #2
0
    def post(self):
        try:
            # get token from header
            token = self._get_token_from_header()

            # identify with token
            username = Token.identify(token)

            # get data from request
            story_data = {}
            story_data['media'] = self._get_media_from_request()
            story_data['location'] = self._get_location_from_request()
            timestamp = self._get_timestamp_from_request()
            is_private = self._get_privateness_from_request()
            story_data['title'] = self._try_get_title_from_request()
            story_data['description'] = self._try_get_description_from_request(
            )
            story_data['username'] = username

            # validated data
            story_data['timestamp'] = InputSanitizer.sanitize_integer(
                timestamp)
            story_data['is_private'] = InputSanitizer.sanitize_boolean(
                is_private)

            # ask SS for storage service?

            # save new Story at AS
            self.logger.debug(
                "At POST@/stories got story_data {}".format(story_data))
            new_story_id = User.save_new_story(story_data)

            # generate response
            response = dict(story_data)
            response['story_id'] = new_story_id

            # save stat
            StatCollector.save_event_story_post(story_data["timestamp"])

            # return response
            return ResponseBuilder.build_response(response)

        except (MissingFieldException, InvalidTokenException,
                ExpiredTokenException, InvalidFormatException) as e:
            return ResponseBuilder.build_error_response(
                e.message, e.error_code)
Exemple #3
0
    def post(self):
        try:
            # get token from header
            token = self._get_token_from_header()

            # identify with token
            username = Token.identify(token)

            # get data from request
            flash_data = {}
            flash_data['media'] = self._get_media_from_request()
            flash_data['location'] = self._get_location_from_request()
            timestamp = self._get_timestamp_from_request()
            flash_data['title'] = self._try_get_title_from_request()
            flash_data['description'] = self._try_get_description_from_request()
            flash_data['username'] = username

            # validated data
            flash_data['timestamp'] = InputSanitizer.sanitize_integer(timestamp)

            # save new flash at AS
            self.logger.debug("At POST@/flashes got flash_data {}".format(flash_data))

            new_flash_id = User.save_new_flash(flash_data)

            # generate response
            response = dict(flash_data)
            response['flash_id'] = new_flash_id

            # save stat
            StatCollector.save_event_flash_post(flash_data["timestamp"])

            # return response
            return ResponseBuilder.build_response(response)

        except (MissingFieldException, InvalidTokenException, ExpiredTokenException,
                InvalidFormatException) as e:
            return ResponseBuilder.build_error_response(e.message, e.error_code)
Exemple #4
0
 def test_failed_sanitize_integer(self):
     data_input = "not_an_integer"
     with self.assertRaises(InvalidFormatException) as context:
         InputSanitizer.sanitize_integer(data_input)
     exception = context.exception
     self.assertEqual(exception.error_code, 400)
Exemple #5
0
 def test_successful_sanitize_negative_integer(self):
     data_input = "-51213"
     expected_output = -51213
     self.assertEqual(InputSanitizer.sanitize_integer(data_input),
                      expected_output)