示例#1
0
 def test_settings_are_filtered(self):
     model = VcsSettingsModel()
     repo_settings = [
         UiSetting('extensions', 'largefiles', '', True),
         UiSetting('phases', 'publish', 'True', True),
         UiSetting('hooks', 'changegroup.repo_size', 'hook', True),
         UiSetting('hooks', 'changegroup.push_logger', 'hook', True),
         UiSetting('hooks', 'outgoing.pull_logger', 'hook', True),
         UiSetting('vcs_svn_branch',
                   '84223c972204fa545ca1b22dac7bef5b68d7442d',
                   'test_branch', True),
         UiSetting('vcs_svn_tag',
                   '84229c972204fa545ca1b22dac7bef5b68d7442d', 'test_tag',
                   True),
     ]
     non_repo_settings = [
         UiSetting('test', 'outgoing.pull_logger', 'hook', True),
         UiSetting('hooks', 'test2', 'hook', True),
         UiSetting('vcs_svn_repo',
                   '84229c972204fa545ca1b22dac7bef5b68d7442d', 'test_tag',
                   True),
     ]
     settings = repo_settings + non_repo_settings
     filtered_settings = model._filter_ui_settings(settings)
     assert sorted(filtered_settings) == sorted(repo_settings)
示例#2
0
 def test_repo_settings_filtered_by_section_and_key(self, repo_stub):
     model = VcsSettingsModel(repo=repo_stub.repo_name)
     model.inherit_global_settings = False
     args = ('section', 'key')
     with mock.patch.object(model, 'get_repo_ui_settings') as settings_mock:
         model.get_ui_settings(*args)
     settings_mock.assert_called_once_with(*args)
示例#3
0
 def test_global_settings_filtered_by_section_and_key(self):
     model = VcsSettingsModel()
     args = ('section', )
     with mock.patch.object(model,
                            'get_global_ui_settings') as (settings_mock):
         model.get_svn_patterns(*args)
     settings_mock.assert_called_once_with(*args)
示例#4
0
 def test_inherit_flag_is_saved(self, repo_stub):
     model = VcsSettingsModel(repo=repo_stub)
     model.inherit_global_settings = True
     with self._patch_model(model):
         model.create_or_update_repo_settings(data=self.FORM_DATA,
                                              inherit_global_settings=False)
     assert model.inherit_global_settings is False
示例#5
0
 def test_success_when_repo_is_set(self, backend_svn):
     repo_name = backend_svn.repo_name
     model = VcsSettingsModel(repo=repo_name)
     delete_ui_patch = mock.patch.object(model.repo_settings, 'delete_ui')
     with delete_ui_patch as delete_ui_mock:
         model.delete_repo_svn_pattern(123)
     delete_ui_mock.assert_called_once_with(123)
示例#6
0
    def repos_path(self):
        """
        Gets the repositories root path from database
        """

        settings_model = VcsSettingsModel(sa=self.sa)
        return settings_model.get_repos_location()
示例#7
0
 def test_no_methods_are_called_when_settings_are_inherited(self, backend):
     repo = backend.create_repo()
     model = VcsSettingsModel(repo=repo)
     with self._patch_model(model) as mocks:
         model.create_or_update_repo_settings(data=self.FORM_DATA,
                                              inherit_global_settings=True)
     for method_name in mocks:
         assert mocks[method_name].call_count == 0
示例#8
0
 def test_calls_create_or_update_general_settings(self, repo_stub):
     model = VcsSettingsModel(repo=repo_stub.repo_name)
     create_patch = mock.patch.object(model,
                                      '_create_or_update_general_settings')
     with create_patch as create_mock:
         model.create_or_update_repo_pr_settings(GENERAL_FORM_DATA)
     create_mock.assert_called_once_with(model.repo_settings,
                                         GENERAL_FORM_DATA)
示例#9
0
 def test_calls_create_or_update_general_settings(self):
     model = VcsSettingsModel()
     create_patch = mock.patch.object(model,
                                      '_create_or_update_general_settings')
     with create_patch as create_mock:
         model.create_or_update_global_pr_settings(GENERAL_FORM_DATA)
     create_mock.assert_called_once_with(model.global_settings,
                                         GENERAL_FORM_DATA)
示例#10
0
 def test_updates_global_path_settings(self):
     model = VcsSettingsModel()
     with mock.patch.object(model, '_create_or_update_ui') as create_mock:
         model.update_global_path_setting('False')
     create_mock.assert_called_once_with(model.global_settings,
                                         'paths',
                                         '/',
                                         value='False')
示例#11
0
    def test_get_repo_settings(self, repo_stub):
        model = VcsSettingsModel(repo=repo_stub.repo_name)
        expected_result = {'test': 'test'}
        with mock.patch.object(model, '_collect_all_settings') as collect_mock:
            collect_mock.return_value = expected_result
            result = model.get_repo_settings()

        collect_mock.assert_called_once_with(global_=False)
        assert result == expected_result
