##// END OF EJS Templates
bugfix: fixed #3965 and updated a bunch of api tests which...
dan -
r68:36f83786 default
parent child Browse files
Show More
@@ -24,67 +24,84 b' import pytest'
24 24 from rhodecode.model.repo import RepoModel
25 25 from rhodecode.tests import TEST_USER_ADMIN_LOGIN, TEST_USER_REGULAR_LOGIN
26 26 from rhodecode.api.tests.utils import (
27 build_data, api_call, assert_error, assert_ok, crash)
27 build_data, api_call, assert_error, assert_ok, crash, jsonify)
28 28 from rhodecode.tests.fixture import Fixture
29 29
30 30
31 31 fixture = Fixture()
32 32
33 UPDATE_REPO_NAME = 'api_update_me'
34
35 class SAME_AS_UPDATES(object): """ Constant used for tests below """
33 36
34 37 @pytest.mark.usefixtures("testuser_api", "app")
35 38 class TestApiUpdateRepo(object):
36 @pytest.mark.parametrize("changing_attr, updates", [
37 ('owner', {'owner': TEST_USER_REGULAR_LOGIN}),
38 ('description', {'description': 'new description'}),
39 ('active', {'active': True}),
40 ('active', {'active': False}),
41 ('clone_uri', {'clone_uri': 'http://foo.com/repo'}),
42 ('clone_uri', {'clone_uri': None}),
43 ('landing_rev', {'landing_rev': 'branch:master'}),
44 ('enable_statistics', {'enable_statistics': True}),
45 ('enable_locking', {'enable_locking': True}),
46 ('enable_downloads', {'enable_downloads': True}),
47 ('name', {'name': 'new_repo_name'}),
48 ('repo_group', {'group': 'test_group_for_update'}),
39
40 @pytest.mark.parametrize("changing_attr, updates, expected", [
41 ('owner', {'owner': TEST_USER_REGULAR_LOGIN}, SAME_AS_UPDATES),
42 ('description', {'description': 'new description'}, SAME_AS_UPDATES),
43 ('clone_uri', {'clone_uri': 'http://foo.com/repo'}, SAME_AS_UPDATES),
44 ('clone_uri', {'clone_uri': None}, {'clone_uri': ''}),
45 ('clone_uri', {'clone_uri': ''}, {'clone_uri': ''}),
46 ('landing_rev', {'landing_rev': 'branch:master'},
47 {'landing_rev': ['branch', 'master']}),
48 ('enable_statistics', {'enable_statistics': True}, SAME_AS_UPDATES),
49 ('enable_locking', {'enable_locking': True}, SAME_AS_UPDATES),
50 ('enable_downloads', {'enable_downloads': True}, SAME_AS_UPDATES),
51 ('name', {'name': 'new_repo_name'},
52 {'repo_name': 'new_repo_name'}),
53 ('repo_group',
54 {'group': 'test_group_for_update'},
55 {'repo_name': 'test_group_for_update/%s' % UPDATE_REPO_NAME}),
49 56 ])
50 def test_api_update_repo(self, changing_attr, updates, backend):
51 repo_name = 'api_update_me'
57 def test_api_update_repo(self, changing_attr, updates, expected, backend):
58 repo_name = UPDATE_REPO_NAME
52 59 repo = fixture.create_repo(repo_name, repo_type=backend.alias)
53 60 if changing_attr == 'repo_group':
54 61 fixture.create_repo_group(updates['group'])
55 62
63 expected_api_data = repo.get_api_data(include_secrets=True)
64 if expected is SAME_AS_UPDATES:
65 expected_api_data.update(updates)
66 else:
67 expected_api_data.update(expected)
68
69
56 70 id_, params = build_data(
57 71 self.apikey, 'update_repo', repoid=repo_name, **updates)
58 72 response = api_call(self.app, params)
73
59 74 if changing_attr == 'name':
60 75 repo_name = updates['name']
61 76 if changing_attr == 'repo_group':
62 77 repo_name = '/'.join([updates['group'], repo_name])
78
63 79 try:
64 80 expected = {
65 81 'msg': 'updated repo ID:%s %s' % (repo.repo_id, repo_name),
66 'repository': repo.get_api_data(include_secrets=True)
82 'repository': jsonify(expected_api_data)
67 83 }
68 84 assert_ok(id_, expected, given=response.body)
69 85 finally:
70 86 fixture.destroy_repo(repo_name)
71 87 if changing_attr == 'repo_group':
72
73 88 fixture.destroy_repo_group(updates['group'])
74 89
75 90 def test_api_update_repo_fork_of_field(self, backend):
76 91 master_repo = backend.create_repo()
77 92 repo = backend.create_repo()
78
79 93 updates = {
80 94 'fork_of': master_repo.repo_name
81 95 }
96 expected_api_data = repo.get_api_data(include_secrets=True)
97 expected_api_data.update(updates)
98
82 99 id_, params = build_data(
83 100 self.apikey, 'update_repo', repoid=repo.repo_name, **updates)
84 101 response = api_call(self.app, params)
85 102 expected = {
86 103 'msg': 'updated repo ID:%s %s' % (repo.repo_id, repo.repo_name),
87 'repository': repo.get_api_data(include_secrets=True)
104 'repository': jsonify(expected_api_data)
88 105 }
89 106 assert_ok(id_, expected, given=response.body)
90 107 result = response.json['result']['repository']
@@ -131,7 +148,7 b' class TestApiUpdateRepo(object):'
131 148
132 149 @mock.patch.object(RepoModel, 'update', crash)
133 150 def test_api_update_repo_exception_occurred(self, backend):
134 repo_name = 'api_update_me'
151 repo_name = UPDATE_REPO_NAME
135 152 fixture.create_repo(repo_name, repo_type=backend.alias)
136 153 id_, params = build_data(
137 154 self.apikey, 'update_repo', repoid=repo_name,
@@ -25,7 +25,7 b' from rhodecode.model.user import UserMod'
25 25 from rhodecode.model.user_group import UserGroupModel
26 26 from rhodecode.tests import TEST_USER_REGULAR_LOGIN
27 27 from rhodecode.api.tests.utils import (
28 build_data, api_call, assert_error, assert_ok, crash)
28 build_data, api_call, assert_error, assert_ok, crash, jsonify)
29 29
30 30
31 31 @pytest.mark.usefixtures("testuser_api", "app")
@@ -40,14 +40,18 b' class TestUpdateUserGroup(object):'
40 40 def test_api_update_user_group(self, changing_attr, updates, user_util):
41 41 user_group = user_util.create_user_group()
42 42 group_name = user_group.users_group_name
43 expected_api_data = user_group.get_api_data()
44 expected_api_data.update(updates)
45
43 46 id_, params = build_data(
44 47 self.apikey, 'update_user_group', usergroupid=group_name,
45 48 **updates)
46 49 response = api_call(self.app, params)
50
47 51 expected = {
48 52 'msg': 'updated user group ID:%s %s' % (
49 53 user_group.users_group_id, user_group.users_group_name),
50 'user_group': user_group.get_api_data()
54 'user_group': jsonify(expected_api_data)
51 55 }
52 56 assert_ok(id_, expected, given=response.body)
53 57
@@ -63,6 +67,10 b' class TestUpdateUserGroup(object):'
63 67 self, changing_attr, updates, user_util):
64 68 user_group = user_util.create_user_group()
65 69 group_name = user_group.users_group_name
70 expected_api_data = user_group.get_api_data()
71 expected_api_data.update(updates)
72
73
66 74 # grant permission to this user
67 75 user = UserModel().get_by_username(self.TEST_USER_LOGIN)
68 76
@@ -75,7 +83,7 b' class TestUpdateUserGroup(object):'
75 83 expected = {
76 84 'msg': 'updated user group ID:%s %s' % (
77 85 user_group.users_group_id, user_group.users_group_name),
78 'user_group': user_group.get_api_data()
86 'user_group': jsonify(expected_api_data)
79 87 }
80 88 assert_ok(id_, expected, given=response.body)
81 89
@@ -799,6 +799,7 b' def remove_field_from_repo(request, apiu'
799 799 def update_repo(request, apiuser, repoid, name=Optional(None),
800 800 owner=Optional(OAttr('apiuser')),
801 801 group=Optional(None),
802 active=Optional(True),
802 803 fork_of=Optional(None),
803 804 description=Optional(''), private=Optional(False),
804 805 clone_uri=Optional(None), landing_rev=Optional('rev:tip'),
@@ -873,6 +874,7 b' def update_repo(request, apiuser, repoid'
873 874 store_update(updates, repo_group, 'repo_group')
874 875 store_update(updates, repo_fork_of, 'fork_id')
875 876 store_update(updates, owner, 'user')
877 store_update(updates, active, 'active')
876 878 store_update(updates, description, 'repo_description')
877 879 store_update(updates, private, 'repo_private')
878 880 store_update(updates, clone_uri, 'clone_uri')
@@ -1593,7 +1593,7 b' class Repository(Base, BaseModel):'
1593 1593 'repo_id': repo.repo_id,
1594 1594 'repo_name': repo.repo_name,
1595 1595 'repo_type': repo.repo_type,
1596 'clone_uri': repo.clone_uri,
1596 'clone_uri': repo.clone_uri or '',
1597 1597 'private': repo.private,
1598 1598 'created_on': repo.created_on,
1599 1599 'description': repo.description,
@@ -216,7 +216,13 b' class UserGroupModel(BaseModel):'
216 216 if 'user' in form_data:
217 217 owner = form_data['user']
218 218 if isinstance(owner, basestring):
219 user_group.user = User.get_by_username(form_data['user'])
219 owner = User.get_by_username(form_data['user'])
220
221 if not isinstance(owner, User):
222 raise ValueError(
223 'invalid owner for user group: %s' % form_data['user'])
224
225 user_group.user = owner
220 226
221 227 if 'users_group_members' in form_data:
222 228 members_id_list = self._clean_members_data(
General Comments 0
You need to be logged in to leave comments. Login now