def test_smartyresponse_contains_status_code_400_when_server_gives_a_400( self, mock_send): sender = smarty.RequestsSender() smartyrequest = smarty.Request() smartyrequest.url_prefix = "http://localhost/error" response = sender.send(smartyrequest) self.assertEqual(400, response.status_code)
def test_smartyresponse_contains_correct_payload(self, mock_send): sender = smarty.RequestsSender() smartyrequest = smarty.Request() smartyrequest.url_prefix = "http://localhost" smartyrequest.payload = "This is the test content." response = sender.send(smartyrequest) self.assertEqual("This is the test payload.", response.payload)
def test_smartyresponse_contains_status_code_200_on_success( self, mock_send): sender = smarty.RequestsSender() smartyrequest = smarty.Request() smartyrequest.url_prefix = "http://localhost" response = sender.send(smartyrequest) self.assertEqual(200, response.status_code)
def test_license_not_set(self): sender = smarty.RequestsSender() sender = smarty.LicenseSender([], sender) request = smarty.Request() request.url_prefix = "http://localhost" sender.send(request) self.assertEqual(0, len(request.parameters))
def test_license_set(self): sender = smarty.RequestsSender() licenses = ['one', 'two', 'three'] sender = smarty.LicenseSender(licenses, sender) request = smarty.Request() request.url_prefix = "http://localhost" sender.send(request) self.assertEqual('one,two,three', request.parameters['license'])
def test_populates_headers(self): sender = smarty.RequestsSender() header = { 'Test-User-Agent': 'Test-Agent', 'Test-Content-Type': 'Test-Content-Type' } sender = smarty.CustomHeaderSender(header, sender) self.assertEqual(sender.headers['Test-User-Agent'], 'Test-Agent') self.assertEqual(sender.headers['Test-Content-Type'], 'Test-Content-Type')
def test_custom_headers_used(self): sender = smarty.RequestsSender() header = {'User-Agent': 'Test-Agent', 'Content-Type': 'Test-Type'} sender = smarty.CustomHeaderSender(header, sender) smartyrequest = smarty.Request() smartyrequest.url_prefix = "http://localhost" smartyrequest.payload = "This is the test content." request = sender.build_request(smartyrequest) request = smarty.requests_sender.build_request(request) self.assertEqual('Test-Agent', request.headers['User-Agent']) self.assertEqual('Test-Type', request.headers['Content-Type'])
def build_sender(self): if self.http_sender is not None: return self.http_sender sender = smarty.RequestsSender(self.max_timeout) sender.debug = self.debug sender = smarty.StatusCodeSender(sender) if self.signer is not None: sender = smarty.SigningSender(self.signer, sender) if self.max_retries > 0: sender = smarty.RetrySender(self.max_retries, sender) sender = smarty.URLPrefixSender(self.url_prefix, sender) return sender