示例#12
0
    def test_get_global_settings(self):
        expected_result = {'test': 'test'}
        model = VcsSettingsModel()
        with mock.patch.object(model, '_collect_all_settings') as collect_mock:
            collect_mock.return_value = expected_result
            result = model.get_global_settings()

        collect_mock.assert_called_once_with(global_=True)
        assert result == expected_result
 def validate_python(self, value, state):
     if not value:
         return
     model = VcsSettingsModel(repo=repo_name)
     ui_settings = model.get_svn_patterns(section=section)
     for entry in ui_settings:
         if value == entry.value:
             msg = M(self, 'pattern_exists', state)
             raise formencode.Invalid(msg, value, state)
示例#14
0
 def test_cache_is_marked_for_invalidation(self, repo_stub):
     model = VcsSettingsModel(repo=repo_stub)
     invalidation_patcher = mock.patch(
         'rhodecode.controllers.admin.repos.ScmModel.mark_for_invalidation')
     with invalidation_patcher as invalidation_mock:
         model.create_or_update_repo_settings(data=self.FORM_DATA,
                                              inherit_global_settings=True)
     invalidation_mock.assert_called_once_with(repo_stub.repo_name,
                                               delete=True)
示例#15
0
 def test_key_is_not_found(self, repo_stub, field_to_remove):
     model = VcsSettingsModel(repo=repo_stub.repo_name)
     data = self.FORM_DATA.copy()
     data.pop(field_to_remove)
     with pytest.raises(Exception) as exc_info:
         model.create_or_update_global_hg_settings(data)
     expected_message = 'The given data does not contain {} key'.format(
         field_to_remove)
     assert exc_info.value.message == expected_message
示例#16
0
 def test_global_uis_are_returned_when_no_repo_uis_found(self, repo_stub):
     model = VcsSettingsModel(repo=repo_stub.repo_name)
     result = model.get_repo_ui_settings()
     svn_sections = (VcsSettingsModel.SVN_TAG_SECTION,
                     VcsSettingsModel.SVN_BRANCH_SECTION)
     expected_result = [
         s for s in model.global_settings.get_ui()
         if s.section not in svn_sections
     ]
     assert sorted(result) == sorted(expected_result)
示例#17
0
    def test_collect_all_settings_without_empty_value(self, settings, global_):
        model = VcsSettingsModel()

        settings_patch = mock.patch.object(model, settings)
        with settings_patch as settings_mock:
            settings_mock.get_ui_by_section_and_key.return_value = None
            settings_mock.get_setting_by_name.return_value = None
            result = model._collect_all_settings(global_=global_)

        assert result == {}
示例#18
0
    def test_create_raises_exception_when_data_incomplete(self, repo_stub):
        model = VcsSettingsModel(repo=repo_stub.repo_name)

        deleted_key = 'rhodecode_pr_merge_enabled'
        data = GENERAL_FORM_DATA.copy()
        data.pop(deleted_key)

        with pytest.raises(ValueError) as exc_info:
            model._create_or_update_general_settings(model.repo_settings, data)
        assert (exc_info.value.message ==
                'The given data does not contain {} key'.format(deleted_key))
示例#19
0
    def test_create_nothing_when_no_svn_settings_specified(self, repo_stub):
        model = VcsSettingsModel(repo=repo_stub.repo_name)
        model._create_svn_settings(model.repo_settings, {})
        Session().commit()

        branch_ui = model.repo_settings.get_ui_by_section(
            model.SVN_BRANCH_SECTION)
        tag_ui = model.repo_settings.get_ui_by_section(model.SVN_TAG_SECTION)

        assert len(branch_ui) == 0
        assert len(tag_ui) == 0
示例#20
0
    def test_repo_svn_branch_patterns(self):
        model = VcsSettingsModel()
        expected_result = {'test': 'test'}
        with mock.patch.object(model, 'repo_settings') as settings_mock:
            get_settings = settings_mock.get_ui_by_section
            get_settings.return_value = expected_result
            settings_mock.return_value = expected_result
            result = model.get_repo_svn_branch_patterns()

        get_settings.assert_called_once_with(model.SVN_BRANCH_SECTION)
        assert expected_result == result
示例#21
0
 def test_repo_uis_are_not_overriding_global_uis(self, repo_stub,
                                                 settings_util):
     for key in VcsSettingsModel.GENERAL_SETTINGS:
         settings_util.create_repo_rhodecode_setting(repo_stub,
                                                     key,
                                                     'abcde',
                                                     type_='unicode')
     model = VcsSettingsModel(repo=repo_stub.repo_name)
     result = model.get_global_general_settings()
     expected_result = model.global_settings.get_all_settings()
     assert sorted(result) == sorted(expected_result)
