def test_resource_without_path(config: Config, db: SQLAlchemy): """Test resources that don't have url_prefix.""" class FooDef(Resource): VIEW = View __type__ = 'Foo' def __init__(self, app, import_name=__name__.split('.')[0], static_folder=None, static_url_path=None, template_folder=None, url_prefix='', # We set url_prefix to empty string subdomain=None, url_defaults=None, root_path=None): super().__init__(app, import_name, static_folder, static_url_path, template_folder, url_prefix, subdomain, url_defaults, root_path) config.RESOURCE_DEFINITIONS = FooDef, app = Teal(config=config, db=db) with app.test_request_context(): assert url_for_resource(FooDef) == '/' assert url_for_resource(FooDef, 1) == '/1'
def test_url_for_resource(app: Teal): with app.test_request_context(): # Note we need a test_request_context or flask won't know # which base_url to use. assert url_for_resource('Computer') == '/computers/' assert url_for_resource('Computer', 24) == '/computers/24'