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)
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)
def context_processors_path(request): return path(request)