Show More
@@ -1,161 +1,158 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2010-2016 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | import mock |
|
22 | 22 | import pytest |
|
23 | 23 | |
|
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 | 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 | 33 | UPDATE_REPO_NAME = 'api_update_me' |
|
34 | 34 | |
|
35 | 35 | class SAME_AS_UPDATES(object): """ Constant used for tests below """ |
|
36 | 36 | |
|
37 | 37 | @pytest.mark.usefixtures("testuser_api", "app") |
|
38 | 38 | class TestApiUpdateRepo(object): |
|
39 | 39 | |
|
40 |
@pytest.mark.parametrize(" |
|
|
41 |
( |
|
|
42 |
( |
|
|
43 |
( |
|
|
44 |
( |
|
|
45 |
( |
|
|
46 |
( |
|
|
47 | {'landing_rev': ['branch', 'master']}), | |
|
48 |
( |
|
|
49 |
( |
|
|
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'}, | |
|
40 | @pytest.mark.parametrize("updates, expected", [ | |
|
41 | ({'owner': TEST_USER_REGULAR_LOGIN}, SAME_AS_UPDATES), | |
|
42 | ({'description': 'new description'}, SAME_AS_UPDATES), | |
|
43 | ({'clone_uri': 'http://foo.com/repo'}, SAME_AS_UPDATES), | |
|
44 | ({'clone_uri': None}, {'clone_uri': ''}), | |
|
45 | ({'clone_uri': ''}, {'clone_uri': ''}), | |
|
46 | ({'landing_rev': 'branch:master'}, {'landing_rev': ['branch','master']}), | |
|
47 | ({'enable_statistics': True}, SAME_AS_UPDATES), | |
|
48 | ({'enable_locking': True}, SAME_AS_UPDATES), | |
|
49 | ({'enable_downloads': True}, SAME_AS_UPDATES), | |
|
50 | ({'name': 'new_repo_name'}, {'repo_name': 'new_repo_name'}), | |
|
51 | ({'group': 'test_group_for_update'}, | |
|
55 | 52 | {'repo_name': 'test_group_for_update/%s' % UPDATE_REPO_NAME}), |
|
56 | 53 | ]) |
|
57 |
def test_api_update_repo(self |
|
|
54 | def test_api_update_repo(self, updates, expected, backend): | |
|
58 | 55 | repo_name = UPDATE_REPO_NAME |
|
59 | 56 | repo = fixture.create_repo(repo_name, repo_type=backend.alias) |
|
60 |
if |
|
|
57 | if updates.get('group'): | |
|
61 | 58 | fixture.create_repo_group(updates['group']) |
|
62 | 59 | |
|
63 | 60 | expected_api_data = repo.get_api_data(include_secrets=True) |
|
64 | 61 | if expected is SAME_AS_UPDATES: |
|
65 | 62 | expected_api_data.update(updates) |
|
66 | 63 | else: |
|
67 | 64 | expected_api_data.update(expected) |
|
68 | 65 | |
|
69 | 66 | |
|
70 | 67 | id_, params = build_data( |
|
71 | 68 | self.apikey, 'update_repo', repoid=repo_name, **updates) |
|
72 | 69 | response = api_call(self.app, params) |
|
73 | 70 | |
|
74 |
if |
|
|
71 | if updates.get('name'): | |
|
75 | 72 | repo_name = updates['name'] |
|
76 |
if |
|
|
73 | if updates.get('group'): | |
|
77 | 74 | repo_name = '/'.join([updates['group'], repo_name]) |
|
78 | 75 | |
|
79 | 76 | try: |
|
80 | 77 | expected = { |
|
81 | 78 | 'msg': 'updated repo ID:%s %s' % (repo.repo_id, repo_name), |
|
82 | 79 | 'repository': jsonify(expected_api_data) |
|
83 | 80 | } |
|
84 | 81 | assert_ok(id_, expected, given=response.body) |
|
85 | 82 | finally: |
|
86 | 83 | fixture.destroy_repo(repo_name) |
|
87 |
if |
|
|
84 | if updates.get('group'): | |
|
88 | 85 | fixture.destroy_repo_group(updates['group']) |
|
89 | 86 | |
|
90 | 87 | def test_api_update_repo_fork_of_field(self, backend): |
|
91 | 88 | master_repo = backend.create_repo() |
|
92 | 89 | repo = backend.create_repo() |
|
93 | 90 | updates = { |
|
94 | 91 | 'fork_of': master_repo.repo_name |
|
95 | 92 | } |
|
96 | 93 | expected_api_data = repo.get_api_data(include_secrets=True) |
|
97 | 94 | expected_api_data.update(updates) |
|
98 | 95 | |
|
99 | 96 | id_, params = build_data( |
|
100 | 97 | self.apikey, 'update_repo', repoid=repo.repo_name, **updates) |
|
101 | 98 | response = api_call(self.app, params) |
|
102 | 99 | expected = { |
|
103 | 100 | 'msg': 'updated repo ID:%s %s' % (repo.repo_id, repo.repo_name), |
|
104 | 101 | 'repository': jsonify(expected_api_data) |
|
105 | 102 | } |
|
106 | 103 | assert_ok(id_, expected, given=response.body) |
|
107 | 104 | result = response.json['result']['repository'] |
|
108 | 105 | assert result['fork_of'] == master_repo.repo_name |
|
109 | 106 | |
|
110 | 107 | def test_api_update_repo_fork_of_not_found(self, backend): |
|
111 | 108 | master_repo_name = 'fake-parent-repo' |
|
112 | 109 | repo = backend.create_repo() |
|
113 | 110 | updates = { |
|
114 | 111 | 'fork_of': master_repo_name |
|
115 | 112 | } |
|
116 | 113 | id_, params = build_data( |
|
117 | 114 | self.apikey, 'update_repo', repoid=repo.repo_name, **updates) |
|
118 | 115 | response = api_call(self.app, params) |
|
119 | 116 | expected = 'repository `{}` does not exist'.format(master_repo_name) |
|
120 | 117 | assert_error(id_, expected, given=response.body) |
|
121 | 118 | |
|
122 | 119 | def test_api_update_repo_with_repo_group_not_existing(self): |
|
123 | 120 | repo_name = 'admin_owned' |
|
124 | 121 | fixture.create_repo(repo_name) |
|
125 | 122 | updates = {'group': 'test_group_for_update'} |
|
126 | 123 | id_, params = build_data( |
|
127 | 124 | self.apikey, 'update_repo', repoid=repo_name, **updates) |
|
128 | 125 | response = api_call(self.app, params) |
|
129 | 126 | try: |
|
130 | 127 | expected = 'repository group `%s` does not exist' % ( |
|
131 | 128 | updates['group'],) |
|
132 | 129 | assert_error(id_, expected, given=response.body) |
|
133 | 130 | finally: |
|
134 | 131 | fixture.destroy_repo(repo_name) |
|
135 | 132 | |
|
136 | 133 | def test_api_update_repo_regular_user_not_allowed(self): |
|
137 | 134 | repo_name = 'admin_owned' |
|
138 | 135 | fixture.create_repo(repo_name) |
|
139 | 136 | updates = {'active': False} |
|
140 | 137 | id_, params = build_data( |
|
141 | 138 | self.apikey_regular, 'update_repo', repoid=repo_name, **updates) |
|
142 | 139 | response = api_call(self.app, params) |
|
143 | 140 | try: |
|
144 | 141 | expected = 'repository `%s` does not exist' % (repo_name,) |
|
145 | 142 | assert_error(id_, expected, given=response.body) |
|
146 | 143 | finally: |
|
147 | 144 | fixture.destroy_repo(repo_name) |
|
148 | 145 | |
|
149 | 146 | @mock.patch.object(RepoModel, 'update', crash) |
|
150 | 147 | def test_api_update_repo_exception_occurred(self, backend): |
|
151 | 148 | repo_name = UPDATE_REPO_NAME |
|
152 | 149 | fixture.create_repo(repo_name, repo_type=backend.alias) |
|
153 | 150 | id_, params = build_data( |
|
154 | 151 | self.apikey, 'update_repo', repoid=repo_name, |
|
155 | 152 | owner=TEST_USER_ADMIN_LOGIN,) |
|
156 | 153 | response = api_call(self.app, params) |
|
157 | 154 | try: |
|
158 | 155 | expected = 'failed to update repo `%s`' % (repo_name,) |
|
159 | 156 | assert_error(id_, expected, given=response.body) |
|
160 | 157 | finally: |
|
161 | 158 | fixture.destroy_repo(repo_name) |
General Comments 0
You need to be logged in to leave comments.
Login now