@@ -221,192 +221,209 @@ class _BaseTestApi(object):
_users = User.query().filter_by(is_default_user=False) \
.order_by(User.username).all()
for usr in _users:
ret = usr.get_api_data()
ret_all.append(jsonify(ret))
expected = ret_all
self._compare_ok(id_, expected, given=response.body)
def test_api_get_user(self):
id_, params = _build_data(self.apikey, 'get_user',
userid=TEST_USER_ADMIN_LOGIN)
response = api_call(self, params)
usr = User.get_by_username(TEST_USER_ADMIN_LOGIN)
ret['permissions'] = AuthUser(dbuser=usr).permissions
expected = ret
def test_api_get_user_that_does_not_exist(self):
userid='trololo')
expected = "user `%s` does not exist" % 'trololo'
self._compare_error(id_, expected, given=response.body)
def test_api_get_user_without_giving_userid(self):
id_, params = _build_data(self.apikey, 'get_user')
def test_api_get_user_without_giving_userid_non_admin(self):
id_, params = _build_data(self.apikey_regular, 'get_user')
usr = User.get_by_username(self.TEST_USER_LOGIN)
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)
expected = 'userid is not the same as your user'
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,)
def test_api_lock_repo_lock_acquire(self):
id_, params = _build_data(self.apikey, 'lock',
userid=TEST_USER_ADMIN_LOGIN,
repoid=self.REPO,
locked=True)
'repo': self.REPO, 'locked': True,
'locked_since': response.json['result']['locked_since'],
'locked_by': TEST_USER_ADMIN_LOGIN,
'lock_state_changed': True,
'msg': ('User `%s` set lock state for repo `%s` to `%s`'
% (TEST_USER_ADMIN_LOGIN, self.REPO, True))
def test_api_lock_repo_lock_acquire_by_non_admin(self):
repo_name = u'api_delete_me'
fixture.create_repo(repo_name, repo_type=self.REPO_TYPE,
cur_user=self.TEST_USER_LOGIN)
try:
id_, params = _build_data(self.apikey_regular, 'lock',
'repo': repo_name,
'locked': True,
'locked_by': self.TEST_USER_LOGIN,
% (self.TEST_USER_LOGIN, repo_name, True))
finally:
def test_api_lock_repo_lock_acquire_non_admin_with_userid(self):
Status change: