mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-23 18:59:56 +00:00
exactly one called with instead of last call check
This commit is contained in:
@ -37,7 +37,7 @@ async def test_permits(authorization_policy: AuthorizationPolicy, user: User) ->
|
||||
authorization_policy.validator.verify_access.side_effect = lambda username, *args: username == user.username
|
||||
|
||||
assert await authorization_policy.permits(_identity(user.username), user.access, "/endpoint")
|
||||
authorization_policy.validator.verify_access.assert_called_with(user.username, user.access, "/endpoint")
|
||||
authorization_policy.validator.verify_access.assert_called_once_with(user.username, user.access, "/endpoint")
|
||||
|
||||
assert not await authorization_policy.permits(_identity("somerandomname"), user.access, "/endpoint")
|
||||
assert not await authorization_policy.permits(user.username, user.access, "/endpoint")
|
||||
@ -54,7 +54,7 @@ async def test_auth_handler_api(mocker: MockerFixture) -> None:
|
||||
|
||||
handler = auth_handler()
|
||||
await handler(aiohttp_request, request_handler)
|
||||
check_permission_mock.assert_called_with(aiohttp_request, UserAccess.Read, aiohttp_request.path)
|
||||
check_permission_mock.assert_called_once_with(aiohttp_request, UserAccess.Read, aiohttp_request.path)
|
||||
|
||||
|
||||
async def test_auth_handler_api_no_method(mocker: MockerFixture) -> None:
|
||||
@ -68,7 +68,7 @@ async def test_auth_handler_api_no_method(mocker: MockerFixture) -> None:
|
||||
|
||||
handler = auth_handler()
|
||||
await handler(aiohttp_request, request_handler)
|
||||
check_permission_mock.assert_called_with(aiohttp_request, UserAccess.Write, aiohttp_request.path)
|
||||
check_permission_mock.assert_called_once_with(aiohttp_request, UserAccess.Write, aiohttp_request.path)
|
||||
|
||||
|
||||
async def test_auth_handler_api_post(mocker: MockerFixture) -> None:
|
||||
@ -82,7 +82,7 @@ async def test_auth_handler_api_post(mocker: MockerFixture) -> None:
|
||||
|
||||
handler = auth_handler()
|
||||
await handler(aiohttp_request, request_handler)
|
||||
check_permission_mock.assert_called_with(aiohttp_request, UserAccess.Write, aiohttp_request.path)
|
||||
check_permission_mock.assert_called_once_with(aiohttp_request, UserAccess.Write, aiohttp_request.path)
|
||||
|
||||
|
||||
async def test_auth_handler_read(mocker: MockerFixture) -> None:
|
||||
@ -97,7 +97,7 @@ async def test_auth_handler_read(mocker: MockerFixture) -> None:
|
||||
|
||||
handler = auth_handler()
|
||||
await handler(aiohttp_request, request_handler)
|
||||
check_permission_mock.assert_called_with(aiohttp_request, UserAccess.Read, aiohttp_request.path)
|
||||
check_permission_mock.assert_called_once_with(aiohttp_request, UserAccess.Read, aiohttp_request.path)
|
||||
|
||||
|
||||
async def test_auth_handler_write(mocker: MockerFixture) -> None:
|
||||
@ -112,7 +112,7 @@ async def test_auth_handler_write(mocker: MockerFixture) -> None:
|
||||
|
||||
handler = auth_handler()
|
||||
await handler(aiohttp_request, request_handler)
|
||||
check_permission_mock.assert_called_with(aiohttp_request, UserAccess.Write, aiohttp_request.path)
|
||||
check_permission_mock.assert_called_once_with(aiohttp_request, UserAccess.Write, aiohttp_request.path)
|
||||
|
||||
|
||||
def test_setup_auth(application_with_auth: web.Application, auth: Auth, mocker: MockerFixture) -> None:
|
||||
|
@ -39,8 +39,8 @@ def test_run(application: web.Application, mocker: MockerFixture) -> None:
|
||||
run_application_mock = mocker.patch("aiohttp.web.run_app")
|
||||
|
||||
run_server(application)
|
||||
run_application_mock.assert_called_with(application, host="127.0.0.1", port=port,
|
||||
handle_signals=False, access_log=pytest.helpers.anyvar(int))
|
||||
run_application_mock.assert_called_once_with(application, host="127.0.0.1", port=port,
|
||||
handle_signals=False, access_log=pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_run_with_auth(application_with_auth: web.Application, mocker: MockerFixture) -> None:
|
||||
@ -52,8 +52,8 @@ def test_run_with_auth(application_with_auth: web.Application, mocker: MockerFix
|
||||
run_application_mock = mocker.patch("aiohttp.web.run_app")
|
||||
|
||||
run_server(application_with_auth)
|
||||
run_application_mock.assert_called_with(application_with_auth, host="127.0.0.1", port=port,
|
||||
handle_signals=False, access_log=pytest.helpers.anyvar(int))
|
||||
run_application_mock.assert_called_once_with(application_with_auth, host="127.0.0.1", port=port,
|
||||
handle_signals=False, access_log=pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_run_with_debug(application_with_debug: web.Application, mocker: MockerFixture) -> None:
|
||||
@ -65,5 +65,5 @@ def test_run_with_debug(application_with_debug: web.Application, mocker: MockerF
|
||||
run_application_mock = mocker.patch("aiohttp.web.run_app")
|
||||
|
||||
run_server(application_with_debug)
|
||||
run_application_mock.assert_called_with(application_with_debug, host="127.0.0.1", port=port,
|
||||
handle_signals=False, access_log=pytest.helpers.anyvar(int))
|
||||
run_application_mock.assert_called_once_with(application_with_debug, host="127.0.0.1", port=port,
|
||||
handle_signals=False, access_log=pytest.helpers.anyvar(int))
|
||||
|
@ -24,7 +24,7 @@ async def test_post(client: TestClient, mocker: MockerFixture) -> None:
|
||||
response = await client.post("/service-api/v1/add", json={"packages": ["ahriman"]})
|
||||
|
||||
assert response.ok
|
||||
add_mock.assert_called_with(["ahriman"], now=True)
|
||||
add_mock.assert_called_once_with(["ahriman"], now=True)
|
||||
|
||||
|
||||
async def test_post_exception(client: TestClient, mocker: MockerFixture) -> None:
|
||||
@ -46,4 +46,4 @@ async def test_post_update(client: TestClient, mocker: MockerFixture) -> None:
|
||||
response = await client.post("/service-api/v1/update", json={"packages": ["ahriman"]})
|
||||
|
||||
assert response.ok
|
||||
add_mock.assert_called_with(["ahriman"], now=True)
|
||||
add_mock.assert_called_once_with(["ahriman"], now=True)
|
||||
|
@ -27,7 +27,7 @@ async def test_post(client_with_auth: TestClient, mocker: MockerFixture) -> None
|
||||
|
||||
assert response.ok
|
||||
reload_mock.assert_called_once()
|
||||
load_mock.assert_called_with(client_with_auth.app["configuration"])
|
||||
load_mock.assert_called_once_with(client_with_auth.app["configuration"])
|
||||
|
||||
|
||||
async def test_post_no_auth(client: TestClient, mocker: MockerFixture) -> None:
|
||||
|
@ -24,7 +24,7 @@ async def test_post(client: TestClient, mocker: MockerFixture) -> None:
|
||||
response = await client.post("/service-api/v1/remove", json={"packages": ["ahriman"]})
|
||||
|
||||
assert response.ok
|
||||
remove_mock.assert_called_with(["ahriman"])
|
||||
remove_mock.assert_called_once_with(["ahriman"])
|
||||
|
||||
|
||||
async def test_post_exception(client: TestClient, mocker: MockerFixture) -> None:
|
||||
|
@ -24,7 +24,7 @@ async def test_post(client: TestClient, mocker: MockerFixture) -> None:
|
||||
response = await client.post("/service-api/v1/request", json={"packages": ["ahriman"]})
|
||||
|
||||
assert response.ok
|
||||
add_mock.assert_called_with(["ahriman"], now=False)
|
||||
add_mock.assert_called_once_with(["ahriman"], now=False)
|
||||
|
||||
|
||||
async def test_post_exception(client: TestClient, mocker: MockerFixture) -> None:
|
||||
|
@ -48,7 +48,7 @@ async def test_get_join(client: TestClient, mocker: MockerFixture) -> None:
|
||||
response = await client.get("/service-api/v1/search", params=[("for", "ahriman"), ("for", "maybe")])
|
||||
|
||||
assert response.ok
|
||||
search_mock.assert_called_with("ahriman maybe")
|
||||
search_mock.assert_called_once_with("ahriman maybe")
|
||||
|
||||
|
||||
async def test_get_join_filter(client: TestClient, mocker: MockerFixture) -> None:
|
||||
@ -59,7 +59,7 @@ async def test_get_join_filter(client: TestClient, mocker: MockerFixture) -> Non
|
||||
response = await client.get("/service-api/v1/search", params=[("for", "ah"), ("for", "maybe")])
|
||||
|
||||
assert response.ok
|
||||
search_mock.assert_called_with("maybe")
|
||||
search_mock.assert_called_once_with("maybe")
|
||||
|
||||
|
||||
async def test_get_join_filter_empty(client: TestClient, mocker: MockerFixture) -> None:
|
||||
|
@ -64,8 +64,8 @@ async def test_get(client_with_auth: TestClient, mocker: MockerFixture) -> None:
|
||||
get_response = await client_with_auth.get("/user-api/v1/login", params={"code": "code"})
|
||||
|
||||
assert get_response.ok
|
||||
oauth.get_oauth_username.assert_called_with("code")
|
||||
oauth.known_username.assert_called_with("user")
|
||||
oauth.get_oauth_username.assert_called_once_with("code")
|
||||
oauth.known_username.assert_called_once_with("user")
|
||||
remember_mock.assert_called_once()
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user