Exemplo n.º 1
0
class ContentNegotiatorTest(unittest.TestCase):
    def setUp(self):
        self.request = Mock()
        self.request.headers = {"Accept": "text/html"}
        self.negotiator = ContentNegotiator()

        self.renderers = [
            Mock(media_type="text/html", name="html"),
            Mock(media_type="application/json", name="json"),
        ]

    def test_select_renderer_basic(self):
        r = self.negotiator.select_renderer(self.request, self.renderers)
        self.assertEqual(r[0], self.renderers[0])

    def test_select_renderer_more(self):
        self.request.headers = {"Accept": "application/json"}
        r = self.negotiator.select_renderer(self.request, self.renderers)
        self.assertEqual(r[0], self.renderers[1])

    def test_select_renderer_wildcard(self):
        self.request.headers = {"Accept": "application/*"}
        r = self.negotiator.select_renderer(self.request, self.renderers)
        self.assertEqual(r[0], self.renderers[1])

    def test_select_renderer_fail(self):
        self.request.headers = {"Accept": "application/xml"}
        self.assertRaises(
            NoRendererException,
            self.negotiator.select_renderer,
            self.request,
            self.renderers
        )
class ContentNegotiatorTest(unittest.TestCase):
    def setUp(self):
        self.request = Mock()
        self.request.headers = {"Accept": "text/html"}
        self.negotiator = ContentNegotiator()

        self.renderers = [
            Mock(media_type="text/html", name="html"),
            Mock(media_type="application/json", name="json"),
        ]

    def test_select_renderer_basic(self):
        r = self.negotiator.select_renderer(self.request, self.renderers)
        self.assertEqual(r[0], self.renderers[0])

    def test_select_renderer_more(self):
        self.request.headers = {"Accept": "application/json"}
        r = self.negotiator.select_renderer(self.request, self.renderers)
        self.assertEqual(r[0], self.renderers[1])

    def test_select_renderer_wildcard(self):
        self.request.headers = {"Accept": "application/*"}
        r = self.negotiator.select_renderer(self.request, self.renderers)
        self.assertEqual(r[0], self.renderers[1])

    def test_select_renderer_fail(self):
        self.request.headers = {"Accept": "application/xml"}
        self.assertRaises(NoRendererException, self.negotiator.select_renderer,
                          self.request, self.renderers)
    def setUp(self):
        self.request = Mock()
        self.request.headers = {"Accept": "text/html"}
        self.negotiator = ContentNegotiator()

        self.renderers = [
            Mock(media_type="text/html", name="html"),
            Mock(media_type="application/json", name="json"),
        ]
Exemplo n.º 4
0
    def setUp(self):
        self.request = Mock()
        self.request.headers = {"Accept": "text/html"}
        self.negotiator = ContentNegotiator()

        self.renderers = [
            Mock(media_type="text/html", name="html"),
            Mock(media_type="application/json", name="json"),
        ]