api: make all tests for API pass

This commit is contained in:
RhodeCode Admin 2023-07-18 09:45:22 +02:00
parent 458caff188
commit e564ec9b32
64 changed files with 39 additions and 111 deletions

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#
@ -129,26 +128,30 @@ class TestCommentPullRequest(object):
assert_ok(id_, expected, response.body)
@pytest.mark.backends("git", "hg")
def test_api_comment_pull_request_change_status_with_specific_commit_id(
def test_api_comment_pull_request_change_status_with_specific_commit_id_and_test_commit(
self, pr_util, no_notifications):
pull_request = pr_util.create_pull_request()
pull_request_id = pull_request.pull_request_id
latest_commit_id = 'test_commit'
# inject additional revision, to fail test the status change on
# non-latest commit
pull_request.revisions = pull_request.revisions + ['test_commit']
id_, params = build_data(
self.apikey, 'comment_pull_request',
message='test-change-of-status-not-allowed',
repoid=pull_request.target_repo.repo_name,
pullrequestid=pull_request.pull_request_id,
status='approved', commit_id=latest_commit_id)
response = api_call(self.app, params)
pull_request = PullRequestModel().get(pull_request_id)
comments = CommentsModel().get_comments(
pull_request.target_repo.repo_id, pull_request=pull_request)
expected = {
'pull_request_id': pull_request.pull_request_id,
'comment_id': None,
'comment_id': comments[-1].comment_id,
'status': {'given': 'approved', 'was_changed': False}
}
assert_ok(id_, expected, response.body)
@ -230,19 +233,6 @@ class TestCommentPullRequest(object):
expected = 'userid is not the same as your user'
assert_error(id_, expected, given=response.body)
@pytest.mark.backends("git", "hg")
def test_api_comment_pull_request_non_admin_with_userid_error(self, pr_util):
pull_request = pr_util.create_pull_request()
id_, params = build_data(
self.apikey_regular, 'comment_pull_request',
repoid=pull_request.target_repo.repo_name,
pullrequestid=pull_request.pull_request_id,
userid=TEST_USER_ADMIN_LOGIN)
response = api_call(self.app, params)
expected = 'userid is not the same as your user'
assert_error(id_, expected, given=response.body)
@pytest.mark.backends("git", "hg")
def test_api_comment_pull_request_wrong_commit_id_error(self, pr_util):
pull_request = pr_util.create_pull_request()
@ -288,7 +278,7 @@ class TestCommentPullRequest(object):
assert message_after_edit == text_form_db
@pytest.mark.backends("git", "hg")
def test_api_edit_comment_wrong_version(self, pr_util):
def test_api_edit_comment_wrong_version_mismatch(self, pr_util):
pull_request = pr_util.create_pull_request()
id_, params = build_data(
@ -302,7 +292,7 @@ class TestCommentPullRequest(object):
message_after_edit = 'just message'
id_, params = build_data(
self.apikey_regular,
self.apikey,
'edit_comment',
comment_id=comment_id,
message=message_after_edit,
@ -333,7 +323,7 @@ class TestCommentPullRequest(object):
version=0,
)
response = api_call(self.app, params)
expected = "comment ({}) can't be changed with empty string".format(comment_id, 1)
expected = f"comment ({comment_id}) can't be changed with empty string"
assert_error(id_, expected, given=response.body)
@pytest.mark.backends("git", "hg")

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#
@ -18,12 +17,9 @@
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
import json
import mock
import pytest
from rhodecode.lib.utils2 import safe_unicode
from rhodecode.lib.vcs import settings
from rhodecode.model.meta import Session
from rhodecode.model.repo import RepoModel
@ -32,6 +28,8 @@ from rhodecode.tests import TEST_USER_ADMIN_LOGIN
from rhodecode.api.tests.utils import (
build_data, api_call, assert_ok, assert_error, crash)
from rhodecode.tests.fixture import Fixture
from rhodecode.lib.ext_json import json
from rhodecode.lib.str_utils import safe_str
fixture = Fixture()
@ -66,7 +64,7 @@ class TestCreateRepo(object):
expected = ret
assert_ok(id_, expected, given=response.body)
repo = RepoModel().get_by_repo_name(safe_unicode(expected_name))
repo = RepoModel().get_by_repo_name(safe_str(expected_name))
assert repo is not None
id_, params = build_data(self.apikey, 'get_repo', repoid=expected_name)
@ -77,7 +75,7 @@ class TestCreateRepo(object):
assert body['result']['enable_locking'] is False
assert body['result']['enable_statistics'] is False
fixture.destroy_repo(safe_unicode(expected_name))
fixture.destroy_repo(safe_str(expected_name))
def test_api_create_restricted_repo_type(self, backend):
repo_name = 'api-repo-type-{0}'.format(backend.alias)

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#
@ -21,6 +20,7 @@
import pytest
from rhodecode.lib.str_utils import safe_bytes
from rhodecode.model.db import Gist
from rhodecode.api.tests.utils import (
build_data, api_call, assert_error, assert_ok)
@ -54,8 +54,8 @@ class TestApiGetGist(object):
def test_api_get_gist_with_content(self, gist_util, http_host_only_stub):
mapping = {
u'filename1.txt': {'content': u'hello world'},
u'filename1ą.txt': {'content': u'hello worldę'}
b'filename1.txt': {'content': b'hello world'},
safe_bytes('filename1ą.txt'): {'content': safe_bytes('hello worldę')}
}
gist = gist_util.create_gist(gist_mapping=mapping)
gist_id = gist.gist_access_id

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#
@ -50,7 +49,7 @@ class TestGetMethod(object):
expected = ['comment_commit',
{'apiuser': '<RequiredType>',
'comment_type': "<Optional:u'note'>",
'comment_type': "<Optional:'note'>",
'commit_id': '<RequiredType>',
'extra_recipients': '<Optional:[]>',
'message': '<RequiredType>',

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#
@ -25,7 +24,8 @@ import urlobject
from rhodecode.api.tests.utils import (
build_data, api_call, assert_error, assert_ok)
from rhodecode.lib import helpers as h
from rhodecode.lib.utils2 import safe_unicode
from rhodecode.lib.str_utils import safe_str
pytestmark = pytest.mark.backends("git", "hg")
@ -50,13 +50,13 @@ class TestGetPullRequest(object):
repo_name=pull_request.target_repo.repo_name,
pull_request_id=pull_request.pull_request_id))
pr_url = safe_unicode(
pr_url = safe_str(
url_obj.with_netloc(http_host_only_stub))
source_url = safe_unicode(
source_url = safe_str(
pull_request.source_repo.clone_url().with_netloc(http_host_only_stub))
target_url = safe_unicode(
target_url = safe_str(
pull_request.target_repo.clone_url().with_netloc(http_host_only_stub))
shadow_url = safe_unicode(
shadow_url = safe_str(
PullRequestModel().get_shadow_clone_url(pull_request))
expected = {

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#
@ -20,12 +19,9 @@
import pytest
import urlobject
from rhodecode.api.tests.utils import (
build_data, api_call, assert_error, assert_ok)
from rhodecode.lib import helpers as h
from rhodecode.lib.utils2 import safe_unicode
pytestmark = pytest.mark.backends("git", "hg")

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#
@ -54,7 +53,7 @@ class TestGetRepoChangeset(object):
details=details,
)
response = api_call(self.app, params)
expected = "commit_id must be a string value got <type 'int'> instead"
expected = "commit_id must be a string value got <class 'int'> instead"
assert_error(id_, expected, given=response.body)
@pytest.mark.parametrize("details", ['basic', 'extended', 'full'])
@ -137,5 +136,5 @@ class TestGetRepoChangeset(object):
details=details,
)
response = api_call(self.app, params)
expected = "commit_id must be a string value got <type 'int'> instead"
expected = "commit_id must be a string value got <class 'int'> instead"
assert_error(id_, expected, given=response.body)

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#
@ -19,12 +18,11 @@
# and proprietary license terms, please see https://rhodecode.com/licenses/
import json
import pytest
from rhodecode.model.user import UserModel
from rhodecode.api.tests.utils import build_data, api_call
from rhodecode.lib.ext_json import json
@pytest.mark.usefixtures("testuser_api", "app")
@ -68,4 +66,4 @@ class TestGetUserGroups(object):
result = json.loads(response.body)
assert result['id'] == id_
assert result['error'] is None
assert sorted(result['result']) == sorted(expected_list)
assert result['result'] == expected_list

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#
@ -112,7 +111,7 @@ class TestMergePullRequest(object):
'merge_status_message': 'This pull request can be automatically merged.',
'possible': True,
'merge_commit_id': pull_request.shadow_merge_ref.commit_id,
'merge_ref': pull_request.shadow_merge_ref._asdict()
'merge_ref': pull_request.shadow_merge_ref.asdict()
}
assert_ok(id_, expected, response.body)
@ -213,7 +212,7 @@ class TestMergePullRequest(object):
'merge_status_message': 'This pull request can be automatically merged.',
'possible': True,
'merge_commit_id': pull_request.shadow_merge_ref.commit_id,
'merge_ref': pull_request.shadow_merge_ref._asdict()
'merge_ref': pull_request.shadow_merge_ref.asdict()
}
assert_ok(id_, expected, response.body)

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#
@ -82,8 +81,8 @@ class TestUpdatePullRequest(object):
def test_api_update_update_commits(self, pr_util, no_notifications):
commits = [
{'message': 'a'},
{'message': 'b', 'added': [FileNode('file_b', 'test_content\n')]},
{'message': 'c', 'added': [FileNode('file_c', 'test_content\n')]},
{'message': 'b', 'added': [FileNode(b'file_b', b'test_content\n')]},
{'message': 'c', 'added': [FileNode(b'file_c', b'test_content\n')]},
]
pull_request = pr_util.create_pull_request(
commits=commits, target_head='a', source_head='b', revisions=['b'])

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#
@ -28,7 +27,8 @@ from rhodecode.lib.vcs.exceptions import RepositoryError
class TestGetCommitOrError(object):
def setup(self):
def setup_method(self):
self.commit_hash = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa10'
@pytest.mark.parametrize("ref", ['ref', '12345', 'a:b:c:d', 'branch:name'])
@ -66,7 +66,8 @@ class TestGetCommitOrError(object):
class TestResolveRefOrError(object):
def setup(self):
def setup_method(self):
self.commit_hash = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa10'
def test_success_with_no_hash_specified(self):
@ -128,7 +129,8 @@ class TestResolveRefOrError(object):
class TestGetRefHash(object):
def setup(self):
def setup_method(self):
self.commit_hash = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa10'
self.bookmark_name = 'test-bookmark'

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2020 RhodeCode GmbH
#
@ -50,7 +49,7 @@ def assert_ok(id_, expected, given):
given = json.loads(given)
if given.get('error'):
err = given['error']
pytest.fail(u"Unexpected ERROR in success response: {}".format(err))
pytest.fail(f"Unexpected ERROR in expected success response: `{err}`")
expected = jsonify({
'id': id_,

View file

@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2011-2020 RhodeCode GmbH
#