def test_update_settings_from_fixture(database): # No force-overwrite - the fixtures will be created because # do not exist. assert not SettingsGroup.query.count() assert not Setting.query.count() updated = update_settings_from_fixture(settings_fixture) assert len(updated) == SettingsGroup.query.count() # force-overwrite - the fixtures exist, but they will be overwritten now. force_updated = update_settings_from_fixture(settings_fixture, overwrite_group=True, overwrite_setting=True) assert len(force_updated) == SettingsGroup.query.count() updated_fixture = (('general', { 'name': "General Settings", 'description': "How many items per page are displayed.", 'settings': (('project_title', { 'value': "FlaskBB", 'value_type': "string", 'name': "Project title", 'description': "The title of the project.", }), ('test_fixture', { 'description': 'This is a test fixture', 'name': 'Test Fixture', 'value': 'FlaskBBTest', 'value_type': 'string' })) }), ) updated = update_settings_from_fixture(updated_fixture) assert len(updated) == 1
def update(settings=None, force=False): """Updates the settings via a fixture. All fixtures have to be placed in the `fixture`. Usage: python manage.py update -s your_fixture """ try: fixture = import_string( "flaskbb.fixtures.{}".format(settings) ) fixture = fixture.fixture except ImportError: raise "{} fixture is not available".format(settings) if force: count = update_settings_from_fixture(fixture, overwrite_group=True, overwrite_setting=True) app.logger.info( "{} groups and {} settings forcefully updated." .format(count[0], count[1]) ) else: count = update_settings_from_fixture(fixture) app.logger.info( "{} groups and {} settings updated.".format(count[0], count[1]) )
def update(settings=None, force=False): """Updates the settings via a fixture. All fixtures have to be placed in the `fixture`. Usage: python manage.py update -s your_fixture """ if settings is None: settings = "settings" try: fixture = import_string( "flaskbb.fixtures.{}".format(settings) ) fixture = fixture.fixture except ImportError: raise "{} fixture is not available".format(settings) overwrite_group = overwrite_setting = False if force: overwrite_group = overwrite_setting = True count = update_settings_from_fixture( fixture=fixture, overwrite_group=overwrite_group, overwrite_setting=overwrite_setting ) print("{} groups and {} settings updated.".format( len(count.keys()), len(count.values())) )
def upgrade(all_latest, fixture, force): """Updates the migrations and fixtures.""" if all_latest: click.secho("[+] Upgrading migrations to the latest version...", fg="cyan") alembic.upgrade() if fixture or all_latest: try: settings = import_string("flaskbb.fixtures.{}".format(fixture)) settings = settings.fixture except ImportError: raise FlaskBBCLIError( "{} fixture is not available".format(fixture), fg="red") click.secho("[+] Updating fixtures...", fg="cyan") count = update_settings_from_fixture(fixture=settings, overwrite_group=force, overwrite_setting=force) click.secho("[+] {settings} settings in {groups} setting groups " "updated.".format(groups=len(count), settings=sum( len(settings) for settings in count.values())), fg="green")
def upgrade(all_latest, fixture, force): """Updates the migrations and fixtures.""" if all_latest: click.secho("[+] Upgrading migrations to the latest version...", fg="cyan") alembic.upgrade() if fixture or all_latest: try: settings = import_string( "flaskbb.fixtures.{}".format(fixture) ) settings = settings.fixture except ImportError: raise FlaskBBCLIError("{} fixture is not available" .format(fixture), fg="red") click.secho("[+] Updating fixtures...", fg="cyan") count = update_settings_from_fixture( fixture=settings, overwrite_group=force, overwrite_setting=force ) click.secho("[+] {settings} settings in {groups} setting groups " "updated.".format(groups=len(count), settings=sum( len(settings) for settings in count.values()) ), fg="green")
def test_update_settings_from_fixture_overwrite(database, default_settings, updated_fixture): # should add groups: testgroup # should add testgroup/monty_python, general/test_fixture pre_update_group_count = SettingsGroup.query.count() pre_update_setting_count = Setting.query.count() updated = update_settings_from_fixture(updated_fixture) assert len(updated) == 2 assert _individual_settings(updated) == 2 assert pre_update_group_count + 1 == SettingsGroup.query.count() assert pre_update_setting_count + 2 == Setting.query.count()
def test_update_settings_from_fixture_force(database, default_settings, updated_fixture): # force-overwrite - nothing changed so nothing should happen here pre_update_group_count = SettingsGroup.query.count() pre_update_setting_count = Setting.query.count() force_updated = update_settings_from_fixture(settings_fixture, overwrite_group=True, overwrite_setting=True) assert len(force_updated) == 0 assert _individual_settings(force_updated) == 0 assert pre_update_group_count == SettingsGroup.query.count() assert pre_update_setting_count == Setting.query.count() # should update groups: general # should update settings: 2 in general, 1 in testgroup force_updated_1 = update_settings_from_fixture(updated_fixture, overwrite_group=True, overwrite_setting=True) assert len(force_updated_1) == 2 assert _individual_settings(force_updated_1) == 3 assert pre_update_group_count + 1 == SettingsGroup.query.count() assert pre_update_setting_count + 2 == Setting.query.count()
def test_update_settings_from_fixture(database): # No force-overwrite - the fixtures will be created because # do not exist. assert not SettingsGroup.query.count() assert not Setting.query.count() updated = update_settings_from_fixture(settings_fixture) assert len(updated) == SettingsGroup.query.count() # force-overwrite - the fixtures exist, but they will be overwritten now. force_updated = update_settings_from_fixture(settings_fixture, overwrite_group=True, overwrite_setting=True) assert len(force_updated) == SettingsGroup.query.count() updated_fixture = ( ('general', { 'name': "General Settings", 'description': "How many items per page are displayed.", 'settings': ( ('project_title', { 'value': "FlaskBB", 'value_type': "string", 'name': "Project title", 'description': "The title of the project.", }), ('test_fixture', { 'description': 'This is a test fixture', 'name': 'Test Fixture', 'value': 'FlaskBBTest', 'value_type': 'string' }) ) }), ) updated = update_settings_from_fixture(updated_fixture) assert len(updated) == 1
def test_update_settings_from_fixture(database): settings_fixture_group_count = len(settings_fixture) settings_fixture_setting_count = sum( len(settings_fixture[k][1]['settings']) for k in range(len(settings_fixture))) assert not SettingsGroup.query.count() assert not Setting.query.count() # No force-overwrite - the fixtures will be created because they # do not exist. updated = update_settings_from_fixture(settings_fixture) assert settings_fixture_group_count == len(updated) assert settings_fixture_group_count == SettingsGroup.query.count() assert settings_fixture_setting_count == _individual_settings(updated) assert settings_fixture_setting_count == Setting.query.count()
def test_update_settings_from_fixture(database): settings_fixture_group_count = len(settings_fixture) settings_fixture_setting_count = sum( len(settings_fixture[k][1]['settings']) for k in range(len(settings_fixture)) ) assert not SettingsGroup.query.count() assert not Setting.query.count() # No force-overwrite - the fixtures will be created because they # do not exist. updated = update_settings_from_fixture(settings_fixture) assert settings_fixture_group_count == len(updated) assert settings_fixture_group_count == SettingsGroup.query.count() assert settings_fixture_setting_count == _individual_settings(updated) assert settings_fixture_setting_count == Setting.query.count()