Exemplo n.º 1
0
 def test_default_format_setting(self):
     """ Test that default setting works
     """
     expected = "json"
     step = ToString(default_format=expected)
     request = HttpRequest()
     actual = step.get_format(request)
     self.assertEqual(
         expected, actual, "Wrong format determined. Expected {} got {} instead.".format(expected, actual)
     )
Exemplo n.º 2
0
    def test_format_determinition_test_get_parameter(self):
        """ If request has GET parameter specified
            format is determined correctly """
        step = ToString()

        request = HttpRequest()

        formats = ["json", "xml", "yaml"]

        for expected in formats:
            request.GET["format"] = expected
            actual = step.get_format(request)
            self.assertEqual(
                expected, actual, "Wrong format determined. Expected {} got {} instead.".format(expected, actual)
            )
Exemplo n.º 3
0
    def test_format_determinition_forced_setting(self):
        """ Test that forced setting override GET
        """
        expected = "json"
        step = ToString(force_format=expected)

        request = HttpRequest()

        formats = ["json", "xml", "yaml"]

        for fmt in formats:
            request.GET["format"] = fmt
            actual = step.get_format(request)
            self.assertEqual(
                expected, actual, "Wrong format determined. Expected {} got {} instead.".format(expected, actual)
            )
Exemplo n.º 4
0
    def test_format_determinition_test_by_content_type(self):
        """ If request has GET parameter specified format is determined correctly
        """
        step = ToString()

        request = HttpRequest()

        formats = ["application/json", "application/xml", "application/yaml"]

        for content_type in formats:
            request.META["CONTENT_TYPE"] = content_type
            expected = content_type.split("/")[1]
            actual = step.get_format(request)
            self.assertEqual(
                expected, actual, "Wrong format determined. Expected {} got {} instead.".format(expected, actual)
            )
Exemplo n.º 5
0
 def test_format_determinition_test_exception(self):
     """ Throws error if nothing is specified
     """
     step = ToString()
     request = HttpRequest()
     step.get_format(request)