##// END OF EJS Templates
api: make all tests for API pass
super-admin -
r5048:a6860778 default
parent child Browse files
Show More
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -129,26 +128,30 b' class TestCommentPullRequest(object):'
129 128 assert_ok(id_, expected, response.body)
130 129
131 130 @pytest.mark.backends("git", "hg")
132 def test_api_comment_pull_request_change_status_with_specific_commit_id(
131 def test_api_comment_pull_request_change_status_with_specific_commit_id_and_test_commit(
133 132 self, pr_util, no_notifications):
134 133 pull_request = pr_util.create_pull_request()
135 134 pull_request_id = pull_request.pull_request_id
136 135 latest_commit_id = 'test_commit'
136
137 137 # inject additional revision, to fail test the status change on
138 138 # non-latest commit
139 139 pull_request.revisions = pull_request.revisions + ['test_commit']
140 140
141 141 id_, params = build_data(
142 142 self.apikey, 'comment_pull_request',
143 message='test-change-of-status-not-allowed',
143 144 repoid=pull_request.target_repo.repo_name,
144 145 pullrequestid=pull_request.pull_request_id,
145 146 status='approved', commit_id=latest_commit_id)
146 147 response = api_call(self.app, params)
147 148 pull_request = PullRequestModel().get(pull_request_id)
149 comments = CommentsModel().get_comments(
150 pull_request.target_repo.repo_id, pull_request=pull_request)
148 151
149 152 expected = {
150 153 'pull_request_id': pull_request.pull_request_id,
151 'comment_id': None,
154 'comment_id': comments[-1].comment_id,
152 155 'status': {'given': 'approved', 'was_changed': False}
153 156 }
154 157 assert_ok(id_, expected, response.body)
@@ -231,19 +234,6 b' class TestCommentPullRequest(object):'
231 234 assert_error(id_, expected, given=response.body)
232 235
233 236 @pytest.mark.backends("git", "hg")
234 def test_api_comment_pull_request_non_admin_with_userid_error(self, pr_util):
235 pull_request = pr_util.create_pull_request()
236 id_, params = build_data(
237 self.apikey_regular, 'comment_pull_request',
238 repoid=pull_request.target_repo.repo_name,
239 pullrequestid=pull_request.pull_request_id,
240 userid=TEST_USER_ADMIN_LOGIN)
241 response = api_call(self.app, params)
242
243 expected = 'userid is not the same as your user'
244 assert_error(id_, expected, given=response.body)
245
246 @pytest.mark.backends("git", "hg")
247 237 def test_api_comment_pull_request_wrong_commit_id_error(self, pr_util):
248 238 pull_request = pr_util.create_pull_request()
249 239 id_, params = build_data(
@@ -288,7 +278,7 b' class TestCommentPullRequest(object):'
288 278 assert message_after_edit == text_form_db
289 279
290 280 @pytest.mark.backends("git", "hg")
291 def test_api_edit_comment_wrong_version(self, pr_util):
281 def test_api_edit_comment_wrong_version_mismatch(self, pr_util):
292 282 pull_request = pr_util.create_pull_request()
293 283
294 284 id_, params = build_data(
@@ -302,7 +292,7 b' class TestCommentPullRequest(object):'
302 292
303 293 message_after_edit = 'just message'
304 294 id_, params = build_data(
305 self.apikey_regular,
295 self.apikey,
306 296 'edit_comment',
307 297 comment_id=comment_id,
308 298 message=message_after_edit,
@@ -333,7 +323,7 b' class TestCommentPullRequest(object):'
333 323 version=0,
334 324 )
335 325 response = api_call(self.app, params)
336 expected = "comment ({}) can't be changed with empty string".format(comment_id, 1)
326 expected = f"comment ({comment_id}) can't be changed with empty string"
337 327 assert_error(id_, expected, given=response.body)
338 328
339 329 @pytest.mark.backends("git", "hg")
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -18,12 +17,9 b''
18 17 # RhodeCode Enterprise Edition, including its added features, Support services,
19 18 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 19
21 import json
22
23 20 import mock
24 21 import pytest
25 22
26 from rhodecode.lib.utils2 import safe_unicode
27 23 from rhodecode.lib.vcs import settings
28 24 from rhodecode.model.meta import Session
29 25 from rhodecode.model.repo import RepoModel
@@ -32,6 +28,8 b' from rhodecode.tests import TEST_USER_AD'
32 28 from rhodecode.api.tests.utils import (
33 29 build_data, api_call, assert_ok, assert_error, crash)
34 30 from rhodecode.tests.fixture import Fixture
31 from rhodecode.lib.ext_json import json
32 from rhodecode.lib.str_utils import safe_str
35 33
36 34
37 35 fixture = Fixture()
@@ -66,7 +64,7 b' class TestCreateRepo(object):'
66 64 expected = ret
67 65 assert_ok(id_, expected, given=response.body)
68 66
69 repo = RepoModel().get_by_repo_name(safe_unicode(expected_name))
67 repo = RepoModel().get_by_repo_name(safe_str(expected_name))
70 68 assert repo is not None
71 69
72 70 id_, params = build_data(self.apikey, 'get_repo', repoid=expected_name)
@@ -77,7 +75,7 b' class TestCreateRepo(object):'
77 75 assert body['result']['enable_locking'] is False
78 76 assert body['result']['enable_statistics'] is False
79 77
80 fixture.destroy_repo(safe_unicode(expected_name))
78 fixture.destroy_repo(safe_str(expected_name))
81 79
82 80 def test_api_create_restricted_repo_type(self, backend):
83 81 repo_name = 'api-repo-type-{0}'.format(backend.alias)
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -21,6 +20,7 b''
21 20
22 21 import pytest
23 22
23 from rhodecode.lib.str_utils import safe_bytes
24 24 from rhodecode.model.db import Gist
25 25 from rhodecode.api.tests.utils import (
26 26 build_data, api_call, assert_error, assert_ok)
@@ -54,8 +54,8 b' class TestApiGetGist(object):'
54 54
55 55 def test_api_get_gist_with_content(self, gist_util, http_host_only_stub):
56 56 mapping = {
57 u'filename1.txt': {'content': u'hello world'},
58 u'filename1ą.txt': {'content': u'hello worldę'}
57 b'filename1.txt': {'content': b'hello world'},
58 safe_bytes('filename1ą.txt'): {'content': safe_bytes('hello worldę')}
59 59 }
60 60 gist = gist_util.create_gist(gist_mapping=mapping)
61 61 gist_id = gist.gist_access_id
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -50,7 +49,7 b' class TestGetMethod(object):'
50 49
51 50 expected = ['comment_commit',
52 51 {'apiuser': '<RequiredType>',
53 'comment_type': "<Optional:u'note'>",
52 'comment_type': "<Optional:'note'>",
54 53 'commit_id': '<RequiredType>',
55 54 'extra_recipients': '<Optional:[]>',
56 55 'message': '<RequiredType>',
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -25,7 +24,8 b' import urlobject'
25 24 from rhodecode.api.tests.utils import (
26 25 build_data, api_call, assert_error, assert_ok)
27 26 from rhodecode.lib import helpers as h
28 from rhodecode.lib.utils2 import safe_unicode
27 from rhodecode.lib.str_utils import safe_str
28
29 29
30 30 pytestmark = pytest.mark.backends("git", "hg")
31 31
@@ -50,13 +50,13 b' class TestGetPullRequest(object):'
50 50 repo_name=pull_request.target_repo.repo_name,
51 51 pull_request_id=pull_request.pull_request_id))
52 52
53 pr_url = safe_unicode(
53 pr_url = safe_str(
54 54 url_obj.with_netloc(http_host_only_stub))
55 source_url = safe_unicode(
55 source_url = safe_str(
56 56 pull_request.source_repo.clone_url().with_netloc(http_host_only_stub))
57 target_url = safe_unicode(
57 target_url = safe_str(
58 58 pull_request.target_repo.clone_url().with_netloc(http_host_only_stub))
59 shadow_url = safe_unicode(
59 shadow_url = safe_str(
60 60 PullRequestModel().get_shadow_clone_url(pull_request))
61 61
62 62 expected = {
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -20,12 +19,9 b''
20 19
21 20
22 21 import pytest
23 import urlobject
24 22
25 23 from rhodecode.api.tests.utils import (
26 24 build_data, api_call, assert_error, assert_ok)
27 from rhodecode.lib import helpers as h
28 from rhodecode.lib.utils2 import safe_unicode
29 25
30 26 pytestmark = pytest.mark.backends("git", "hg")
31 27
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -54,7 +53,7 b' class TestGetRepoChangeset(object):'
54 53 details=details,
55 54 )
56 55 response = api_call(self.app, params)
57 expected = "commit_id must be a string value got <type 'int'> instead"
56 expected = "commit_id must be a string value got <class 'int'> instead"
58 57 assert_error(id_, expected, given=response.body)
59 58
60 59 @pytest.mark.parametrize("details", ['basic', 'extended', 'full'])
@@ -137,5 +136,5 b' class TestGetRepoChangeset(object):'
137 136 details=details,
138 137 )
139 138 response = api_call(self.app, params)
140 expected = "commit_id must be a string value got <type 'int'> instead"
139 expected = "commit_id must be a string value got <class 'int'> instead"
141 140 assert_error(id_, expected, given=response.body)
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -19,12 +18,11 b''
19 18 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 19
21 20
22 import json
23
24 21 import pytest
25 22
26 23 from rhodecode.model.user import UserModel
27 24 from rhodecode.api.tests.utils import build_data, api_call
25 from rhodecode.lib.ext_json import json
28 26
29 27
30 28 @pytest.mark.usefixtures("testuser_api", "app")
@@ -68,4 +66,4 b' class TestGetUserGroups(object):'
68 66 result = json.loads(response.body)
69 67 assert result['id'] == id_
70 68 assert result['error'] is None
71 assert sorted(result['result']) == sorted(expected_list)
69 assert result['result'] == expected_list
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -112,7 +111,7 b' class TestMergePullRequest(object):'
112 111 'merge_status_message': 'This pull request can be automatically merged.',
113 112 'possible': True,
114 113 'merge_commit_id': pull_request.shadow_merge_ref.commit_id,
115 'merge_ref': pull_request.shadow_merge_ref._asdict()
114 'merge_ref': pull_request.shadow_merge_ref.asdict()
116 115 }
117 116
118 117 assert_ok(id_, expected, response.body)
@@ -213,7 +212,7 b' class TestMergePullRequest(object):'
213 212 'merge_status_message': 'This pull request can be automatically merged.',
214 213 'possible': True,
215 214 'merge_commit_id': pull_request.shadow_merge_ref.commit_id,
216 'merge_ref': pull_request.shadow_merge_ref._asdict()
215 'merge_ref': pull_request.shadow_merge_ref.asdict()
217 216 }
218 217
219 218 assert_ok(id_, expected, response.body)
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -82,8 +81,8 b' class TestUpdatePullRequest(object):'
82 81 def test_api_update_update_commits(self, pr_util, no_notifications):
83 82 commits = [
84 83 {'message': 'a'},
85 {'message': 'b', 'added': [FileNode('file_b', 'test_content\n')]},
86 {'message': 'c', 'added': [FileNode('file_c', 'test_content\n')]},
84 {'message': 'b', 'added': [FileNode(b'file_b', b'test_content\n')]},
85 {'message': 'c', 'added': [FileNode(b'file_c', b'test_content\n')]},
87 86 ]
88 87 pull_request = pr_util.create_pull_request(
89 88 commits=commits, target_head='a', source_head='b', revisions=['b'])
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -28,7 +27,8 b' from rhodecode.lib.vcs.exceptions import'
28 27
29 28
30 29 class TestGetCommitOrError(object):
31 def setup(self):
30
31 def setup_method(self):
32 32 self.commit_hash = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa10'
33 33
34 34 @pytest.mark.parametrize("ref", ['ref', '12345', 'a:b:c:d', 'branch:name'])
@@ -66,7 +66,8 b' class TestGetCommitOrError(object):'
66 66
67 67
68 68 class TestResolveRefOrError(object):
69 def setup(self):
69
70 def setup_method(self):
70 71 self.commit_hash = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa10'
71 72
72 73 def test_success_with_no_hash_specified(self):
@@ -128,7 +129,8 b' class TestResolveRefOrError(object):'
128 129
129 130
130 131 class TestGetRefHash(object):
131 def setup(self):
132
133 def setup_method(self):
132 134 self.commit_hash = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa10'
133 135 self.bookmark_name = 'test-bookmark'
134 136
@@ -1,4 +1,3 b''
1 # -*- coding: utf-8 -*-
2 1
3 2 # Copyright (C) 2010-2020 RhodeCode GmbH
4 3 #
@@ -50,7 +49,7 b' def assert_ok(id_, expected, given):'
50 49 given = json.loads(given)
51 50 if given.get('error'):
52 51 err = given['error']
53 pytest.fail(u"Unexpected ERROR in success response: {}".format(err))
52 pytest.fail(f"Unexpected ERROR in expected success response: `{err}`")
54 53
55 54 expected = jsonify({
56 55 'id': id_,
@@ -1,4 +1,4 b''
1 # -*- coding: utf-8 -*-
1
2 2
3 3 # Copyright (C) 2011-2020 RhodeCode GmbH
4 4 #
General Comments 0
You need to be logged in to leave comments. Login now