core: run ruff format

This commit is contained in:
RhodeCode Admin 2025-01-13 17:47:37 +01:00
parent 7130effb58
commit 166db21812
821 changed files with 82905 additions and 84121 deletions

View file

@ -22,8 +22,7 @@ from rhodecode.model.comment import CommentsModel
from rhodecode.model.db import UserLog, User, ChangesetComment
from rhodecode.model.pull_request import PullRequestModel
from rhodecode.tests import TEST_USER_ADMIN_LOGIN
from rhodecode.api.tests.utils import (
build_data, api_call, assert_error, assert_ok)
from rhodecode.api.tests.utils import build_data, api_call, assert_error, assert_ok
@pytest.mark.usefixtures("testuser_api", "app")
@ -43,29 +42,32 @@ class TestCommentPullRequest(object):
author = pull_request.user_id
repo = pull_request.target_repo.repo_id
id_, params = build_data(
self.apikey, 'comment_pull_request',
self.apikey,
"comment_pull_request",
repoid=pull_request.target_repo.repo_name,
pullrequestid=pull_request.pull_request_id,
message='test message')
message="test message",
)
response = api_call(self.app, params)
pull_request = PullRequestModel().get(pull_request.pull_request_id)
comments = CommentsModel().get_comments(
pull_request.target_repo.repo_id, pull_request=pull_request)
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': comments[-1].comment_id,
'status': {'given': None, 'was_changed': None}
"pull_request_id": pull_request.pull_request_id,
"comment_id": comments[-1].comment_id,
"status": {"given": None, "was_changed": None},
}
assert_ok(id_, expected, response.body)
journal = UserLog.query()\
.filter(UserLog.user_id == author)\
.filter(UserLog.repository_id == repo) \
.order_by(UserLog.user_log_id.asc()) \
journal = (
UserLog.query()
.filter(UserLog.user_id == author)
.filter(UserLog.repository_id == repo)
.order_by(UserLog.user_log_id.asc())
.all()
assert journal[-1].action == 'repo.pull_request.comment.create'
)
assert journal[-1].action == "repo.pull_request.comment.create"
@pytest.mark.backends("git", "hg")
def test_api_comment_pull_request_with_extra_recipients(self, pr_util, user_util):
@ -77,105 +79,109 @@ class TestCommentPullRequest(object):
user2_id = user2.user_id
id_, params = build_data(
self.apikey, 'comment_pull_request',
self.apikey,
"comment_pull_request",
repoid=pull_request.target_repo.repo_name,
pullrequestid=pull_request.pull_request_id,
message='test message',
extra_recipients=[user1.user_id, user2.username]
message="test message",
extra_recipients=[user1.user_id, user2.username],
)
response = api_call(self.app, params)
pull_request = PullRequestModel().get(pull_request.pull_request_id)
comments = CommentsModel().get_comments(
pull_request.target_repo.repo_id, pull_request=pull_request)
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': comments[-1].comment_id,
'status': {'given': None, 'was_changed': None}
"pull_request_id": pull_request.pull_request_id,
"comment_id": comments[-1].comment_id,
"status": {"given": None, "was_changed": None},
}
assert_ok(id_, expected, response.body)
# check user1/user2 inbox for notification
user1 = User.get(user1_id)
assert 1 == len(user1.notifications)
assert 'test message' in user1.notifications[0].notification.body
assert "test message" in user1.notifications[0].notification.body
user2 = User.get(user2_id)
assert 1 == len(user2.notifications)
assert 'test message' in user2.notifications[0].notification.body
assert "test message" in user2.notifications[0].notification.body
@pytest.mark.backends("git", "hg")
def test_api_comment_pull_request_change_status(
self, pr_util, no_notifications):
def test_api_comment_pull_request_change_status(self, pr_util, no_notifications):
pull_request = pr_util.create_pull_request()
pull_request_id = pull_request.pull_request_id
id_, params = build_data(
self.apikey, 'comment_pull_request',
self.apikey,
"comment_pull_request",
repoid=pull_request.target_repo.repo_name,
pullrequestid=pull_request.pull_request_id,
status='rejected')
status="rejected",
)
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)
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': comments[-1].comment_id,
'status': {'given': 'rejected', 'was_changed': True}
"pull_request_id": pull_request.pull_request_id,
"comment_id": comments[-1].comment_id,
"status": {"given": "rejected", "was_changed": True},
}
assert_ok(id_, expected, response.body)
@pytest.mark.backends("git", "hg")
def test_api_comment_pull_request_change_status_with_specific_commit_id_and_test_commit(
self, pr_util, no_notifications):
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'
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']
pull_request.revisions = pull_request.revisions + ["test_commit"]
id_, params = build_data(
self.apikey, 'comment_pull_request',
message='test-change-of-status-not-allowed',
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)
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)
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': comments[-1].comment_id,
'status': {'given': 'approved', 'was_changed': False}
"pull_request_id": pull_request.pull_request_id,
"comment_id": comments[-1].comment_id,
"status": {"given": "approved", "was_changed": False},
}
assert_ok(id_, expected, response.body)
@pytest.mark.backends("git", "hg")
def test_api_comment_pull_request_change_status_with_specific_commit_id(
self, pr_util, no_notifications):
def test_api_comment_pull_request_change_status_with_specific_commit_id(self, pr_util, no_notifications):
pull_request = pr_util.create_pull_request()
pull_request_id = pull_request.pull_request_id
latest_commit_id = pull_request.revisions[0]
id_, params = build_data(
self.apikey, 'comment_pull_request',
self.apikey,
"comment_pull_request",
repoid=pull_request.target_repo.repo_name,
pullrequestid=pull_request.pull_request_id,
status='approved', commit_id=latest_commit_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)
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': comments[-1].comment_id,
'status': {'given': 'approved', 'was_changed': True}
"pull_request_id": pull_request.pull_request_id,
"comment_id": comments[-1].comment_id,
"status": {"given": "approved", "was_changed": True},
}
assert_ok(id_, expected, response.body)
@ -185,12 +191,11 @@ class TestCommentPullRequest(object):
pull_request_id = pull_request.pull_request_id
pull_request_repo = pull_request.target_repo.repo_name
id_, params = build_data(
self.apikey, 'comment_pull_request',
repoid=pull_request_repo,
pullrequestid=pull_request_id)
self.apikey, "comment_pull_request", repoid=pull_request_repo, pullrequestid=pull_request_id
)
response = api_call(self.app, params)
expected = 'Both message and status parameters are missing. At least one is required.'
expected = "Both message and status parameters are missing. At least one is required."
assert_error(id_, expected, given=response.body)
@pytest.mark.backends("git", "hg")
@ -199,51 +204,53 @@ class TestCommentPullRequest(object):
pull_request_id = pull_request.pull_request_id
pull_request_repo = pull_request.target_repo.repo_name
id_, params = build_data(
self.apikey, 'comment_pull_request',
repoid=pull_request_repo,
pullrequestid=pull_request_id,
status='42')
self.apikey, "comment_pull_request", repoid=pull_request_repo, pullrequestid=pull_request_id, status="42"
)
response = api_call(self.app, params)
expected = 'Unknown comment status: `42`'
expected = "Unknown comment status: `42`"
assert_error(id_, expected, given=response.body)
@pytest.mark.backends("git", "hg")
def test_api_comment_pull_request_repo_error(self, pr_util):
pull_request = pr_util.create_pull_request()
id_, params = build_data(
self.apikey, 'comment_pull_request',
repoid=666, pullrequestid=pull_request.pull_request_id)
self.apikey, "comment_pull_request", repoid=666, pullrequestid=pull_request.pull_request_id
)
response = api_call(self.app, params)
expected = 'repository `666` does not exist'
expected = "repository `666` does not exist"
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',
self.apikey_regular,
"comment_pull_request",
repoid=pull_request.target_repo.repo_name,
pullrequestid=pull_request.pull_request_id,
userid=TEST_USER_ADMIN_LOGIN)
userid=TEST_USER_ADMIN_LOGIN,
)
response = api_call(self.app, params)
expected = 'userid is not the same as your user'
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()
id_, params = build_data(
self.apikey_regular, 'comment_pull_request',
self.apikey_regular,
"comment_pull_request",
repoid=pull_request.target_repo.repo_name,
status='approved',
status="approved",
pullrequestid=pull_request.pull_request_id,
commit_id='XXX')
commit_id="XXX",
)
response = api_call(self.app, params)
expected = 'Invalid commit_id `XXX` for this pull request.'
expected = "Invalid commit_id `XXX` for this pull request."
assert_error(id_, expected, given=response.body)
@pytest.mark.backends("git", "hg")
@ -252,26 +259,26 @@ class TestCommentPullRequest(object):
id_, params = build_data(
self.apikey,
'comment_pull_request',
"comment_pull_request",
repoid=pull_request.target_repo.repo_name,
pullrequestid=pull_request.pull_request_id,
message='test message',
message="test message",
)
response = api_call(self.app, params)
json_response = response.json
comment_id = json_response['result']['comment_id']
comment_id = json_response["result"]["comment_id"]
message_after_edit = 'just message'
message_after_edit = "just message"
id_, params = build_data(
self.apikey,
'edit_comment',
"edit_comment",
comment_id=comment_id,
message=message_after_edit,
version=0,
)
response = api_call(self.app, params)
json_response = response.json
assert json_response['result']['version'] == 1
assert json_response["result"]["version"] == 1
text_form_db = ChangesetComment.get(comment_id).text
assert message_after_edit == text_form_db
@ -281,24 +288,26 @@ class TestCommentPullRequest(object):
pull_request = pr_util.create_pull_request()
id_, params = build_data(
self.apikey, 'comment_pull_request',
self.apikey,
"comment_pull_request",
repoid=pull_request.target_repo.repo_name,
pullrequestid=pull_request.pull_request_id,
message='test message')
message="test message",
)
response = api_call(self.app, params)
json_response = response.json
comment_id = json_response['result']['comment_id']
comment_id = json_response["result"]["comment_id"]
message_after_edit = 'just message'
message_after_edit = "just message"
id_, params = build_data(
self.apikey,
'edit_comment',
"edit_comment",
comment_id=comment_id,
message=message_after_edit,
version=1,
)
response = api_call(self.app, params)
expected = 'comment ({}) version ({}) mismatch'.format(comment_id, 1)
expected = "comment ({}) version ({}) mismatch".format(comment_id, 1)
assert_error(id_, expected, given=response.body)
@pytest.mark.backends("git", "hg")
@ -306,19 +315,21 @@ class TestCommentPullRequest(object):
pull_request = pr_util.create_pull_request()
id_, params = build_data(
self.apikey, 'comment_pull_request',
self.apikey,
"comment_pull_request",
repoid=pull_request.target_repo.repo_name,
pullrequestid=pull_request.pull_request_id,
message='test message')
message="test message",
)
response = api_call(self.app, params)
json_response = response.json
comment_id = json_response['result']['comment_id']
comment_id = json_response["result"]["comment_id"]
id_, params = build_data(
self.apikey,
'edit_comment',
"edit_comment",
comment_id=comment_id,
message='',
message="",
version=0,
)
response = api_call(self.app, params)
@ -331,25 +342,25 @@ class TestCommentPullRequest(object):
pull_request_id = pull_request.pull_request_id
id_, params = build_data(
self.apikey,
'comment_pull_request',
"comment_pull_request",
repoid=pull_request.target_repo.repo_name,
pullrequestid=pull_request_id,
message='test message'
message="test message",
)
response = api_call(self.app, params)
json_response = response.json
comment_id = json_response['result']['comment_id']
comment_id = json_response["result"]["comment_id"]
id_, params = build_data(
self.apikey_regular,
'edit_comment',
"edit_comment",
comment_id=comment_id,
message='just message',
message="just message",
version=0,
userid=TEST_USER_ADMIN_LOGIN
userid=TEST_USER_ADMIN_LOGIN,
)
response = api_call(self.app, params)
expected = 'userid is not the same as your user'
expected = "userid is not the same as your user"
assert_error(id_, expected, given=response.body)
@pytest.mark.backends("git", "hg")
@ -358,20 +369,20 @@ class TestCommentPullRequest(object):
pull_request_id = pull_request.pull_request_id
id_, params = build_data(
self.apikey,
'comment_pull_request',
"comment_pull_request",
repoid=pull_request.target_repo.repo_name,
pullrequestid=pull_request_id,
message='test message'
message="test message",
)
response = api_call(self.app, params)
json_response = response.json
comment_id = json_response['result']['comment_id']
comment_id = json_response["result"]["comment_id"]
id_, params = build_data(
self.apikey_regular,
'edit_comment',
"edit_comment",
comment_id=comment_id,
message='just message',
message="just message",
version=0,
)
response = api_call(self.app, params)