def test_possible_add_resource(self): spec = APISpecification(version='v1', base_url='http://api.glb.com') resource = Resource('comments') resource.add_path(Path('/comments')) spec.add_resource(resource) assert len(spec.resources) == 1 assert len(resource.paths) == 1 assert resource.name == 'comments' assert resource.paths[0].name == '/comments'
def test_possible_add_resource(self): spec = APISpecification(version='v1', base_url='http://api.glb.com') resource = Resource('comments') resource.add_path(Path('/comments')) spec.add_resource(resource) assert len(spec.resources) == 1 assert len(resource.paths) == 1 assert resource.name == 'comments' assert resource.paths[0].name == '/comments'
def add(self, path, handler): resource = Resource(path) basic_methods = list(self.get_basic_methods(handler)) if basic_methods: resource.add_path( Path('/{0}'.format(path), methods=basic_methods)) resource.add_path( Path('/{0}.{{type}}'.format(path), params=[Param('type', style='url')], methods=basic_methods)) instance_methods = list(self.get_instance_methods(handler)) if instance_methods: resource.add_path( Path('/{0}/{{key}}'.format(path), params=[Param('key', style='url')], methods=instance_methods)) resource.add_path( Path('/{0}/{{key}}.{{type}}'.format(path), params=[ Param('key', style='url'), Param('type', style='url') ], methods=instance_methods)) self.spec.add_resource(resource)
def add(self, path, handler): resource = Resource(path) basic_methods = list(self.get_basic_methods(handler)) if basic_methods: resource.add_path(Path('/{0}'.format(path), methods=basic_methods)) resource.add_path( Path('/{0}.{{type}}'.format(path), params=[Param('type', style='url')], methods=basic_methods)) instance_methods = list(self.get_instance_methods(handler)) if instance_methods: resource.add_path( Path('/{0}/{{key}}'.format(path), params=[Param('key', style='url')], methods=instance_methods)) resource.add_path( Path('/{0}/{{key}}.{{type}}'.format(path), params=[ Param('key', style='url'), Param('type', style='url') ], methods=instance_methods)) self.spec.add_resource(resource)