def test_add_issuetracker_patterns(self, autologin_user, backend,
                                       csrf_token, request):
        pattern = 'issuetracker_pat'
        another_pattern = pattern + '1'
        post_url = url('repo_issuetracker_save',
                       repo_name=backend.repo.repo_name)
        post_data = {
            'new_pattern_pattern_0': pattern,
            'new_pattern_url_0': 'url',
            'new_pattern_prefix_0': 'prefix',
            'new_pattern_description_0': 'description',
            'new_pattern_pattern_1': another_pattern,
            'new_pattern_url_1': 'url1',
            'new_pattern_prefix_1': 'prefix1',
            'new_pattern_description_1': 'description1',
            'csrf_token': csrf_token
        }
        self.app.post(post_url, post_data, status=302)
        self.settings_model = IssueTrackerSettingsModel(repo=backend.repo)
        settings = self.settings_model.get_repo_settings()
        self.uid = md5(pattern)
        assert settings[self.uid]['pat'] == pattern
        self.another_uid = md5(another_pattern)
        assert settings[self.another_uid]['pat'] == another_pattern

        @request.addfinalizer
        def cleanup():
            self.settings_model.delete_entries(self.uid)
            self.settings_model.delete_entries(self.another_uid)
    def test_edit_issuetracker_pattern(self, autologin_user, backend,
                                       csrf_token, request):
        entry_key = 'issuetracker_pat_'
        pattern = 'issuetracker_pat2'
        old_pattern = 'issuetracker_pat'
        old_uid = md5(old_pattern)

        sett = SettingsModel(repo=backend.repo).create_or_update_setting(
            entry_key + old_uid, old_pattern, 'unicode')
        Session().add(sett)
        Session().commit()
        post_url = url('repo_issuetracker_save',
                       repo_name=backend.repo.repo_name)
        post_data = {
            'new_pattern_pattern_0': pattern,
            'new_pattern_url_0': 'url',
            'new_pattern_prefix_0': 'prefix',
            'new_pattern_description_0': 'description',
            'uid': old_uid,
            'csrf_token': csrf_token
        }
        self.app.post(post_url, post_data, status=302)
        self.settings_model = IssueTrackerSettingsModel(repo=backend.repo)
        settings = self.settings_model.get_repo_settings()
        self.uid = md5(pattern)
        assert settings[self.uid]['pat'] == pattern
        with pytest.raises(KeyError):
            settings[old_uid]

        @request.addfinalizer
        def cleanup():
            self.settings_model.delete_entries(self.uid)
Beispiel #3
0
 def repo_issuetracker_delete(self, repo_name):
     uid = request.POST.get('uid')
     repo_settings = IssueTrackerSettingsModel(repo=repo_name)
     try:
         repo_settings.delete_entries(uid)
     except Exception:
         h.flash(_('Error occurred during deleting issue tracker entry'),
                 category='error')
     else:
         h.flash(_('Removed issue tracker entry'), category='success')
     return redirect(url('repo_settings_issuetracker', repo_name=repo_name))
Beispiel #4
0
 def test_value_is_not_set_when_repository_is_not_specified(
         self, repo_stub):
     it_model = IssueTrackerSettingsModel()
     it_model.inherit_global_settings = False
     settings_model = SettingsModel(repo=repo_stub.repo_name)
     setting = settings_model.get_setting_by_name(
         IssueTrackerSettingsModel.INHERIT_SETTINGS)
     assert setting is None
     global_setting = it_model.global_settings.get_setting_by_name(
         IssueTrackerSettingsModel.INHERIT_SETTINGS)
     assert global_setting is None
Beispiel #5
0
 def test_value_is_set(self, repo_stub):
     model = IssueTrackerSettingsModel(repo=repo_stub.repo_name)
     model.inherit_global_settings = False
     setting = model.repo_settings.get_setting_by_name(
         IssueTrackerSettingsModel.INHERIT_SETTINGS)
     try:
         assert setting.app_settings_type == 'bool'
         assert setting.app_settings_value is False
     finally:
         Session().delete(setting)
         Session().commit()
Beispiel #6
0
 def test_effective_settings(self, inherit_settings, method):
     model = IssueTrackerSettingsModel()
     expected_result = {'test': 'test'}
     inherit_patch = mock.patch(
         'rhodecode.model.settings.IssueTrackerSettingsModel'
         '.inherit_global_settings', inherit_settings)
     settings_patch = mock.patch.object(model,
                                        method,
                                        return_value=expected_result)
     with inherit_patch, settings_patch as settings_mock:
         result = model.get_settings(cache=True)
     settings_mock.assert_called_once_with(cache=True)
     assert result == expected_result
