def populate(filename, baseurl=None, reset=False): """Populate the database with sample data""" populator = Populate(db, filepath=filename, baseurl=baseurl, app=app) if not reset: try: populator() except RuntimeError: with app.test_request_context( base_url=baseurl or 'http://localhost:5000/'): populator() else: populator.reset()
def configure(app, db): try: is_installed = Quokka.objects.get(slug="is_installed") except: is_installed = False if not is_installed: print("Loading fixtures") populate = Populate(db) populate.create_configs() populate.create_purposes() populate.create_channel_types() populate.create_base_channels() Quokka.objects.create(slug="is_installed")
class PopulateTestCase(TestCase): def setUp(self): self.db = list(self.app.extensions.get('mongoengine').keys())[0] self.db.connection.drop_database('quokka_test') self.populate = Populate(self.db) def create_app(self): self.admin = create_admin() return create_app(config='quokka.test_settings', DEBUG=False, test=True, admin_instance=self.admin) def test_role_called_with_name_and_instance(self): role_1st_call = self.populate.role('admin') role_2nd_call = self.populate.role(role_1st_call) self.assertEqual(role_1st_call.name, role_2nd_call.name)
def setUpClass(cls): '''Set up fixtures for the class. This methods runs once for the entire class. This test case do not insert or update any record on the database, so there is no problem to be run only once for the class. This way it save some time, instead of populate the test database each time a test is executed. ''' admin = create_admin() app = create_app(config='quokka.test_settings', DEBUG=False, test=True, admin_instance=admin) with app.app_context(): db = list(app.extensions.get('mongoengine').keys())[0] db.connection.drop_database('quokka_test') from quokka.utils.populate import Populate Populate(db)() cls.app = app cls.db = db
def configure(app, db): try: is_installed = Quokka.objects.get(slug="is_installed") except: is_installed = False if not is_installed: app.logger.info("Loading fixtures") populate = Populate(db, filepath=app.config.get('POPULATE_FILEPATH'), first_install=True) try: populate.create_configs() populate.create_purposes() populate.create_channel_types() populate.create_base_channels() populate.role("admin") populate.role("author") try: with app.app_context(): user_data, user_obj = populate.create_initial_superuser() populate.create_initial_post(user_data, user_obj) except Exception as e: app.logger.warning("Cant create initial user and post: %s" % e) except Exception as e: app.logger.error("Error loading fixtures, try again - %s" % e) populate.reset() Config.objects.delete() else: Quokka.objects.create(slug="is_installed")
def populate(filepath): """Populate the database with sample data""" from quokka.utils.populate import Populate Populate(db, filepath=filepath)()
def setUp(self): self.db = self.app.extensions.get('mongoengine') from quokka.utils.populate import Populate Populate(self.db)()
def configure(app, db): try: is_installed = Quokka.objects.get(slug="is_installed") except: is_installed = False if not is_installed: print("Loading fixtures") populate = Populate(db, filepath=app.config.get('POPULATE_FILEPATH')) populate.create_configs() populate.create_purposes() populate.create_channel_types() populate.create_base_channels() try: with app.test_request_context(): user_data, user_obj = populate.create_initial_superuser() populate.create_initial_post(user_data, user_obj) except: logger.warning("Could not create initial user and post") Quokka.objects.create(slug="is_installed")
def populate(filename, baseurl=None): """Populate the database with sample data""" from quokka.utils.populate import Populate Populate(db, filepath=filename, baseurl=baseurl, app=app)()
def configure(app, db): try: is_installed = Quokka.objects.get(slug="is_installed") except: is_installed = False if not is_installed: app.logger.info("Loading fixtures") populate = Populate( db, filepath=app.config.get('POPULATE_FILEPATH'), first_install=True ) try: populate.create_configs() populate.create_purposes() populate.create_channel_types() populate.create_base_channels() populate.role("admin") populate.role("author") try: with app.app_context(): user_data, user_obj = populate.create_initial_superuser() populate.create_initial_post(user_data, user_obj) except Exception as e: app.logger.warning("Cant create initial user and post: %s" % e) except Exception as e: app.logger.error("Error loading fixtures, try again - %s" % e) populate.reset() Config.objects.delete() else: Quokka.objects.create(slug="is_installed")
def populate(): Populate(db=db)()
def setUp(self): self.db = list(self.app.extensions.get('mongoengine').keys())[0] self.db.connection.drop_database('quokka_test') self.populate = Populate(self.db)
def populate(): """Populate the database with sample data""" from quokka.utils.populate import Populate Populate(db)()
def setUp(self): self.db = list(self.app.extensions.get('mongoengine').keys())[0] self.db.connection.drop_database('quokka_test') from quokka.utils.populate import Populate Populate(self.db)()