@@ -269,96 +269,113 @@ class _BaseTestApi(object):
self._compare_ok(id_, expected, given=response.body)
def test_api_get_user_with_giving_userid_non_admin(self):
id_, params = _build_data(self.apikey_regular, 'get_user',
userid=self.TEST_USER_LOGIN)
response = api_call(self, params)
expected = 'userid is not the same as your user'
self._compare_error(id_, expected, given=response.body)
def test_api_pull_remote(self):
repo_name = u'test_pull'
r = fixture.create_repo(repo_name, repo_type=self.REPO_TYPE)
r.clone_uri = os.path.join(Ui.get_by_key('paths', '/').ui_value, self.REPO)
Session().commit()
id_, params = _build_data(self.apikey, 'pull',
repoid=repo_name,)
expected = {'msg': 'Pulled from `%s`' % repo_name,
'repository': repo_name}
fixture.destroy_repo(repo_name)
def test_api_pull_fork(self):
fork_name = u'fork'
fixture.create_fork(self.REPO, fork_name)
repoid=fork_name,)
expected = {'msg': 'Pulled from `%s`' % fork_name,
'repository': fork_name}
fixture.destroy_repo(fork_name)
def test_api_pull_error_no_remote_no_fork(self):
# should fail because no clone_uri is set
repoid=self.REPO, )
expected = 'Unable to pull changes from `%s`' % self.REPO
def test_api_pull_custom_remote(self):
repo_name = u'test_pull_custom_remote'
fixture.create_repo(repo_name, repo_type=self.REPO_TYPE)
custom_remote_path = os.path.join(Ui.get_by_key('paths', '/').ui_value, self.REPO)
repoid=repo_name,
clone_uri=custom_remote_path)
def test_api_rescan_repos(self):
id_, params = _build_data(self.apikey, 'rescan_repos')
expected = {'added': [], 'removed': []}
@mock.patch.object(ScmModel, 'repo_scan', crash)
def test_api_rescann_error(self):
id_, params = _build_data(self.apikey, 'rescan_repos', )
expected = 'Error occurred during rescan repositories action'
def test_api_invalidate_cache(self):
repo = RepoModel().get_by_repo_name(self.REPO)
repo.scm_instance_cached() # seed cache
id_, params = _build_data(self.apikey, 'invalidate_cache',
repoid=self.REPO)
expected = {
'msg': "Cache for repository `%s` was invalidated" % (self.REPO,),
'repository': self.REPO
}
@mock.patch.object(ScmModel, 'mark_for_invalidation', crash)
def test_api_invalidate_cache_error(self):
expected = 'Error occurred during cache invalidation action'
def test_api_invalidate_cache_regular_user_no_permission(self):
id_, params = _build_data(self.apikey_regular, 'invalidate_cache',
expected = "repository `%s` does not exist" % (self.REPO,)
Status change: