def test_content_length_str(self): request = HTTPRequest('PUT', 'https', 'amazon.com', 443, None, None, {}, {}, 'Body') mock_connection = mock.Mock() request.authorize(mock_connection) # Ensure Content-Length header is a str. This is more explicit than # relying on other code cast the value later. (Python 2.7.0, for # example, assumes headers are of type str.) self.assertIsInstance(request.headers['Content-Length'], str)
def test_content_length_str(self): request = HTTPRequest('PUT', 'https', 'amazon.com', 443, None, None, {}, {}, 'Body') mock_connection = mock.Mock() request.authorize(mock_connection) # Ensure Content-Length header is a str. This is more explicit than # relying on other code cast the value later. (Python 2.7.0, for # example, assumes headers are of type str.) self.assertIsInstance(request.headers['Content-Length'], str)
def test_user_agent_not_url_encoded(self): headers = {'Some-Header': u'should be encoded \u2713', 'User-Agent': UserAgent} request = HTTPRequest('PUT', 'https', 'amazon.com', 443, None, None, {}, headers, 'Body') mock_connection = mock.Mock() # Create a method that preserves the headers at the time of # authorization. def mock_add_auth(req, **kwargs): mock_connection.headers_at_auth = req.headers.copy() mock_connection._auth_handler.add_auth = mock_add_auth request.authorize(mock_connection) # Ensure the headers at authorization are as expected i.e. # the user agent header was not url encoded but the other header was. self.assertEqual(mock_connection.headers_at_auth, {'Some-Header': 'should be encoded %E2%9C%93', 'User-Agent': UserAgent})
def test_user_agent_not_url_encoded(self): headers = {'Some-Header': u'should be url encoded', 'User-Agent': UserAgent} request = HTTPRequest('PUT', 'https', 'amazon.com', 443, None, None, {}, headers, 'Body') mock_connection = mock.Mock() # Create a method that preserves the headers at the time of # authorization. def mock_add_auth(req, **kwargs): mock_connection.headers_at_auth = req.headers.copy() mock_connection._auth_handler.add_auth = mock_add_auth request.authorize(mock_connection) # Ensure the headers at authorization are as expected i.e. # the user agent header was not url encoded but the other header was. self.assertEqual(mock_connection.headers_at_auth, {'Some-Header': 'should%20be%20url%20encoded', 'User-Agent': UserAgent})