Show More
@@ -44,8 +44,9 b" SOCIAL_PLUGINS_LIST = ['github', 'bitbuc" | |||||
44 |
|
44 | |||
45 |
|
45 | |||
46 | class SettingNotFound(Exception): |
|
46 | class SettingNotFound(Exception): | |
47 | def __init__(self): |
|
47 | def __init__(self, setting_id): | |
48 | super(SettingNotFound, self).__init__('Setting is not found') |
|
48 | msg = 'Setting `{}` is not found'.format(setting_id) | |
|
49 | super(SettingNotFound, self).__init__(msg) | |||
49 |
|
50 | |||
50 |
|
51 | |||
51 | class SettingsModel(BaseModel): |
|
52 | class SettingsModel(BaseModel): | |
@@ -155,7 +156,7 b' class SettingsModel(BaseModel):' | |||||
155 | def delete_ui(self, id_): |
|
156 | def delete_ui(self, id_): | |
156 | ui = self.UiDbModel.get(id_) |
|
157 | ui = self.UiDbModel.get(id_) | |
157 | if not ui: |
|
158 | if not ui: | |
158 | raise SettingNotFound() |
|
159 | raise SettingNotFound(id_) | |
159 | Session().delete(ui) |
|
160 | Session().delete(ui) | |
160 |
|
161 | |||
161 | def get_setting_by_name(self, name): |
|
162 | def get_setting_by_name(self, name): | |
@@ -635,7 +636,13 b' class VcsSettingsModel(object):' | |||||
635 |
|
636 | |||
636 | @assert_repo_settings |
|
637 | @assert_repo_settings | |
637 | def delete_repo_svn_pattern(self, id_): |
|
638 | def delete_repo_svn_pattern(self, id_): | |
638 |
self.repo_settings.delet |
|
639 | ui = self.repo_settings.UiDbModel.get(id_) | |
|
640 | if ui and ui.repository.repo_name == self.repo_settings.repo: | |||
|
641 | # only delete if it's the same repo as initialized settings | |||
|
642 | self.repo_settings.delete_ui(id_) | |||
|
643 | else: | |||
|
644 | # raise error as if we wouldn't find this option | |||
|
645 | self.repo_settings.delete_ui(-1) | |||
639 |
|
646 | |||
640 | def delete_global_svn_pattern(self, id_): |
|
647 | def delete_global_svn_pattern(self, id_): | |
641 | self.global_settings.delete_ui(id_) |
|
648 | self.global_settings.delete_ui(id_) |
@@ -491,7 +491,7 b' class TestDeleteUiValue(object):' | |||||
491 | model = SettingsModel() |
|
491 | model = SettingsModel() | |
492 | with pytest.raises(SettingNotFound) as exc_info: |
|
492 | with pytest.raises(SettingNotFound) as exc_info: | |
493 | model.delete_ui(id_) |
|
493 | model.delete_ui(id_) | |
494 | assert exc_info.value.message == 'Setting is not found' |
|
494 | assert exc_info.value.message == 'Setting `{}` is not found'.format(id_) | |
495 |
|
495 | |||
496 | def test_delete_ui_when_repo_is_not_set(self, settings_util): |
|
496 | def test_delete_ui_when_repo_is_not_set(self, settings_util): | |
497 | model = SettingsModel() |
|
497 | model = SettingsModel() |
@@ -635,13 +635,24 b' class TestCreateOrUpdateGlobalGitSetting' | |||||
635 |
|
635 | |||
636 |
|
636 | |||
637 | class TestDeleteRepoSvnPattern(object): |
|
637 | class TestDeleteRepoSvnPattern(object): | |
638 | def test_success_when_repo_is_set(self, backend_svn): |
|
638 | def test_success_when_repo_is_set(self, backend_svn, settings_util): | |
|
639 | repo = backend_svn.create_repo() | |||
|
640 | repo_name = repo.repo_name | |||
|
641 | ||||
|
642 | model = VcsSettingsModel(repo=repo_name) | |||
|
643 | entry = settings_util.create_repo_rhodecode_ui( | |||
|
644 | repo, VcsSettingsModel.SVN_BRANCH_SECTION, 'svn-branch') | |||
|
645 | Session().commit() | |||
|
646 | ||||
|
647 | model.delete_repo_svn_pattern(entry.ui_id) | |||
|
648 | ||||
|
649 | def test_fail_when_delete_id_from_other_repo(self, backend_svn): | |||
639 | repo_name = backend_svn.repo_name |
|
650 | repo_name = backend_svn.repo_name | |
640 | model = VcsSettingsModel(repo=repo_name) |
|
651 | model = VcsSettingsModel(repo=repo_name) | |
641 | delete_ui_patch = mock.patch.object(model.repo_settings, 'delete_ui') |
|
652 | delete_ui_patch = mock.patch.object(model.repo_settings, 'delete_ui') | |
642 | with delete_ui_patch as delete_ui_mock: |
|
653 | with delete_ui_patch as delete_ui_mock: | |
643 | model.delete_repo_svn_pattern(123) |
|
654 | model.delete_repo_svn_pattern(123) | |
644 |
delete_ui_mock.assert_called_once_with(1 |
|
655 | delete_ui_mock.assert_called_once_with(-1) | |
645 |
|
656 | |||
646 | def test_raises_exception_when_repository_is_not_specified(self): |
|
657 | def test_raises_exception_when_repository_is_not_specified(self): | |
647 | model = VcsSettingsModel() |
|
658 | model = VcsSettingsModel() |
General Comments 0
You need to be logged in to leave comments.
Login now