Example #1
0
    def test_redirects(self):
        url = 'http://testserver/ehco/'
        response = local_requests.get(url, allow_redirects=False)
        self.assertEqual(response.status_code, codes.found)
        if django.VERSION < (1, 9):
            self.assertEqual(response.headers['Location'], 'http://testserver/echo/')
        else:
            self.assertEqual(response.headers['Location'], '/echo/')

        response = local_requests.get(url, allow_redirects=True)
        self.assertEqual(response.status_code, codes.ok)
        self.assertEqual(response.url, 'http://testserver/echo/')
        self.assertEqual(response.history[0].status_code, codes.found)
Example #2
0
 def test_sends_params(self):
     url = 'http://testserver/echo/'
     response = local_requests.get(url, headers={
         'user-agent': 'Mozilla/5.0',
     })
     self.assertEqual(response.status_code, codes.ok)
     data = response.json()
     self.assertEqual(data['META']['HTTP_USER_AGENT'], 'Mozilla/5.0')
Example #3
0
 def test_sends_custom_headers(self):
     url = 'http://testserver/echo/'
     response = local_requests.get(url, params={
         'q': 'search',
     })
     self.assertEqual(response.status_code, codes.ok)
     data = response.json()
     self.assertEqual(data['GET']['q'], 'search')
Example #4
0
 def test_get_api_root(self):
     url = 'http://testserver/api/'
     response = local_requests.get(url)
     self.assertEqual(response.status_code, codes.ok)
     self.assertEqual(response.json(), {
         'authors': 'http://testserver/api/authors/',
         'books': 'http://testserver/api/books/',
     })