Ejemplo n.º 1
0
    def post(self, story_id):
        try:
            # get token from header
            token = self._get_token_from_header()

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

            # get the reaction type
            reaction = self._get_reaction_from_request()
            reaction = InputSanitizer.sanitize_story_reaction(reaction)

            # post reaction to story by story_id
            saved_reaction = Story.react_to_story(story_id, username, reaction)

            # generate response
            output = {"reacting_user_id": username, "reaction": saved_reaction}

            # return response
            return ResponseBuilder.build_response(output)

        except (InvalidTokenException, ExpiredTokenException,
                InvalidFormatException, MissingFieldException,
                StoryNotFoundException) as e:
            return ResponseBuilder.build_error_response(
                e.message, e.error_code)
Ejemplo n.º 2
0
 def test_successful_sanitize_story_reaction(self):
     for n in ALLOWED_STORY_REACTIONS:
         data_input = n.upper()
         self.assertEqual(
             InputSanitizer.sanitize_story_reaction(data_input), n)