def test_none_is_returned_when_key_is_not_found(self, repo_stub, settings_util): settings_util.create_repo_rhodecode_ui(repo_stub, 'wrong section', 'wrong value') model = SettingsModel(repo=repo_stub.repo_name) result = model.get_ui_by_key('abcde') assert result is None
def test_delete_ui_when_repo_is_not_set(self, settings_util): model = SettingsModel() result = settings_util.create_rhodecode_ui('section', None, cleanup=False) key = result.ui_key model.delete_ui(result.ui_id) Session().commit() setting = model.get_ui_by_key(key) assert setting is None
def test_ui_settings_are_returned_when_key_is_found(self, settings_util): section = 'test section' value = 'test value' settings_util.create_rhodecode_ui('wrong section', 'wrong value') setting = settings_util.create_rhodecode_ui(section, value) key = setting.ui_key model = SettingsModel() result = model.get_ui_by_key(key) assert result.ui_value == value assert result.ui_section == section assert result.ui_active is True
def test_ui_section_value_is_created(self, repo_stub, additional_kwargs): model = SettingsModel(repo=repo_stub.repo_name) section = 'test section' value = 'test value' result = model.create_ui_section_value(section, value) key = result.ui_key Session().commit() setting = model.get_ui_by_key(key) try: assert setting == result assert isinstance(setting, RepoRhodeCodeUi) finally: Session().delete(result) Session().commit()
def test_ui_section_value_is_created_with_autogenerated_key( self, backend_stub, additional_kwargs): model = SettingsModel() section = 'test section' value = 'test value' result = model.create_ui_section_value(section, value, **additional_kwargs) key = result.ui_key Session().commit() setting = model.get_ui_by_key(key) try: assert setting == result assert isinstance(setting, RhodeCodeUi) finally: Session().delete(result) Session().commit()
def disable_hooks(request, hooks): """Disables the given hooks from the UI settings.""" session = meta.Session() model = SettingsModel() for hook_key in hooks: sett = model.get_ui_by_key(hook_key) sett.ui_active = False session.add(sett) # Invalidate cache ui_settings = session.query(db.RhodeCodeUi).options( caching_query.FromCache('sql_cache_short', 'get_hg_ui_settings')) ui_settings.invalidate() ui_settings = session.query(db.RhodeCodeUi).options( caching_query.FromCache('sql_cache_short', 'get_hook_settings', 'get_hook_settings')) ui_settings.invalidate() @request.addfinalizer def rollback(): session.rollback()
def create_ui_settings(self, repo_store_path): """ Creates ui settings, fills out hooks and disables dotencode """ settings_model = SettingsModel(sa=self.sa) # Build HOOKS hooks = [ (RhodeCodeUi.HOOK_REPO_SIZE, 'python:vcsserver.hooks.repo_size'), # HG (RhodeCodeUi.HOOK_PRE_PULL, 'python:vcsserver.hooks.pre_pull'), (RhodeCodeUi.HOOK_PULL, 'python:vcsserver.hooks.log_pull_action'), (RhodeCodeUi.HOOK_PRE_PUSH, 'python:vcsserver.hooks.pre_push'), (RhodeCodeUi.HOOK_PUSH, 'python:vcsserver.hooks.log_push_action'), ] for key, value in hooks: hook_obj = settings_model.get_ui_by_key(key) hooks2 = hook_obj if hook_obj else RhodeCodeUi() hooks2.ui_section = 'hooks' hooks2.ui_key = key hooks2.ui_value = value self.sa.add(hooks2) # enable largefiles largefiles = RhodeCodeUi() largefiles.ui_section = 'extensions' largefiles.ui_key = 'largefiles' largefiles.ui_value = '' self.sa.add(largefiles) # set default largefiles cache dir, defaults to # /repo location/.cache/largefiles largefiles = RhodeCodeUi() largefiles.ui_section = 'largefiles' largefiles.ui_key = 'usercache' largefiles.ui_value = os.path.join(repo_store_path, '.cache', 'largefiles') self.sa.add(largefiles) # enable hgsubversion disabled by default hgsubversion = RhodeCodeUi() hgsubversion.ui_section = 'extensions' hgsubversion.ui_key = 'hgsubversion' hgsubversion.ui_value = '' hgsubversion.ui_active = False self.sa.add(hgsubversion) # enable hggit disabled by default hggit = RhodeCodeUi() hggit.ui_section = 'extensions' hggit.ui_key = 'hggit' hggit.ui_value = '' hggit.ui_active = False self.sa.add(hggit) # set svn branch defaults branches = ["/branches/*", "/trunk"] tags = ["/tags/*"] for branch in branches: settings_model.create_ui_section_value( RhodeCodeUi.SVN_BRANCH_ID, branch) for tag in tags: settings_model.create_ui_section_value(RhodeCodeUi.SVN_TAG_ID, tag)