Пример #1
0
    def test_endpoint_sort_custom_strategy(self):
        """Parser should sort duplicate endpoint paths using a custom sort
        strategy.
        """
        source_cells = [
            '# POST /1',
            '# POST /+',
            '# GET /a'
        ]

        def custom_sort_fun(endpoint):
            if endpoint.find('1') >= 0:
                return 0
            elif endpoint.find('a') >= 0:
                return 1
            else:
                return 2

        parser = APICellParser(comment_prefix='#')
        endpoints = parser.endpoints(source_cells, custom_sort_fun)
        expected_values = ['/+', '/a', '/1']

        for index in range(0, len(expected_values)):
            endpoint, _ = endpoints[index]
            self.assertEqual(expected_values[index], endpoint, 'Endpoint was not found in expected order')
Пример #2
0
    def test_endpoint_sort_custom_strategy(self):
        """Parser should sort duplicate endpoint paths using a custom sort
        strategy.
        """
        source_cells = [
            '# POST /1',
            '# POST /+',
            '# GET /a'
        ]

        def custom_sort_fun(endpoint):
            index = sys.maxsize
            if endpoint.find('1') >= 0:
                return 0
            elif endpoint.find('a') >= 0:
                return 1
            else:
                return 2

        parser = APICellParser(comment_prefix='#')
        endpoints = parser.endpoints(source_cells, custom_sort_fun)
        expected_values = ['/+', '/a', '/1']

        for index in range(0, len(expected_values)):
            endpoint, _ = endpoints[index]
            self.assertEqual(expected_values[index], endpoint, 'Endpoint was not found in expected order')
Пример #3
0
    def test_endpoint_sort_default_strategy(self):
        """Parser should sort duplicate endpoint paths."""
        source_cells = [
            '# POST /:foo', '# POST /hello/:foo', '# GET /hello/:foo',
            '# PUT /hello/world'
        ]
        parser = APICellParser(kernelspec='some_unknown_kernel')
        endpoints = parser.endpoints(source_cells)
        expected_values = ['/hello/world', '/hello/:foo', '/:foo']

        for index in range(0, len(expected_values)):
            endpoint, _ = endpoints[index]
            self.assertEqual(expected_values[index], endpoint,
                             'Endpoint was not found in expected order')
Пример #4
0
    def test_endpoint_sort_default_strategy(self):
        """Parser should sort duplicate endpoint paths."""
        source_cells = [
            '# POST /:foo',
            '# POST /hello/:foo',
            '# GET /hello/:foo',
            '# PUT /hello/world'
        ]
        parser = APICellParser(comment_prefix='#')
        endpoints = parser.endpoints(source_cells)
        expected_values = ['/hello/world', '/hello/:foo', '/:foo']

        for index in range(0, len(expected_values)):
            endpoint, _ = endpoints[index]
            self.assertEqual(expected_values[index], endpoint, 'Endpoint was not found in expected order')
Пример #5
0
 def test_endpoint_concatenation(self):
     """Parser should concatenate multiple cells with the same verb+path."""
     source_cells = [
         '# POST /foo/:bar', '# POST /foo/:bar', '# POST /foo', 'ignored',
         '# GET /foo/:bar'
     ]
     parser = APICellParser(kernelspec='some_unknown_kernel')
     endpoints = parser.endpoints(source_cells)
     self.assertEqual(len(endpoints), 2)
     # for ease of testing
     endpoints = dict(endpoints)
     self.assertEqual(len(endpoints['/foo']), 1)
     self.assertEqual(len(endpoints['/foo/:bar']), 2)
     self.assertEqual(endpoints['/foo']['POST'], '# POST /foo\n')
     self.assertEqual(endpoints['/foo/:bar']['POST'],
                      '# POST /foo/:bar\n# POST /foo/:bar\n')
     self.assertEqual(endpoints['/foo/:bar']['GET'], '# GET /foo/:bar\n')
Пример #6
0
 def test_endpoint_concatenation(self):
     """Parser should concatenate multiple cells with the same verb+path."""
     source_cells = [
         '# POST /foo/:bar',
         '# POST /foo/:bar',
         '# POST /foo',
         'ignored',
         '# GET /foo/:bar'
     ]
     parser = APICellParser(comment_prefix='#')
     endpoints = parser.endpoints(source_cells)
     self.assertEqual(len(endpoints), 2)
     # for ease of testing
     endpoints = dict(endpoints)
     self.assertEqual(len(endpoints['/foo']), 1)
     self.assertEqual(len(endpoints['/foo/:bar']), 2)
     self.assertEqual(endpoints['/foo']['POST'], '# POST /foo\n')
     self.assertEqual(endpoints['/foo/:bar']['POST'], '# POST /foo/:bar\n# POST /foo/:bar\n')
     self.assertEqual(endpoints['/foo/:bar']['GET'], '# GET /foo/:bar\n')