Beispiel #7
0
    def repo_issuetracker_save(self, repo_name):
        # Save inheritance
        repo_settings = IssueTrackerSettingsModel(repo=repo_name)
        inherited = (
            request.POST.get('inherit_global_issuetracker') == "inherited")
        repo_settings.inherit_global_settings = inherited
        Session().commit()

        form = IssueTrackerPatternsForm()().to_python(request.POST)
        if form:
            self._update_patterns(form, repo_settings)

        h.flash(_('Updated issue tracker entries'), category='success')
        return redirect(url('repo_settings_issuetracker', repo_name=repo_name))
Beispiel #8
0
    def settings_issuetracker_save(self):
        settings_model = IssueTrackerSettingsModel()

        form = IssueTrackerPatternsForm()().to_python(request.POST)
        for uid in form['delete_patterns']:
            settings_model.delete_entries(uid)

        for pattern in form['patterns']:
            for setting, value, type_ in pattern:
                sett = settings_model.create_or_update_setting(
                    setting, value, type_)
                Session().add(sett)

            Session().commit()

        SettingsModel().invalidate_settings_cache()
        h.flash(_('Updated issue tracker entries'), category='success')
        return redirect(url('admin_settings_issuetracker'))
Beispiel #9
0
    def repo_issuetracker(self, repo_name):
        """GET /admin/settings/issue-tracker: All items in the collection"""
        c.active = 'issuetracker'
        c.data = 'data'
        c.repo_info = self._load_repo(repo_name)

        repo = Repository.get_by_repo_name(repo_name)
        c.settings_model = IssueTrackerSettingsModel(repo=repo)
        c.global_patterns = c.settings_model.get_global_settings()
        c.repo_patterns = c.settings_model.get_repo_settings()

        return render('admin/repos/repo_edit.html')
Beispiel #10
0
 def test_get_repo_settings(self, repo_stub):
     model = IssueTrackerSettingsModel(repo=repo_stub.repo_name)
     input_settings = {
         'rhodecode_issuetracker_pat_123': 'pat',
         'rhodecode_issuetracker_url_123': 'url',
         'rhodecode_issuetracker_desc_123': 'desc',
         'rhodecode_issuetracker_pref_123': 'pref',
     }
     expected_result = {
         '123': {
             'desc': 'desc',
             'pat': 'pat',
             'pref': 'pref',
             'url': 'url'
         }
     }
     with mock.patch.object(model, 'repo_settings') as settings_mock:
         get_settings = settings_mock.get_all_settings
         get_settings.return_value = input_settings
         settings_mock.return_value = input_settings
         result = model.get_repo_settings(cache=True)
     get_settings.assert_called_once_with(cache=True)
     assert expected_result == result
    def test_delete_issuetracker_pattern(self, autologin_user, backend,
                                         csrf_token, settings_util):
        repo = backend.create_repo()
        entry_key = 'issuetracker_pat_'
        pattern = 'issuetracker_pat3'
        uid = md5(pattern)
        settings_util.create_repo_rhodecode_setting(repo=backend.repo,
                                                    name=entry_key + uid,
                                                    value=entry_key,
                                                    type_='unicode',
                                                    cleanup=False)

        self.app.post(url('repo_issuetracker_delete',
                          repo_name=backend.repo.repo_name), {
                              '_method': 'delete',
                              'uid': uid,
                              'csrf_token': csrf_token
                          },
                      status=302)
        settings = IssueTrackerSettingsModel(repo=repo).get_repo_settings()
        assert 'rhodecode_%s%s' % (entry_key, uid) not in settings
