Example #1
0
    def view_test(self, *keys):
        decorator_values = {
            'required': {
                'x': object
            },
            'optional': {
                'y': object
            },
            'unlimited': True,
            'returns': object,
        }
        decorator_kwargs = {ikey: decorator_values[ikey] for ikey in keys}

        @api_view(**decorator_kwargs)
        def view_callable(**kwargs):
            pass

        api_tree = {'/': {GET: view_callable}}

        documentation = APIDocumentationMaker().create_documentation(api_tree)

        view_dict = documentation['/']['GET']

        view_dict.pop('description', None)

        assert set(keys) == set(view_dict.keys())
Example #2
0
    def view_callable_test(self, view_callable_class):
        @view_callable_class
        def view_callable():
            pass

        api_tree = {'/': view_callable}

        APIDocumentationMaker().create_documentation(api_tree)
Example #3
0
    def skip_keys_test(self, parameter_kind):
        api_tree = self.make_api_tree(parameter_kind)

        documentation = APIDocumentationMaker().create_documentation(api_tree)

        view_dict = documentation['/']['GET'].copy()
        del view_dict['description']

        assert view_dict == {}
class TestPrepareItem(unittest.TestCase):
    """ Test the function which prepares the API documentation result by
        converting class objects to name-strings. """
    def setUp(self):
        self.apidoc_view = APIDocumentationMaker()
    
    def test_custom_class(self):
        class CustomClass(object):
            pass
        
        assert self.apidoc_view.prepare(CustomClass) == 'CustomClass'
    
    def test_dict_obj(self):
        expected = prep_json({'a': 'object'})
        result = self.apidoc_view.prepare({'a': object})
        assert result == expected
    
    def test_list_obj(self):
        expected = prep_json(['object'])
        result = self.apidoc_view.prepare([object])
        assert result == expected
    
    def test_dict_list(self):
        expected = prep_json({'a': ['object']})
        result = self.apidoc_view.prepare({'a': [object]})
        assert result == expected
    
    def test_list_dict(self):
        expected = prep_json([{'a': 'object'}])
        result = self.apidoc_view.prepare([{'a': object}])
        assert result == expected
    
    def test_listof_object(self):
        assert self.apidoc_view.prepare(ListOf(object)) == 'ListOf(object)'
    
    def test_listof_list(self):
        expected = (
            'ListOf(\n' +
            prep_json(['object'], 1) + '\n'
            +')'
            )
        result = self.apidoc_view.prepare(ListOf([object]))
        assert result == expected
    
    def test_listof_dict(self):
        expected = (
            "ListOf(\n"
            + prep_json({'a': 'object'}, 1) + '\n'
            + ')'
            )
        result = self.apidoc_view.prepare(ListOf({'a': object}))
        assert result == expected
Example #5
0
    def no_mutation_test(self, parameter_kind):
        """ Confirm that this behavior does not mutate the iospec dictionaries
            of the view-callable's IOManager in-place. """
        api_tree = self.make_api_tree(parameter_kind)

        view_callable = api_tree['/'][GET]

        # Confirm that '_call' works before 'create_documentation'.
        view_callable._call(x=object())

        APIDocumentationMaker().create_documentation(api_tree)

        # Confirm that '_call' works after 'create_documentation'.
        view_callable._call(x=object())
Example #6
0
class TestPrepareItem(unittest.TestCase):
    """ Test the function which prepares the API documentation result by
        converting class objects to name-strings. """
    def setUp(self):
        self.apidoc_view = APIDocumentationMaker()

    def test_custom_class(self):
        class CustomClass(object):
            pass

        assert self.apidoc_view.prepare(CustomClass) == 'CustomClass'

    def test_dict_obj(self):
        expected = prep_json({'a': 'object'})
        result = self.apidoc_view.prepare({'a': object})
        assert result == expected

    def test_list_obj(self):
        expected = prep_json(['object'])
        result = self.apidoc_view.prepare([object])
        assert result == expected

    def test_dict_list(self):
        expected = prep_json({'a': ['object']})
        result = self.apidoc_view.prepare({'a': [object]})
        assert result == expected

    def test_list_dict(self):
        expected = prep_json([{'a': 'object'}])
        result = self.apidoc_view.prepare([{'a': object}])
        assert result == expected

    def test_listof_object(self):
        assert self.apidoc_view.prepare(ListOf(object)) == 'ListOf(object)'

    def test_listof_list(self):
        expected = ('ListOf(\n' + prep_json(['object'], 1) + '\n' + ')')
        result = self.apidoc_view.prepare(ListOf([object]))
        assert result == expected

    def test_listof_dict(self):
        expected = ("ListOf(\n" + prep_json({'a': 'object'}, 1) + '\n' + ')')
        result = self.apidoc_view.prepare(ListOf({'a': object}))
        assert result == expected
 def setUp(self):
     self.apidoc_view = APIDocumentationMaker()
Example #8
0
 def setUp(self):
     self.apidoc_view = APIDocumentationMaker()