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