def test_table_finder(self): """ Should return all Table subclasses. """ tables = table_finder(modules=["tests.example_apps.music.tables"]) table_class_names = [i.__name__ for i in tables] table_class_names.sort() self.assertEqual( table_class_names, [ "Band", "Concert", "Manager", "Poster", "RecordingStudio", "Shirt", "Ticket", "Venue", ], ) with self.assertRaises(ImportError): table_finder(modules=["foo.bar.baz"])
def test_table_finder_coercion(self): """ Should convert a string argument to a list. """ tables = table_finder(modules="tests.example_app.tables") table_class_names = [i.__name__ for i in tables] table_class_names.sort() self.assertEqual( table_class_names, ["Band", "Concert", "Manager", "Poster", "Ticket", "Venue"], )
def test_exclude_tags(self): """ Should return all Table subclasses without the specified tags. """ tables = table_finder(modules=["tests.example_app.tables"], exclude_tags=["special"]) table_class_names = [i.__name__ for i in tables] table_class_names.sort() self.assertEqual( table_class_names, ["Band", "Concert", "Manager", "Ticket", "Venue"], )
def test_include_tags(self): """ Should return all Table subclasses with a matching tag. """ tables = table_finder(modules=["tests.example_app.tables"], include_tags=["special"]) table_class_names = [i.__name__ for i in tables] table_class_names.sort() self.assertEqual( table_class_names, ["Poster"], )
def test_exclude_imported(self): """ Make sure we can excluded imported Tables. """ filtered_tables = table_finder( modules=["tests.conf.example"], exclude_imported=True, ) self.assertEqual( [i.__name__ for i in filtered_tables], ["Musician"], ) # Now try without filtering: all_tables = table_finder( modules=["tests.conf.example"], exclude_imported=False, ) self.assertEqual( sorted([i.__name__ for i in all_tables]), ["BaseUser", "Musician"], )
""" Import all of the Tables subclasses in your app here, and register them with the APP_CONFIG. """ import os from piccolo.conf.apps import AppConfig, table_finder CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__)) APP_CONFIG = AppConfig( app_name="blog", migrations_folder_path=os.path.join(CURRENT_DIRECTORY, "piccolo_migrations"), table_classes=table_finder(modules=["blog.tables"]), migration_dependencies=[], commands=[], )
""" Import all of the Tables subclasses in your app here, and register them with the APP_CONFIG. """ import os from piccolo.conf.apps import AppConfig, table_finder CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__)) APP_CONFIG = AppConfig( app_name="home", migrations_folder_path=os.path.join(CURRENT_DIRECTORY, "piccolo_migrations"), table_classes=table_finder(modules=["home.tables"]), migration_dependencies=[], commands=[], )