コード例 #1
0
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()
コード例 #2
0
ファイル: fixtures.py プロジェクト: tonnyhjw/FlaskPyCMS
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")
コード例 #3
0
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
コード例 #5
0
ファイル: fixtures.py プロジェクト: zming619/quokka
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")
コード例 #6
0
def populate(filepath):
    """Populate the database with sample data"""
    from quokka.utils.populate import Populate
    Populate(db, filepath=filepath)()
コード例 #7
0
 def setUp(self):
     self.db = self.app.extensions.get('mongoengine')
     from quokka.utils.populate import Populate
     Populate(self.db)()
コード例 #8
0
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")
コード例 #9
0
ファイル: manage.py プロジェクト: wigginslab/quokka
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)()
コード例 #10
0
ファイル: fixtures.py プロジェクト: Cetids/quokka
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")
コード例 #11
0
ファイル: fixtures.py プロジェクト: Ryanker/quokka
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")
コード例 #12
0
ファイル: manage.py プロジェクト: leiyue/quokka-demo
def populate():
    Populate(db=db)()
コード例 #13
0
 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)
コード例 #14
0
def populate():
    """Populate the database with sample data"""
    from quokka.utils.populate import Populate
    Populate(db)()
コード例 #15
0
 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)()