Esempio n. 1
0
    def test_path(self):
        # Test work with empty or corrupted HttpRequest instance
        request = HttpRequest()
        request.META = {'SERVER_NAME': 'www.google.com', 'SERVER_PORT': 80}
        context = path(request)
        self.assertEqual(
            context, {
                'REQUEST_ABSOLUTE_URI': 'http://www.google.com',
                'REQUEST_FULL_PATH': '',
                'REQUEST_PATH': ''
            })

        # Check how it works on real request
        url = reverse('context_processors_path')
        response = self.client.get(url)
        self.assertContains(response,
                            '"REQUEST_ABSOLUTE_URI": "http://testserver%s' % \
                            url)
        self.assertContains(response, '"REQUEST_FULL_PATH": "%s"' % url)
        self.assertContains(response, '"REQUEST_PATH": "%s"' % url)

        response = self.client.get(url, {'q': 'Query'})
        self.assertContains(response,
                            '"REQUEST_ABSOLUTE_URI": "http://testserver' \
                            '%s?q=Query"' % url)
        self.assertContains(response,
                            '"REQUEST_FULL_PATH": "%s?q=Query"' % url)
        self.assertContains(response, '"REQUEST_PATH": "%s"' % url)
Esempio n. 2
0
    def test_path(self):
        # Test work with empty or corrupted HttpRequest instance
        request = HttpRequest()
        request.META = {'SERVER_NAME': 'www.google.com',
                        'SERVER_PORT': 80}
        context = path(request)
        self.assertEqual(context,
                         {'REQUEST_ABSOLUTE_URI': 'http://www.google.com',
                          'REQUEST_FULL_PATH': '',
                          'REQUEST_PATH': ''})

        # Check how it works on real request
        url = reverse('context_processors_path')
        response = self.client.get(url)
        self.assertContains(response,
                            '"REQUEST_ABSOLUTE_URI": "http://testserver%s' % \
                            url)
        self.assertContains(response,
                            '"REQUEST_FULL_PATH": "%s"' % url)
        self.assertContains(response,
                            '"REQUEST_PATH": "%s"' % url)

        response = self.client.get(url, {'q': 'Query'})
        self.assertContains(response,
                            '"REQUEST_ABSOLUTE_URI": "http://testserver' \
                            '%s?q=Query"' % url)
        self.assertContains(response,
                            '"REQUEST_FULL_PATH": "%s?q=Query"' % url)
        self.assertContains(response,
                            '"REQUEST_PATH": "%s"' % url)
Esempio n. 3
0
def context_processors_path(request):
    return path(request)