def test_api_create_gist(self, lifetime, gist_type, gist_acl_level): id_, params = build_data(self.apikey_regular, 'create_gist', lifetime=lifetime, description='foobar-gist', gist_type=gist_type, acl_level=gist_acl_level, files={'foobar': { 'content': 'foo' }}) response = api_call(self.app, params) response_json = response.json gist = response_json['result']['gist'] expected = { 'gist': { 'access_id': gist['access_id'], 'created_on': gist['created_on'], 'modified_at': gist['modified_at'], 'description': 'foobar-gist', 'expires': gist['expires'], 'gist_id': gist['gist_id'], 'type': gist_type, 'url': gist['url'], # content is empty since we don't show it here 'content': None, 'acl_level': gist_acl_level, }, 'msg': 'created new gist' } try: assert_ok(id_, expected, given=response.body) finally: Fixture().destroy_gists()
def repos(request, pylonsapp): """Create a copy of each test repo in a repo group.""" fixture = Fixture() repo_group = fixture.create_repo_group(REPO_GROUP) repo_group_id = repo_group.group_id fixture.create_fork(HG_REPO, HG_REPO, repo_name_full=HG_REPO_WITH_GROUP, repo_group=repo_group_id) fixture.create_fork(GIT_REPO, GIT_REPO, repo_name_full=GIT_REPO_WITH_GROUP, repo_group=repo_group_id) @request.addfinalizer def cleanup(): fixture.destroy_repo(HG_REPO_WITH_GROUP) fixture.destroy_repo(GIT_REPO_WITH_GROUP) fixture.destroy_repo_group(repo_group_id)
import functools from rhodecode.tests import * from rhodecode.model.repos_group import ReposGroupModel from rhodecode.model.db import RepoGroup from rhodecode.model.meta import Session from nose.tools import with_setup from rhodecode.tests.models.common import _create_project_tree, check_tree_perms, \ _get_perms, _check_expected_count, expected_count, _destroy_project_tree from rhodecode.model.users_group import UserGroupModel from rhodecode.tests.fixture import Fixture fixture = Fixture() test_u2_id = None test_u2_gr_id = None _get_repo_perms = None _get_group_perms = None def permissions_setup_func(group_name='g0', perm='group.read', recursive=True): """ Resets all permissions to perm attribute """ repos_group = RepoGroup.get_by_group_name(group_name=group_name) if not repos_group: raise Exception('Cannot get group %s' % group_name) perms_updates = [[test_u2_gr_id, perm, 'users_group']] ReposGroupModel()._update_permissions(repos_group, perms_updates=perms_updates,
class TestCreateUserGroup(object): fixture = Fixture() def test_api_create_user_group(self): group_name = 'some_new_group' id_, params = build_data(self.apikey, 'create_user_group', group_name=group_name) response = api_call(self.app, params) ret = { 'msg': 'created new user group `%s`' % (group_name, ), 'user_group': jsonify(UserGroupModel().get_by_name(group_name).get_api_data()) } expected = ret assert_ok(id_, expected, given=response.body) self.fixture.destroy_user_group(group_name) def test_api_create_user_group_regular_user(self): group_name = 'some_new_group' usr = UserModel().get_by_username(self.TEST_USER_LOGIN) usr.inherit_default_permissions = False Session().add(usr) UserModel().grant_perm(self.TEST_USER_LOGIN, 'hg.usergroup.create.true') Session().commit() id_, params = build_data(self.apikey_regular, 'create_user_group', group_name=group_name) response = api_call(self.app, params) expected = { 'msg': 'created new user group `%s`' % (group_name, ), 'user_group': jsonify(UserGroupModel().get_by_name(group_name).get_api_data()) } try: assert_ok(id_, expected, given=response.body) finally: self.fixture.destroy_user_group(group_name) UserModel().revoke_perm(self.TEST_USER_LOGIN, 'hg.usergroup.create.true') usr = UserModel().get_by_username(self.TEST_USER_LOGIN) usr.inherit_default_permissions = True Session().add(usr) Session().commit() def test_api_create_user_group_regular_user_no_permission(self): group_name = 'some_new_group' id_, params = build_data(self.apikey_regular, 'create_user_group', group_name=group_name) response = api_call(self.app, params) expected = "Access was denied to this resource." assert_error(id_, expected, given=response.body) def test_api_create_user_group_that_exist(self, user_util): group = user_util.create_user_group() group_name = group.users_group_name id_, params = build_data(self.apikey, 'create_user_group', group_name=group_name) response = api_call(self.app, params) expected = "user group `%s` already exist" % (group_name, ) assert_error(id_, expected, given=response.body) @mock.patch.object(UserGroupModel, 'create', crash) def test_api_create_user_group_exception_occurred(self): group_name = 'exception_happens' id_, params = build_data(self.apikey, 'create_user_group', group_name=group_name) response = api_call(self.app, params) expected = 'failed to create group `%s`' % (group_name, ) assert_error(id_, expected, given=response.body)
import mock import pytest from rhodecode.controllers.files import FilesController from rhodecode.lib import helpers as h from rhodecode.lib.compat import OrderedDict from rhodecode.lib.ext_json import json from rhodecode.lib.vcs import nodes from rhodecode.lib.vcs.conf import settings from rhodecode.tests import ( url, assert_session_flash, assert_not_in_session_flash) from rhodecode.tests.fixture import Fixture from rhodecode.tests.utils import AssertResponse fixture = Fixture() NODE_HISTORY = { 'hg': json.loads(fixture.load_resource('hg_node_history_response.json')), 'git': json.loads(fixture.load_resource('git_node_history_response.json')), 'svn': json.loads(fixture.load_resource('svn_node_history_response.json')), } @pytest.mark.usefixtures("app") class TestFilesController: def test_index(self, backend): response = self.app.get(url( controller='files', action='index', repo_name=backend.repo_name, revision='tip', f_path='/'))