Beispiel #1
0
class PlusToSpaceTestCase(TestCase):

    rf = RequestFactory()
    ptsm = PlusToSpaceMiddleware()

    def test_plus_to_space(self):
        """Pluses should be converted to %20."""
        request = self.rf.get("/url+with+plus")
        # should work without a QUERY_STRING key in META
        del request.META["QUERY_STRING"]
        response = self.ptsm.process_request(request)
        assert isinstance(response, HttpResponsePermanentRedirect)
        eq_("/url%20with%20plus", response["location"])

    def test_query_string(self):
        """Query strings should be maintained."""
        request = self.rf.get("/pa+th", {"a": "b"})
        response = self.ptsm.process_request(request)
        eq_("/pa%20th?a=b", response["location"])

    def test_query_string_unaffected(self):
        """Pluses in query strings are not affected."""
        request = self.rf.get("/pa+th?var=a+b")
        response = self.ptsm.process_request(request)
        eq_("/pa%20th?var=a+b", response["location"])

    def test_pass_through(self):
        """URLs without a + should be left alone."""
        request = self.rf.get("/path")
        assert not self.ptsm.process_request(request)

    def test_with_locale(self):
        """URLs with a locale should keep it."""
        request = self.rf.get("/pa+th", {"a": "b"})
        request.LANGUAGE_CODE = "ru"
        response = self.ptsm.process_request(request)
        eq_("/ru/pa%20th?a=b", response["location"])

    def test_smart_query_string(self):
        """The request QUERY_STRING might not be unicode."""
        request = self.rf.get("/pa+th")
        request.LANGUAGE_CODE = "ja"
        request.META["QUERY_STRING"] = "s=%E3%82%A2"
        response = self.ptsm.process_request(request)
        eq_("/ja/pa%20th?s=%E3%82%A2", response["location"])
Beispiel #2
0
class PlusToSpaceTestCase(TestCase):

    rf = RequestFactory()
    ptsm = PlusToSpaceMiddleware()

    def test_plus_to_space(self):
        """Pluses should be converted to %20."""
        request = self.rf.get('/url+with+plus')
        # should work without a QUERY_STRING key in META
        del request.META['QUERY_STRING']
        response = self.ptsm.process_request(request)
        assert isinstance(response, HttpResponsePermanentRedirect)
        eq_('/url%20with%20plus', response['location'])

    def test_query_string(self):
        """Query strings should be maintained."""
        request = self.rf.get('/pa+th', {'a': 'b'})
        response = self.ptsm.process_request(request)
        eq_('/pa%20th?a=b', response['location'])

    def test_query_string_unaffected(self):
        """Pluses in query strings are not affected."""
        request = self.rf.get('/pa+th?var=a+b')
        response = self.ptsm.process_request(request)
        eq_('/pa%20th?var=a+b', response['location'])

    def test_pass_through(self):
        """URLs without a + should be left alone."""
        request = self.rf.get('/path')
        assert not self.ptsm.process_request(request)

    def test_with_locale(self):
        """URLs with a locale should keep it."""
        request = self.rf.get('/pa+th', {'a': 'b'})
        request.LANGUAGE_CODE = 'ru'
        response = self.ptsm.process_request(request)
        eq_('/ru/pa%20th?a=b', response['location'])

    def test_smart_query_string(self):
        """The request QUERY_STRING might not be unicode."""
        request = self.rf.get(u'/pa+th')
        request.LANGUAGE_CODE = 'ja'
        request.META['QUERY_STRING'] = 's=\xe3\x82\xa2'
        response = self.ptsm.process_request(request)
        eq_('/ja/pa%20th?s=%E3%82%A2', response['location'])