コード例 #1
0
class TestDispatcherUrls(unittest.TestCase):
    def setUp(self):
        self.disp = Dispatcher()

        self.disp.add_endpoint('user_page', '/path/to/{tenant_id}')
        self.disp.add_endpoint('instance_detail',
                               '/path/to/{tenant_id}/{instance_id}')

    def test_get_endpoint_path(self):
        req = MagicMock()
        req.env = {'tenant_id': '1234'}

        path = self.disp.get_endpoint_path(req, 'user_page')

        self.assertEqual(path, '/path/to/1234')

        path = self.disp.get_endpoint_path(req,
                                           'instance_detail',
                                           instance_id='9876')

        self.assertEqual(path, '/path/to/1234/9876')

    def test_get_endpoint_url(self):
        req = MagicMock()
        req.env = {'tenant_id': '1234'}
        req.protocol = 'http'
        req.get_header.return_value = 'some_host'
        req.app = ''

        path = self.disp.get_endpoint_url(req, 'user_page')

        self.assertEqual(path, 'http://some_host/path/to/1234')

        path = self.disp.get_endpoint_url(req,
                                          'instance_detail',
                                          instance_id='9876')

        self.assertEqual(path, 'http://some_host/path/to/1234/9876')
コード例 #2
0
ファイル: test_dispatcher.py プロジェクト: LiuZhiyan/jumpgate
class TestDispatcherUrls(unittest.TestCase):
    def setUp(self):
        self.disp = Dispatcher()

        self.disp.add_endpoint('user_page', '/path/to/{tenant_id}')
        self.disp.add_endpoint('instance_detail',
                               '/path/to/{tenant_id}/{instance_id}')

    def test_get_endpoint_path(self):
        req = MagicMock()
        req.env = {'tenant_id': '1234'}

        path = self.disp.get_endpoint_path(req, 'user_page')

        self.assertEquals(path, '/path/to/1234')

        path = self.disp.get_endpoint_path(
            req, 'instance_detail', instance_id='9876')

        self.assertEquals(path, '/path/to/1234/9876')

    def test_get_endpoint_url(self):
        req = MagicMock()
        req.env = {'tenant_id': '1234'}
        req.protocol = 'http'
        req.get_header.return_value = 'some_host'
        req.app = ''

        path = self.disp.get_endpoint_url(req, 'user_page')

        self.assertEquals(path, 'http://some_host/path/to/1234')

        path = self.disp.get_endpoint_url(
            req, 'instance_detail', instance_id='9876')

        self.assertEquals(path, 'http://some_host/path/to/1234/9876')