コード例 #1
0
ファイル: test_common.py プロジェクト: thomasez/zato-apitest
    def test_when_the_url_is_invoked_json(self):

        data_impl = {'a': {'b': 'cc'}}

        method = 'POST'
        address = 'http://{}.example.com'.format(util.rand_string())
        url_path = '/{}'.format(util.rand_string())
        qs = '?{}={}'.format(*util.rand_string(2))
        headers = {
            util.rand_string(): util.rand_string(),
            util.rand_string(): util.rand_string()
        }

        ctx = Bunch(zato=Bunch(request=Bunch()))

        ctx.zato.request.is_xml = False
        ctx.zato.request.is_json = True
        ctx.zato.request.response_format = 'JSON'
        ctx.zato.request.data_impl = data_impl
        ctx.zato.request.method = method
        ctx.zato.request.address = address
        ctx.zato.request.url_path = url_path
        ctx.zato.request.qs = qs
        ctx.zato.request.headers = headers

        common.when_the_url_is_invoked(ctx, [JSONEchoAdapter({})])
        sent_request = loads(ctx.zato.response.data_impl['data'])

        # Confirms the headers we sent were received.
        for key, value in headers.items():
            self.assertEquals(sent_request['request']['headers'][key], value)

        # Confirms the body we sent was received.
        self.assertDictEqual(loads(sent_request['request']['data']), data_impl)
コード例 #2
0
    def test_when_the_url_is_invoked_form(self):

        form = {'key1': ['value1'], 'key2': ['value2']}

        method = 'POST'
        address = 'http://{}.example.com'.format(util.rand_string())
        url_path = '/{}'.format(util.rand_string())
        headers = {
            util.rand_string(): util.rand_string(),
            util.rand_string(): util.rand_string()
        }

        ctx = Bunch(zato=Bunch(request=Bunch()))

        ctx.zato.request.is_xml = False
        ctx.zato.request.is_json = False
        ctx.zato.request.is_raw = False
        ctx.zato.request.is_form = True
        ctx.zato.request.request_format = 'FORM'
        ctx.zato.request.response_format = 'JSON'
        ctx.zato.request.form = form
        ctx.zato.request.data_impl = None
        ctx.zato.request.method = method
        ctx.zato.request.address = address
        ctx.zato.request.url_path = url_path
        ctx.zato.request.qs = ''
        ctx.zato.request.headers = headers

        common.when_the_url_is_invoked(ctx, [JSONEchoAdapter({})])
        sent_request = loads(ctx.zato.response.data_impl['data'])

        # Confirms the headers we sent were received.
        for key, value in headers.items():
            self.assertEquals(sent_request['request']['headers'][key], value)

        # Confirms the form data we sent was received.
        self.assertDictEqual(
            urlparse.parse_qs(sent_request['request']['data']), form)
コード例 #3
0
ファイル: test_common.py プロジェクト: thomasez/zato-apitest
    def test_when_the_url_is_invoked_xml(self):

        data = '<a><b>cc</b></a>'
        data_impl = etree.fromstring(data)
        data_c14n = xml_c14nize(data_impl)

        method = 'POST'
        address = 'http://{}.example.com'.format(util.rand_string())
        url_path = '/{}'.format(util.rand_string())
        qs = '?{}={}'.format(*util.rand_string(2))
        headers = {
            util.rand_string(): util.rand_string(),
            util.rand_string(): util.rand_string()
        }

        ctx = Bunch(zato=Bunch(request=Bunch()))

        ctx.zato.request.is_xml = True
        ctx.zato.request.data_impl = data_impl
        ctx.zato.request.method = method
        ctx.zato.request.address = address
        ctx.zato.request.url_path = url_path
        ctx.zato.request.qs = qs
        ctx.zato.request.headers = headers

        common.when_the_url_is_invoked(ctx, [XMLEchoAdapter(b'<dummy/>')])
        sent_request = loads(
            etree.fromstring(
                ctx.zato.response.data.text).xpath('/response')[0].text)

        # Confirms the headers we sent were received.
        for key, value in headers.items():
            self.assertEquals(sent_request['request']['headers'][key], value)

        # Confirms the body we sent was received.
        self.assertEquals(xml_c14nize(sent_request['request']['data']),
                          data_c14n)