Example #1
0
    def test_format_address(self):
        cid = rand_string()
        address_host = rand_string()
        address_url_path = '/a/{a}/b{b}/c-{c}/{d}d/'

        config = self._get_config()
        config['address_host'] = address_host
        config['address_url_path'] = address_url_path

        requests_module = _FakeRequestsModule()
        wrapper = HTTPSOAPWrapper(config, requests_module)

        try:
            wrapper.format_address(cid, None)
        except ValueError, e:
            eq_(e.message, 'CID:[{}] No parameters given for URL path'.format(cid))
Example #2
0
    def test_format_address(self):
        cid = rand_string()
        address_host = rand_string()
        address_url_path = '/a/{a}/b{b}/c-{c}/{d}d/'

        config = self._get_config()
        config['address_host'] = address_host
        config['address_url_path'] = address_url_path

        requests_module = _FakeRequestsModule()
        wrapper = HTTPSOAPWrapper(config, requests_module)

        try:
            wrapper.format_address(cid, None)
        except ValueError, e:
            eq_(e.message, 'CID:[{}] No parameters given for URL path'.format(cid))
Example #3
0
    def test_format_address(self):
        cid = rand_string()
        address_host = rand_string()
        address_url_path = '/a/{a}/b{b}/c-{c}/{d}d/'

        config = self._get_config()
        config['address_host'] = address_host
        config['address_url_path'] = address_url_path

        requests_module = _FakeRequestsModule()
        wrapper = HTTPSOAPWrapper(config, requests_module)

        try:
            wrapper.format_address(cid, None)
        except ValueError as e:
            eq_(e.message, 'CID:[{}] No parameters given for URL path'.format(cid))
        else:
            self.fail('Expected ValueError (params is None)')

        a = rand_string()
        b = rand_string()
        c = rand_string()
        d = rand_string()
        e = rand_string()
        f = rand_string()

        params = {'a':a, 'b':b, 'c':c, 'd':d, 'e':e, 'f':f}
        address, non_path_params = wrapper.format_address(cid, params)
        eq_(address, '{}/a/{}/b{}/c-{}/{}d/'.format(address_host, a, b, c, d))
        eq_(non_path_params, {'e':e, 'f':f})

        params = {'a':a, 'b':b}

        try:
            address, non_path_params = wrapper.format_address(cid, params)
        except ValueError as e:
            eq_(e.message, 'CID:[{}] Could not build URL path'.format(cid))
        else:
            self.fail('Expected ValueError (not enough keys in params)')
Example #4
0
    def test_http_methods(self):
        address_host = rand_string()

        config = self._get_config()
        config['is_active'] = True
        config['soap_version'] = '1.2'
        config['address_host'] = address_host

        requests_module = _FakeRequestsModule()
        wrapper = HTTPSOAPWrapper(config, requests_module)

        for address_url_path in ('/zzz', '/a/{a}/b/{b}'):
            for transport in ('soap', rand_string()):
                for name in ('get', 'delete', 'options', 'post', 'put',
                             'patch'):
                    config['transport'] = transport

                    _cid = rand_string()
                    _data = rand_string()

                    expected_http_request_value = rand_string()
                    expected_http_request_value = rand_string()

                    expected_params = rand_string()

                    expected_args1 = rand_string()
                    expected_args2 = rand_string()

                    expected_kwargs1 = rand_string()
                    expected_kwargs2 = rand_string()

                    def http_request(method,
                                     cid,
                                     data='',
                                     params=None,
                                     *args,
                                     **kwargs):

                        eq_(method, name.upper())
                        eq_(cid, _cid)

                        if name in ('get', 'delete', 'options'):
                            eq_(data, '')
                        else:
                            eq_(data, _data)

                        eq_(params, expected_params)
                        eq_(args, (expected_args1, expected_args2))
                        eq_(sorted(kwargs.items()),
                            [('bar', expected_kwargs2),
                             ('foo', expected_kwargs1)])

                        return expected_http_request_value

                    def format_address(cid, params):
                        return expected_http_request_value

                    wrapper.http_request = http_request
                    wrapper.format_address = format_address

                    func = getattr(wrapper, name)

                    if name in ('get', 'delete', 'options'):
                        http_request_value = func(_cid,
                                                  expected_params,
                                                  expected_args1,
                                                  expected_args2,
                                                  foo=expected_kwargs1,
                                                  bar=expected_kwargs2)
                    else:
                        http_request_value = func(_cid,
                                                  _data,
                                                  expected_params,
                                                  expected_args1,
                                                  expected_args2,
                                                  foo=expected_kwargs1,
                                                  bar=expected_kwargs2)

                    eq_(http_request_value, expected_http_request_value)
Example #5
0
    def test_http_methods(self):
        address_host = rand_string()

        config = self._get_config()
        config['is_active'] = True
        config['soap_version'] = '1.2'
        config['address_host'] = address_host

        requests_module = _FakeRequestsModule()
        wrapper = HTTPSOAPWrapper(config, requests_module)

        for address_url_path in('/zzz', '/a/{a}/b/{b}'):
            for transport in('soap', rand_string()):
                for name in('get', 'delete', 'options', 'post', 'put', 'patch'):
                    config['transport'] = transport

                    _cid = rand_string()
                    _data = rand_string()

                    expected_http_request_value = rand_string()
                    expected_http_request_value = rand_string()

                    expected_params = rand_string()

                    expected_args1 = rand_string()
                    expected_args2 = rand_string()

                    expected_kwargs1 = rand_string()
                    expected_kwargs2 = rand_string()

                    def http_request(method, cid, data='', params=None, *args, **kwargs):

                        eq_(method, name.upper())
                        eq_(cid, _cid)

                        if name in('get', 'delete', 'options'):
                            eq_(data, '')
                        else:
                            eq_(data, _data)

                        eq_(params, expected_params)
                        eq_(args, (expected_args1, expected_args2))
                        eq_(sorted(kwargs.items()), [('bar', expected_kwargs2), ('foo', expected_kwargs1)])

                        return expected_http_request_value

                    def format_address(cid, params):
                        return expected_http_request_value

                    wrapper.http_request = http_request
                    wrapper.format_address = format_address

                    func = getattr(wrapper, name)

                    if name in('get', 'delete', 'options'):
                        http_request_value = func(
                            _cid, expected_params, expected_args1, expected_args2,
                            foo=expected_kwargs1, bar=expected_kwargs2)
                    else:
                        http_request_value = func(
                            _cid, _data, expected_params, expected_args1, expected_args2,
                            foo=expected_kwargs1, bar=expected_kwargs2)

                    eq_(http_request_value, expected_http_request_value)