Exemplo n.º 1
0
    def handle_request(self):

        log.log_url(self.cherrypy.url())

        request = self.cherrypy.to_mapper_request()
        items = self.mapping_handler.mapping_item_for_mapping_request(request)

        if len(items) == 0:
            self.cherrypy.response.status = 500
            return "no response found for request"

        if len(items) > 1:
            log.log_multiple_matches(items)

        matched_item = items[0]
        response = matched_item.response

        self.cherrypy.response.status = response.status
        self.fill_headers(response.headers)

        log.log_request(matched_item.request)
        log.log_response(response)
        log.print_seperator()

        return response.body_response()
Exemplo n.º 2
0
    def test_return_correct_body_for_multiple_response(self):
        item1 = Mock(file_name="file1")
        item1.request = "request1"

        item2 = Mock(file_name="file2")
        item2.request = "request2"
        # item2.title = Mock(return_value="title2")

        mapper = CherryPyMapper()
        mapper.cherrypy = Mock()
        mapper.cherrypy.url = Mock(return_value="some url")

        body = log.log_multiple_matches([item1, item2])
        self.assertEqual(body, "Matched 2 items, choosing the first one\n- file1\nrequest1\n\n- file2\nrequest2\n")
Exemplo n.º 3
0
    def test_return_correct_body_for_multiple_response(self):
        item1 = Mock(file_name="file1")
        item1.request = "request1"

        item2 = Mock(file_name="file2")
        item2.request = "request2"
        # item2.title = Mock(return_value="title2")

        mapper = CherryPyMapper()
        mapper.cherrypy = Mock()
        mapper.cherrypy.url = Mock(return_value="some url")

        body = log.log_multiple_matches([item1, item2])
        self.assertEqual(
            body,
            "Matched 2 items, choosing the first one\n- file1\nrequest1\n\n- file2\nrequest2\n"
        )