core: run ruff format
This commit is contained in:
parent
7130effb58
commit
166db21812
821 changed files with 82905 additions and 84121 deletions
|
|
@ -21,70 +21,85 @@ import pytest
|
|||
|
||||
from rhodecode.model.db import Gist
|
||||
from rhodecode.model.gist import GistModel
|
||||
from rhodecode.api.tests.utils import (
|
||||
build_data, api_call, assert_error, assert_ok, crash)
|
||||
from rhodecode.api.tests.utils import build_data, api_call, assert_error, assert_ok, crash
|
||||
from rhodecode.tests.fixtures.rc_fixture import Fixture
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("testuser_api", "app")
|
||||
class TestApiCreateGist(object):
|
||||
@pytest.mark.parametrize("lifetime, gist_type, gist_acl_level", [
|
||||
(10, Gist.GIST_PUBLIC, Gist.ACL_LEVEL_PUBLIC),
|
||||
(20, Gist.GIST_PUBLIC, Gist.ACL_LEVEL_PRIVATE),
|
||||
(40, Gist.GIST_PRIVATE, Gist.ACL_LEVEL_PUBLIC),
|
||||
(80, Gist.GIST_PRIVATE, Gist.ACL_LEVEL_PRIVATE),
|
||||
])
|
||||
@pytest.mark.parametrize(
|
||||
"lifetime, gist_type, gist_acl_level",
|
||||
[
|
||||
(10, Gist.GIST_PUBLIC, Gist.ACL_LEVEL_PUBLIC),
|
||||
(20, Gist.GIST_PUBLIC, Gist.ACL_LEVEL_PRIVATE),
|
||||
(40, Gist.GIST_PRIVATE, Gist.ACL_LEVEL_PUBLIC),
|
||||
(80, Gist.GIST_PRIVATE, Gist.ACL_LEVEL_PRIVATE),
|
||||
],
|
||||
)
|
||||
def test_api_create_gist(self, lifetime, gist_type, gist_acl_level):
|
||||
id_, params = build_data(
|
||||
self.apikey_regular, 'create_gist',
|
||||
self.apikey_regular,
|
||||
"create_gist",
|
||||
lifetime=lifetime,
|
||||
description='foobar-gist',
|
||||
description="foobar-gist",
|
||||
gist_type=gist_type,
|
||||
acl_level=gist_acl_level,
|
||||
files={'foobar_ąć': {'content': 'foo'}})
|
||||
files={"foobar_ąć": {"content": "foo"}},
|
||||
)
|
||||
response = api_call(self.app, params)
|
||||
response_json = response.json
|
||||
gist = response_json['result']['gist']
|
||||
gist = response_json["result"]["gist"]
|
||||
expected = {
|
||||
'gist': {
|
||||
'access_id': gist['access_id'],
|
||||
'created_on': gist['created_on'],
|
||||
'modified_at': gist['modified_at'],
|
||||
'description': 'foobar-gist',
|
||||
'expires': gist['expires'],
|
||||
'gist_id': gist['gist_id'],
|
||||
'type': gist_type,
|
||||
'url': gist['url'],
|
||||
"gist": {
|
||||
"access_id": gist["access_id"],
|
||||
"created_on": gist["created_on"],
|
||||
"modified_at": gist["modified_at"],
|
||||
"description": "foobar-gist",
|
||||
"expires": gist["expires"],
|
||||
"gist_id": gist["gist_id"],
|
||||
"type": gist_type,
|
||||
"url": gist["url"],
|
||||
# content is empty since we don't show it here
|
||||
'content': None,
|
||||
'acl_level': gist_acl_level,
|
||||
"content": None,
|
||||
"acl_level": gist_acl_level,
|
||||
},
|
||||
'msg': 'created new gist'
|
||||
"msg": "created new gist",
|
||||
}
|
||||
try:
|
||||
assert_ok(id_, expected, given=response.body)
|
||||
finally:
|
||||
Fixture().destroy_gists()
|
||||
|
||||
@pytest.mark.parametrize("expected, lifetime, gist_type, gist_acl_level, files", [
|
||||
({'gist_type': '"ups" is not one of private, public'},
|
||||
10, 'ups', Gist.ACL_LEVEL_PUBLIC, {'f': {'content': 'f'}}),
|
||||
|
||||
({'lifetime': '-120 is less than minimum value -1'},
|
||||
-120, Gist.GIST_PUBLIC, Gist.ACL_LEVEL_PUBLIC, {'f': {'content': 'f'}}),
|
||||
|
||||
({'0.content': 'Required'},
|
||||
10, Gist.GIST_PUBLIC, Gist.ACL_LEVEL_PUBLIC, {'f': {'x': 'f'}}),
|
||||
])
|
||||
def test_api_try_create_gist(
|
||||
self, expected, lifetime, gist_type, gist_acl_level, files):
|
||||
@pytest.mark.parametrize(
|
||||
"expected, lifetime, gist_type, gist_acl_level, files",
|
||||
[
|
||||
(
|
||||
{"gist_type": '"ups" is not one of private, public'},
|
||||
10,
|
||||
"ups",
|
||||
Gist.ACL_LEVEL_PUBLIC,
|
||||
{"f": {"content": "f"}},
|
||||
),
|
||||
(
|
||||
{"lifetime": "-120 is less than minimum value -1"},
|
||||
-120,
|
||||
Gist.GIST_PUBLIC,
|
||||
Gist.ACL_LEVEL_PUBLIC,
|
||||
{"f": {"content": "f"}},
|
||||
),
|
||||
({"0.content": "Required"}, 10, Gist.GIST_PUBLIC, Gist.ACL_LEVEL_PUBLIC, {"f": {"x": "f"}}),
|
||||
],
|
||||
)
|
||||
def test_api_try_create_gist(self, expected, lifetime, gist_type, gist_acl_level, files):
|
||||
id_, params = build_data(
|
||||
self.apikey_regular, 'create_gist',
|
||||
self.apikey_regular,
|
||||
"create_gist",
|
||||
lifetime=lifetime,
|
||||
description='foobar-gist',
|
||||
description="foobar-gist",
|
||||
gist_type=gist_type,
|
||||
acl_level=gist_acl_level,
|
||||
files=files)
|
||||
files=files,
|
||||
)
|
||||
response = api_call(self.app, params)
|
||||
|
||||
try:
|
||||
|
|
@ -92,9 +107,9 @@ class TestApiCreateGist(object):
|
|||
finally:
|
||||
Fixture().destroy_gists()
|
||||
|
||||
@mock.patch.object(GistModel, 'create', crash)
|
||||
@mock.patch.object(GistModel, "create", crash)
|
||||
def test_api_create_gist_exception_occurred(self):
|
||||
id_, params = build_data(self.apikey_regular, 'create_gist', files={})
|
||||
id_, params = build_data(self.apikey_regular, "create_gist", files={})
|
||||
response = api_call(self.app, params)
|
||||
expected = 'failed to create gist'
|
||||
expected = "failed to create gist"
|
||||
assert_error(id_, expected, given=response.body)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue