Exemple #1
0
    def post(self, resource, parameters={}, data={}, headers={}):
        """
        Perform a POST HTTP requeste on a resource.

        :arg resource: the resource to POST to
        :arg parameters: a dictionary of GET parameters for the resource
        :arg data: a dictionary of POST parameters for the resource
        :arg headers: optional headers. If specified, these will override the
            default headers.

        :returns:
            A response from the AltaPay service as a :samp:`dict`.

        :raises:
            :UnauthorizedAccessError: If the supplied credentials are not
                valid.

            :ResponseStatusError: If the response code from AltaPay is not a
                subset of the allowed response codes.

        """
        return self._request(urljoin(self.url, resource),
                             'POST',
                             params=utils.http_build_query(parameters),
                             data=utils.http_build_query_dict(data),
                             headers=headers or self._headers())
Exemple #2
0
    def post(self, resource, parameters={}, data={}, headers={}):
        """
        Perform a POST HTTP requeste on a resource.

        :arg resource: the resource to POST to
        :arg parameters: a dictionary of GET parameters for the resource
        :arg data: a dictionary of POST parameters for the resource
        :arg headers: optional headers. If specified, these will override the
            default headers.

        :returns:
            A response from the AltaPay service as a :samp:`dict`.

        :raises:
            :UnauthorizedAccessError: If the supplied credentials are not
                valid.

            :ResponseStatusError: If the response code from AltaPay is not a
                subset of the allowed response codes.

        """
        return self._request(
            urljoin(self.url, resource), 'POST',
            params=utils.http_build_query(parameters),
            data=utils.http_build_query_dict(data),
            headers=headers or self._headers())
Exemple #3
0
 def test_http_build_query_complex_dict(self):
     payload = OrderedDict([('customer',
                             OrderedDict([('name', 'test'),
                                          ('address', 'testaddress')]))])
     query_string = utils.http_build_query(payload)
     self.assertEqual(
         query_string,
         quote('customer[name]=test&customer[address]=testaddress',
               safe='/=&'))
Exemple #4
0
 def download(self, resource, parameters={}, headers={}):
     """
     Downloads a resource. Acts as a custom HTTP GET.
     Not that it is considered the callers responsibility to actually
     flush/close the stream.
     """
     response = requests.get(
         resource, params=utils.http_build_query(parameters), stream=True,
         headers=headers or self._headers(), auth=self._auth)
     return BytesIO(response.content)
Exemple #5
0
 def test_http_build_query_list_with_complex_dict(self):
     payload = OrderedDict([('orderline', [
         OrderedDict([('title', 'test'), ('qty', 1)]),
         OrderedDict([('title', 'test2'), ('qty', 2)])
     ])])
     query_string = utils.http_build_query(payload)
     self.assertEqual(
         query_string,
         quote(('orderline[0][title]=test&orderline[0][qty]=1&'
                'orderline[1][title]=test2&orderline[1][qty]=2'),
               safe='/=&'))
 def test_http_build_query_complex_dict(self):
     payload = OrderedDict([
         ('customer', OrderedDict([
             ('name', 'test'), ('address', 'testaddress')]
         ))
     ])
     query_string = utils.http_build_query(payload)
     self.assertEqual(
         query_string, quote(
             'customer[name]=test&customer[address]=testaddress',
             safe='/=&'))
Exemple #7
0
 def download(self, resource, parameters={}, headers={}):
     """
     Downloads a resource. Acts as a custom HTTP GET.
     Not that it is considered the callers responsibility to actually
     flush/close the stream.
     """
     response = requests.get(resource,
                             params=utils.http_build_query(parameters),
                             stream=True,
                             headers=headers or self._headers(),
                             auth=self._auth)
     return BytesIO(response.content)
Exemple #8
0
 def test_http_build_query_nested_dict(self):
     payload = OrderedDict([
         ('customer',
          OrderedDict([('address',
                        OrderedDict([('name', 'testname'),
                                     ('address', 'testaddr')]))]))
     ])
     query_string = utils.http_build_query(payload)
     self.assertEqual(
         query_string,
         quote(('customer[address][name]=testname&'
                'customer[address][address]=testaddr'),
               safe='/=&'))
 def test_http_build_query_nested_dict(self):
     payload = OrderedDict([
         ('customer', OrderedDict([
             ('address', OrderedDict([
                 ('name', 'testname'),
                 ('address', 'testaddr')
             ]))
         ]))
     ])
     query_string = utils.http_build_query(payload)
     self.assertEqual(
         query_string, quote((
             'customer[address][name]=testname&'
             'customer[address][address]=testaddr'), safe='/=&'))
 def test_http_build_query_list_with_complex_dict(self):
     payload = OrderedDict([
         ('orderline', [
             OrderedDict([
                 ('title', 'test'), ('qty', 1)
             ]),
             OrderedDict([
                 ('title', 'test2'), ('qty', 2)
             ])
         ])
     ])
     query_string = utils.http_build_query(payload)
     self.assertEqual(
         query_string, quote((
             'orderline[0][title]=test&orderline[0][qty]=1&'
             'orderline[1][title]=test2&orderline[1][qty]=2'),
             safe='/=&'))
Exemple #11
0
 def test_http_build_query_simple_list(self):
     payload = OrderedDict([('a', ['1', '2']), ('b', [3, 4])])
     query_string = utils.http_build_query(payload)
     self.assertEqual(query_string,
                      quote('a[0]=1&a[1]=2&b[0]=3&b[1]=4', safe='/=&'))
Exemple #12
0
 def test_http_build_query_simple(self):
     payload = OrderedDict([('a', '1'), ('b', 2)])
     query_string = utils.http_build_query(payload)
     self.assertEqual(query_string, 'a=1&b=2')
 def test_http_build_query_simple_list(self):
     payload = OrderedDict([('a', ['1', '2']), ('b', [3, 4])])
     query_string = utils.http_build_query(payload)
     self.assertEqual(
         query_string, quote('a[0]=1&a[1]=2&b[0]=3&b[1]=4', safe='/=&'))
 def test_http_build_query_simple(self):
     payload = OrderedDict([('a', '1'), ('b', 2)])
     query_string = utils.http_build_query(payload)
     self.assertEqual(query_string, 'a=1&b=2')