Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)