示例#1
0
 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)
示例#2
0
 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)
示例#3
0
    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)
示例#4
0
    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)