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

@ -19,8 +19,7 @@
import pytest
from rhodecode.api.utils import Optional, OAttr
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")
@ -28,72 +27,73 @@ class TestApi(object):
maxDiff = None
def test_Optional_object(self):
option1 = Optional(None)
assert '<Optional:{}>'.format(None) == repr(option1)
assert "<Optional:{}>".format(None) == repr(option1)
assert option1() is None
assert 1 == Optional.extract(Optional(1))
assert 'example' == Optional.extract('example')
assert "example" == Optional.extract("example")
def test_Optional_OAttr(self):
option1 = Optional(OAttr('apiuser'))
assert 'apiuser' == Optional.extract(option1)
option1 = Optional(OAttr("apiuser"))
assert "apiuser" == Optional.extract(option1)
def test_OAttr_object(self):
oattr1 = OAttr('apiuser')
assert '<OptionalAttr:apiuser>' == repr(oattr1)
oattr1 = OAttr("apiuser")
assert "<OptionalAttr:apiuser>" == repr(oattr1)
assert oattr1() == oattr1
def test_api_wrong_key(self):
id_, params = build_data('trololo', 'get_user')
id_, params = build_data("trololo", "get_user")
response = api_call(self.app, params)
expected = 'Invalid API KEY'
expected = "Invalid API KEY"
assert_error(id_, expected, given=response.body)
def test_api_missing_non_optional_param(self):
id_, params = build_data(self.apikey, 'get_repo')
id_, params = build_data(self.apikey, "get_repo")
response = api_call(self.app, params)
expected = 'Missing non optional `repoid` arg in JSON DATA'
expected = "Missing non optional `repoid` arg in JSON DATA"
assert_error(id_, expected, given=response.body)
def test_api_missing_non_optional_param_args_null(self):
id_, params = build_data(self.apikey, 'get_repo')
id_, params = build_data(self.apikey, "get_repo")
params = params.replace(b'"args": {}', b'"args": null')
response = api_call(self.app, params)
expected = 'Missing non optional `repoid` arg in JSON DATA'
expected = "Missing non optional `repoid` arg in JSON DATA"
assert_error(id_, expected, given=response.body)
def test_api_missing_non_optional_param_args_bad(self):
id_, params = build_data(self.apikey, 'get_repo')
id_, params = build_data(self.apikey, "get_repo")
params = params.replace(b'"args": {}', b'"args": 1')
response = api_call(self.app, params)
expected = 'Missing non optional `repoid` arg in JSON DATA'
expected = "Missing non optional `repoid` arg in JSON DATA"
assert_error(id_, expected, given=response.body)
def test_api_non_existing_method(self, request):
id_, params = build_data(self.apikey, 'not_existing', args='xx')
id_, params = build_data(self.apikey, "not_existing", args="xx")
response = api_call(self.app, params)
expected = 'No such method: not_existing. Similar methods: none'
expected = "No such method: not_existing. Similar methods: none"
assert_error(id_, expected, given=response.body)
def test_api_non_existing_method_have_similar(self, request):
id_, params = build_data(self.apikey, 'comment', args='xx')
id_, params = build_data(self.apikey, "comment", args="xx")
response = api_call(self.app, params)
expected = 'No such method: comment. ' \
'Similar methods: changeset_comment, comment_pull_request, ' \
'get_pull_request_comments, comment_commit, edit_comment, ' \
'get_comment, get_repo_comments'
expected = (
"No such method: comment. "
"Similar methods: changeset_comment, comment_pull_request, "
"get_pull_request_comments, comment_commit, edit_comment, "
"get_comment, get_repo_comments"
)
assert_error(id_, expected, given=response.body)
def test_api_disabled_user(self, request):
def set_active(active):
from rhodecode.model.db import Session, User
user = User.get_by_auth_token(self.apikey)
user.active = active
Session().add(user)
@ -102,31 +102,34 @@ class TestApi(object):
request.addfinalizer(lambda: set_active(True))
set_active(False)
id_, params = build_data(self.apikey, 'test', args='xx')
id_, params = build_data(self.apikey, "test", args="xx")
response = api_call(self.app, params)
expected = 'Request from this user not allowed'
expected = "Request from this user not allowed"
assert_error(id_, expected, given=response.body)
def test_api_args_is_null(self):
__, params = build_data(self.apikey, 'get_users', )
__, params = build_data(
self.apikey,
"get_users",
)
params = params.replace(b'"args": {}', b'"args": null')
response = api_call(self.app, params)
assert response.status == '200 OK'
assert response.status == "200 OK"
def test_api_args_is_bad(self):
__, params = build_data(self.apikey, 'get_users', )
__, params = build_data(
self.apikey,
"get_users",
)
params = params.replace(b'"args": {}', b'"args": 1')
response = api_call(self.app, params)
assert response.status == '200 OK'
assert response.status == "200 OK"
def test_api_args_different_args(self):
import string
expected = {
'ascii_letters': string.ascii_letters,
'ws': string.whitespace,
'printables': string.printable
}
id_, params = build_data(self.apikey, 'test', args=expected)
expected = {"ascii_letters": string.ascii_letters, "ws": string.whitespace, "printables": string.printable}
id_, params = build_data(self.apikey, "test", args=expected)
response = api_call(self.app, params)
assert response.status == '200 OK'
assert response.status == "200 OK"
assert_ok(id_, expected, response.body)