class TestAdminRepos:
    def test_issuetracker_index(self, autologin_user, backend):
        repo = backend.create_repo()
        response = self.app.get(
            url('repo_settings_issuetracker', repo_name=repo.repo_name))
        assert response.status_code == 200

    def test_add_issuetracker_patterns(self, autologin_user, backend,
                                       csrf_token, request):
        pattern = 'issuetracker_pat'
        another_pattern = pattern + '1'
        post_url = url('repo_issuetracker_save',
                       repo_name=backend.repo.repo_name)
        post_data = {
            'new_pattern_pattern_0': pattern,
            'new_pattern_url_0': 'url',
            'new_pattern_prefix_0': 'prefix',
            'new_pattern_description_0': 'description',
            'new_pattern_pattern_1': another_pattern,
            'new_pattern_url_1': 'url1',
            'new_pattern_prefix_1': 'prefix1',
            'new_pattern_description_1': 'description1',
            'csrf_token': csrf_token
        }
        self.app.post(post_url, post_data, status=302)
        self.settings_model = IssueTrackerSettingsModel(repo=backend.repo)
        settings = self.settings_model.get_repo_settings()
        self.uid = md5(pattern)
        assert settings[self.uid]['pat'] == pattern
        self.another_uid = md5(another_pattern)
        assert settings[self.another_uid]['pat'] == another_pattern

        @request.addfinalizer
        def cleanup():
            self.settings_model.delete_entries(self.uid)
            self.settings_model.delete_entries(self.another_uid)

    def test_edit_issuetracker_pattern(self, autologin_user, backend,
                                       csrf_token, request):
        entry_key = 'issuetracker_pat_'
        pattern = 'issuetracker_pat2'
        old_pattern = 'issuetracker_pat'
        old_uid = md5(old_pattern)

        sett = SettingsModel(repo=backend.repo).create_or_update_setting(
            entry_key + old_uid, old_pattern, 'unicode')
        Session().add(sett)
        Session().commit()
        post_url = url('repo_issuetracker_save',
                       repo_name=backend.repo.repo_name)
        post_data = {
            'new_pattern_pattern_0': pattern,
            'new_pattern_url_0': 'url',
            'new_pattern_prefix_0': 'prefix',
            'new_pattern_description_0': 'description',
            'uid': old_uid,
            'csrf_token': csrf_token
        }
        self.app.post(post_url, post_data, status=302)
        self.settings_model = IssueTrackerSettingsModel(repo=backend.repo)
        settings = self.settings_model.get_repo_settings()
        self.uid = md5(pattern)
        assert settings[self.uid]['pat'] == pattern
        with pytest.raises(KeyError):
            settings[old_uid]

        @request.addfinalizer
        def cleanup():
            self.settings_model.delete_entries(self.uid)

    def test_delete_issuetracker_pattern(self, autologin_user, backend,
                                         csrf_token, settings_util):
        repo = backend.create_repo()
        entry_key = 'issuetracker_pat_'
        pattern = 'issuetracker_pat3'
        uid = md5(pattern)
        settings_util.create_repo_rhodecode_setting(repo=backend.repo,
                                                    name=entry_key + uid,
                                                    value=entry_key,
                                                    type_='unicode',
                                                    cleanup=False)

        self.app.post(url('repo_issuetracker_delete',
                          repo_name=backend.repo.repo_name), {
                              '_method': 'delete',
                              'uid': uid,
                              'csrf_token': csrf_token
                          },
                      status=302)
        settings = IssueTrackerSettingsModel(repo=repo).get_repo_settings()
        assert 'rhodecode_%s%s' % (entry_key, uid) not in settings
Beispiel #13
0
 def test_true_is_returned_when_value_is_not_found(self, repo_stub):
     model = IssueTrackerSettingsModel(repo=repo_stub.repo_name)
     assert model.inherit_global_settings is True
Beispiel #14
0
 def settings_issuetracker_delete(self):
     uid = request.POST.get('uid')
     IssueTrackerSettingsModel().delete_entries(uid)
     h.flash(_('Removed issue tracker entry'), category='success')
     return redirect(url('admin_settings_issuetracker'))
Beispiel #15
0
 def test_get_repo_settings_raise_exception_when_repo_is_not_set(self):
     model = IssueTrackerSettingsModel()
     with pytest.raises(Exception) as exc_info:
         model.get_repo_settings(cache=True)
     assert exc_info.value.message == 'Repository is not specified'
Beispiel #16
0
 def test_value_is_returned(self, repo_stub, settings_util):
     model = IssueTrackerSettingsModel(repo=repo_stub.repo_name)
     settings_util.create_repo_rhodecode_setting(
         repo_stub, IssueTrackerSettingsModel.INHERIT_SETTINGS, False,
         'bool')
     assert model.inherit_global_settings is False
 def cleanup():
     IssueTrackerSettingsModel().delete_entries(self.uid)
Beispiel #18
0
 def test_true_is_returned_when_repository_not_specified(self):
     model = IssueTrackerSettingsModel()
     assert model.inherit_global_settings is True