Exemple #1
0
    def test_match(self):
        ud = url_data.URLData([])

        soap_action1 = uuid4().hex
        url_path1 = uuid4().hex
        match_target1 = '{}{}{}'.format(soap_action1, MISC.SEPARATOR,
                                        url_path1)

        soap_action2 = uuid4().hex
        url_path2 = uuid4().hex
        match_target2 = '{}{}{}'.format(soap_action2, MISC.SEPARATOR,
                                        url_path2)

        soap_action3 = ''
        url_path3 = '/customer/{cid}/order/{oid}'
        match_target3 = '{}{}{}'.format(soap_action3, MISC.SEPARATOR,
                                        url_path3)

        item1 = Bunch()
        item1.match_target = match_target1
        item1.match_target_compiled = parse_compile(item1.match_target)

        item2 = Bunch()
        item2.match_target = match_target2
        item2.match_target_compiled = parse_compile(item2.match_target)

        item3 = Bunch()
        item3.match_target = match_target3
        item3.match_target_compiled = parse_compile(item3.match_target)

        ud.channel_data.append(item1)
        ud.channel_data.append(item2)
        ud.channel_data.append(item3)

        match, _ = ud.match(url_path1, soap_action1)
        self.assertIsInstance(match, Result)
        eq_(match.named, {})
        eq_(match.spans, {})

        match, _ = ud.match(url_path2, soap_action2)
        self.assertIsInstance(match, Result)
        eq_(match.named, {})
        eq_(match.spans, {})

        match, _ = ud.match('/customer/123/order/456', soap_action3)
        self.assertIsInstance(match, Result)
        eq_(sorted(match.named.items()), [(u'cid', u'123'), (u'oid', u'456')])
        eq_(sorted(match.spans.items()), [(u'cid', (13, 16)),
                                          (u'oid', (23, 26))])

        match, _ = ud.match('/foo/bar', '')
        self.assertIsNone(match)
Exemple #2
0
    def test_match(self):
        ud = url_data.URLData([])

        soap_action1 = uuid4().hex
        url_path1 = uuid4().hex
        match_target1 = '{}{}{}'.format(soap_action1, MISC.SEPARATOR, url_path1)

        soap_action2 = uuid4().hex
        url_path2 = uuid4().hex
        match_target2 = '{}{}{}'.format(soap_action2, MISC.SEPARATOR, url_path2)

        soap_action3 = ''
        url_path3 = '/customer/{cid}/order/{oid}'
        match_target3 = '{}{}{}'.format(soap_action3, MISC.SEPARATOR, url_path3)

        item1 = Bunch()
        item1.match_target = match_target1
        item1.match_target_compiled = parse_compile(item1.match_target)

        item2 = Bunch()
        item2.match_target = match_target2
        item2.match_target_compiled = parse_compile(item2.match_target)

        item3 = Bunch()
        item3.match_target = match_target3
        item3.match_target_compiled = parse_compile(item3.match_target)

        ud.channel_data.append(item1)
        ud.channel_data.append(item2)
        ud.channel_data.append(item3)

        match, _ = ud.match(url_path1, soap_action1)
        self.assertIsInstance(match, Result)
        eq_(match.named, {})
        eq_(match.spans, {})

        match, _ = ud.match(url_path2, soap_action2)
        self.assertIsInstance(match, Result)
        eq_(match.named, {})
        eq_(match.spans, {})

        match, _ = ud.match('/customer/123/order/456', soap_action3)
        self.assertIsInstance(match, Result)
        eq_(sorted(match.named.items()), [(u'cid', u'123'), (u'oid', u'456')])
        eq_(sorted(match.spans.items()), [(u'cid', (13, 16)), (u'oid', (23, 26))])

        match, _ = ud.match('/foo/bar', '')
        self.assertIsNone(match)
Exemple #3
0
    def set_up(self):

        for name, config in sorted(self.config.mocks_config.items()):

            # Ignore our own config
            if name == 'apimox':
                continue

            config.name = name
            config.url_path_compiled = parse_compile(config.url_path)
            config.status = int(config.get('status', OK))
            config.method = config.get('method', 'GET')
            config.qs_values = self.get_qs_values(config)
            config.response = self.get_response(config)
            config.resp_headers = self.get_resp_headers(config)

            qs_info = '(qs: {})'.format(config.qs_values)
            logger.info('Mounting `{}` on {}{} {}'.format(name, self.full_address, config.url_path, qs_info))