def test_request(self, urllib2_mock): headers={'Content-Type': 'application/xml', "Accept": 'application/xml', "Authorization": "Basic amltOmJvYg==", } rest.request("http://localhost/", "POST", "body", username="******", password="******") urllib2_mock.Request.assert_called_once_with(url="http://localhost/", data="body", headers=headers)
def test_request(self, urllib2_mock): headers = { 'Content-Type': 'application/xml', "Accept": 'application/xml', "Authorization": "Basic amltOmJvYg==", } rest.request("http://localhost/", "POST", "body", username="******", password="******") urllib2_mock.Request.assert_called_once_with(url="http://localhost/", data="body", headers=headers)
def _post(self, url, body, error_message): url = urljoin(self.host, url) if self.verbose: print "URL: %s" % url print "Request Body:\n%s" % body if self.debug: return try: resp = request(url, method='POST', body=body, username=self.username, password=self.password) except urllib2.HTTPError, e: xml = e.read() if self.verbose: print xml message = ElementTree.fromstring(xml).findtext('.//message') raise Exception(error_message+": "+message)
def _post(self, url, body, error_message): url = urljoin(self.host, url) if self.verbose: print "URL: %s" % url print "Request Body:\n%s" % body if self.debug: return try: resp = request(url, method='POST', body=body, username=self.username, password=self.password) except urllib2.HTTPError, e: xml = e.read() if self.verbose: print xml message = ElementTree.fromstring(xml).findtext('.//message') raise Exception(error_message + ": " + message)