示例#22
0
 def test_value_is_set(self, repo_stub):
     model = VcsSettingsModel(repo=repo_stub.repo_name)
     model.inherit_global_settings = False
     setting = model.repo_settings.get_setting_by_name(
         VcsSettingsModel.INHERIT_SETTINGS)
     try:
         assert setting.app_settings_type == 'bool'
         assert setting.app_settings_value is False
     finally:
         Session().delete(setting)
         Session().commit()
示例#23
0
    def test_update_raises_exception_when_data_incomplete(self):
        model = VcsSettingsModel()

        deleted_key = 'hooks_changegroup_repo_size'
        data = HOOKS_FORM_DATA.copy()
        data.pop(deleted_key)

        with pytest.raises(ValueError) as exc_info:
            model.update_global_hook_settings(data)
        assert (exc_info.value.message ==
                'The given data does not contain {} key'.format(deleted_key))
示例#24
0
 def test_update_global_hook_settings(self, settings_util):
     model = VcsSettingsModel()
     setting_mock = mock.MagicMock()
     setting_mock.ui_active = False
     get_settings_patcher = mock.patch.object(model.global_settings,
                                              'get_ui_by_section_and_key',
                                              return_value=setting_mock)
     session_patcher = mock.patch('rhodecode.model.settings.Session')
     with get_settings_patcher as get_settings_mock, session_patcher:
         model.update_global_hook_settings(HOOKS_FORM_DATA)
     assert setting_mock.ui_active is True
     assert get_settings_mock.call_count == 3
示例#25
0
    def settings_vcs(self):
        """GET /admin/settings: All items in the collection"""
        # url('admin_settings_vcs')
        c.active = 'vcs'
        model = VcsSettingsModel()
        c.svn_branch_patterns = model.get_global_svn_branch_patterns()
        c.svn_tag_patterns = model.get_global_svn_tag_patterns()

        return htmlfill.render(render('admin/settings/settings.html'),
                               defaults=self._form_defaults(),
                               encoding="UTF-8",
                               force_defaults=False)
示例#26
0
    def test_returns_repos_location(self, repo_stub):
        model = VcsSettingsModel()

        result_mock = mock.Mock()
        result_mock.ui_value = '/tmp'

        with mock.patch.object(model, 'global_settings') as settings_mock:
            settings_mock.get_ui_by_key.return_value = result_mock
            result = model.get_repos_location()

        settings_mock.get_ui_by_key.assert_called_once_with('/')
        assert result == '/tmp'
示例#27
0
    def test_update_when_repo_setting_found(self, repo_stub, settings_util):
        model = VcsSettingsModel(repo=repo_stub.repo_name)
        for name in model.GENERAL_SETTINGS:
            settings_util.create_repo_rhodecode_setting(
                repo_stub, name, False, 'bool')

        model._create_or_update_general_settings(model.repo_settings,
                                                 GENERAL_FORM_DATA)

        for name in model.GENERAL_SETTINGS:
            setting = model.repo_settings.get_setting_by_name(name)
            assert setting.app_settings_value is True
示例#28
0
 def test_repo_settings_are_returned_when_inherited_is_false(
         self, repo_stub, settings_util):
     model = VcsSettingsModel(repo=repo_stub.repo_name)
     model.inherit_global_settings = False
     for key in VcsSettingsModel.GENERAL_SETTINGS:
         settings_util.create_repo_rhodecode_setting(repo_stub,
                                                     key,
                                                     'abcde',
                                                     type_='unicode')
     result = model.get_general_settings()
     expected_result = model.get_repo_general_settings()
     assert sorted(result) == sorted(expected_result)
示例#29
0
 def test_repo_uis_are_not_overriding_global_uis(self, repo_stub,
                                                 settings_util):
     for section, key in VcsSettingsModel.HOOKS_SETTINGS:
         settings_util.create_repo_rhodecode_ui(repo_stub,
                                                section,
                                                'repo',
                                                key=key,
                                                active=False)
     model = VcsSettingsModel(repo=repo_stub.repo_name)
     result = model.get_global_ui_settings()
     expected_result = model.global_settings.get_ui()
     assert sorted(result) == sorted(expected_result)
示例#30
0
 def test_repo_uis_are_overriding_global_uis(self, repo_stub,
                                             settings_util):
     for key in VcsSettingsModel.GENERAL_SETTINGS:
         settings_util.create_repo_rhodecode_setting(repo_stub,
                                                     key,
                                                     'abcde',
                                                     type_='unicode')
     model = VcsSettingsModel(repo=repo_stub.repo_name)
     result = model.get_repo_ui_settings()
     for key in result:
         if key in VcsSettingsModel.GENERAL_SETTINGS:
             assert result[key] == 'abcde'