mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-23 10:49:55 +00:00
strict test checks
This commit is contained in:
@ -14,7 +14,7 @@ from ahriman.web.middlewares.auth_handler import auth_handler, AuthorizationPoli
|
||||
def _identity(username: str) -> str:
|
||||
"""
|
||||
generate identity from user
|
||||
:param user: user fixture object
|
||||
:param username: name of the user
|
||||
:return: user identity string
|
||||
"""
|
||||
return f"{username} {UserIdentity.expire_when(60)}"
|
||||
@ -119,7 +119,7 @@ def test_setup_auth(application_with_auth: web.Application, auth: Auth, mocker:
|
||||
"""
|
||||
must setup authorization
|
||||
"""
|
||||
aiohttp_security_setup_mock = mocker.patch("aiohttp_security.setup")
|
||||
setup_mock = mocker.patch("aiohttp_security.setup")
|
||||
application = setup_auth(application_with_auth, auth)
|
||||
assert application.get("validator") is not None
|
||||
aiohttp_security_setup_mock.assert_called_once()
|
||||
setup_mock.assert_called_once_with(application_with_auth, pytest.helpers.anyvar(int), pytest.helpers.anyvar(int))
|
||||
|
@ -71,7 +71,7 @@ async def test_exception_handler_server_error(mocker: MockerFixture) -> None:
|
||||
handler = exception_handler(logging.getLogger())
|
||||
response = await handler(request, request_handler)
|
||||
assert _extract_body(response) == {"error": HTTPInternalServerError().reason}
|
||||
logging_mock.assert_called_once()
|
||||
logging_mock.assert_called_once() # we do not check logging arguments
|
||||
|
||||
|
||||
async def test_exception_handler_unknown_error(mocker: MockerFixture) -> None:
|
||||
@ -85,4 +85,4 @@ async def test_exception_handler_unknown_error(mocker: MockerFixture) -> None:
|
||||
handler = exception_handler(logging.getLogger())
|
||||
response = await handler(request, request_handler)
|
||||
assert _extract_body(response) == {"error": "An error"}
|
||||
logging_mock.assert_called_once()
|
||||
logging_mock.assert_called_once() # we do not check logging arguments
|
||||
|
@ -5,7 +5,16 @@ from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.core.exceptions import InitializeException
|
||||
from ahriman.core.status.watcher import Watcher
|
||||
from ahriman.web.web import on_startup, run_server
|
||||
from ahriman.web.web import on_shutdown, on_startup, run_server
|
||||
|
||||
|
||||
async def test_on_shutdown(application: web.Application, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must write information to log
|
||||
"""
|
||||
logging_mock = mocker.patch("logging.Logger.warning")
|
||||
await on_shutdown(application)
|
||||
logging_mock.assert_called_once_with(pytest.helpers.anyvar(str, True))
|
||||
|
||||
|
||||
async def test_on_startup(application: web.Application, watcher: Watcher, mocker: MockerFixture) -> None:
|
||||
@ -16,7 +25,7 @@ async def test_on_startup(application: web.Application, watcher: Watcher, mocker
|
||||
load_mock = mocker.patch("ahriman.core.status.watcher.Watcher.load")
|
||||
|
||||
await on_startup(application)
|
||||
load_mock.assert_called_once()
|
||||
load_mock.assert_called_once_with()
|
||||
|
||||
|
||||
async def test_on_startup_exception(application: web.Application, watcher: Watcher, mocker: MockerFixture) -> None:
|
||||
|
@ -26,7 +26,7 @@ async def test_post(client_with_auth: TestClient, mocker: MockerFixture) -> None
|
||||
response = await client_with_auth.post("/service-api/v1/reload-auth")
|
||||
|
||||
assert response.ok
|
||||
reload_mock.assert_called_once()
|
||||
reload_mock.assert_called_once_with()
|
||||
load_mock.assert_called_once_with(client_with_auth.app["configuration"])
|
||||
|
||||
|
||||
@ -38,4 +38,4 @@ async def test_post_no_auth(client: TestClient, mocker: MockerFixture) -> None:
|
||||
response = await client.post("/service-api/v1/reload-auth")
|
||||
|
||||
assert response.status == 500
|
||||
reload_mock.assert_called_once()
|
||||
reload_mock.assert_called_once_with()
|
||||
|
@ -45,4 +45,4 @@ async def test_post(client: TestClient, mocker: MockerFixture) -> None:
|
||||
load_mock = mocker.patch("ahriman.core.status.watcher.Watcher.load")
|
||||
response = await client.post("/status-api/v1/packages")
|
||||
assert response.status == 204
|
||||
load_mock.assert_called_once()
|
||||
load_mock.assert_called_once_with()
|
||||
|
@ -36,7 +36,7 @@ async def test_get_redirect_to_oauth(client_with_auth: TestClient) -> None:
|
||||
|
||||
get_response = await client_with_auth.get("/user-api/v1/login")
|
||||
assert get_response.ok
|
||||
oauth.get_oauth_url.assert_called_once()
|
||||
oauth.get_oauth_url.assert_called_once_with()
|
||||
|
||||
|
||||
async def test_get_redirect_to_oauth_empty_code(client_with_auth: TestClient) -> None:
|
||||
@ -48,7 +48,7 @@ async def test_get_redirect_to_oauth_empty_code(client_with_auth: TestClient) ->
|
||||
|
||||
get_response = await client_with_auth.get("/user-api/v1/login", params={"code": ""})
|
||||
assert get_response.ok
|
||||
oauth.get_oauth_url.assert_called_once()
|
||||
oauth.get_oauth_url.assert_called_once_with()
|
||||
|
||||
|
||||
async def test_get(client_with_auth: TestClient, mocker: MockerFixture) -> None:
|
||||
@ -58,7 +58,7 @@ async def test_get(client_with_auth: TestClient, mocker: MockerFixture) -> None:
|
||||
oauth = client_with_auth.app["validator"] = MagicMock(spec=OAuth)
|
||||
oauth.get_oauth_username.return_value = "user"
|
||||
oauth.known_username.return_value = True
|
||||
oauth.enabled = False # lol\
|
||||
oauth.enabled = False # lol
|
||||
oauth.max_age = 60
|
||||
remember_mock = mocker.patch("aiohttp_security.remember")
|
||||
|
||||
@ -67,7 +67,8 @@ async def test_get(client_with_auth: TestClient, mocker: MockerFixture) -> None:
|
||||
assert get_response.ok
|
||||
oauth.get_oauth_username.assert_called_once_with("code")
|
||||
oauth.known_username.assert_called_once_with("user")
|
||||
remember_mock.assert_called_once()
|
||||
remember_mock.assert_called_once_with(
|
||||
pytest.helpers.anyvar(int), pytest.helpers.anyvar(int), pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
async def test_get_unauthorized(client_with_auth: TestClient, mocker: MockerFixture) -> None:
|
||||
|
@ -26,7 +26,7 @@ async def test_post(client_with_auth: TestClient, mocker: MockerFixture) -> None
|
||||
|
||||
post_response = await client_with_auth.post("/user-api/v1/logout")
|
||||
assert post_response.ok
|
||||
forget_mock.assert_called_once()
|
||||
forget_mock.assert_called_once_with(pytest.helpers.anyvar(int), pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
async def test_post_unauthorized(client_with_auth: TestClient, mocker: MockerFixture) -> None:
|
||||
|
Reference in New Issue
Block a user