From 21475e34d3d588eef2674e2c47f1bf203f98bda4 Mon Sep 17 00:00:00 2001 From: Felix Zumstein Date: Fri, 8 Nov 2024 15:12:59 -0300 Subject: [PATCH] make tests compatible with app_path --- tests/test_router_manifest.py | 12 ++++++------ tests/test_router_taskpane.py | 3 ++- tests/test_router_xlwings.py | 33 ++++++++++++--------------------- 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/tests/test_router_manifest.py b/tests/test_router_manifest.py index 32f647a..ec1c4c2 100644 --- a/tests/test_router_manifest.py +++ b/tests/test_router_manifest.py @@ -7,7 +7,7 @@ def test_get_manifest_nonprod(): - response = client.get("/manifest") + response = client.get(f"{settings.app_path}/manifest") assert response.status_code == 200 assert "text/plain" in response.headers["Content-Type"] assert '' in response.text @@ -19,7 +19,7 @@ def test_get_manifest_nonprod(): def test_get_manifest_prod(mocker): mocker.patch.object(settings, "environment", "prod") - response = client.get("/manifest") + response = client.get(f"{settings.app_path}/manifest") assert response.status_code == 200 assert "text/plain" in response.headers["Content-Type"] assert '' in response.text @@ -31,18 +31,18 @@ def test_get_manifest_prod(mocker): def test_empty_function_namespace_prod(mocker): mocker.patch.object(settings, "environment", "prod") mocker.patch.object(settings, "functions_namespace", "") - response = client.get("/manifest") + response = client.get(f"{settings.app_path}/manifest") assert '' in response.text def test_empty_function_namespace_nonprod(mocker): mocker.patch.object(settings, "functions_namespace", "") - response = client.get("/manifest") + response = client.get(f"{settings.app_path}/manifest") assert '' in response.text def test_entraid_auth_deactivated(): - response = client.get("/manifest") + response = client.get(f"{settings.app_path}/manifest") assert "" not in response.text @@ -54,5 +54,5 @@ def test_entraid_auth_activated(mocker): mocker.patch.object( settings, "auth_entraid_tenant_id", "efadd9e3-83b3-41f8-86d1-c0ea7ad203ad" ) - response = client.get("/manifest") + response = client.get(f"{settings.app_path}/manifest") assert "" in response.text diff --git a/tests/test_router_taskpane.py b/tests/test_router_taskpane.py index c514e6f..25f1731 100644 --- a/tests/test_router_taskpane.py +++ b/tests/test_router_taskpane.py @@ -1,11 +1,12 @@ from fastapi.testclient import TestClient +from app.config import settings from app.main import main_app client = TestClient(main_app) def test_get_taskpane(): - response = client.get("/taskpane") + response = client.get(f"{settings.app_path}/taskpane") assert response.status_code == 200 assert "

Example Task Pane

" in response.text diff --git a/tests/test_router_xlwings.py b/tests/test_router_xlwings.py index 9d62dea..7631fc3 100644 --- a/tests/test_router_xlwings.py +++ b/tests/test_router_xlwings.py @@ -11,7 +11,7 @@ def test_get_alert(): # String to the right of $_hostInfo added by Excel response = client.get( - "xlwings/alert?prompt=Exception(%27test%27)&title=Error&buttons=ok&mode=critical&callback=&_host_Info=Excel$Mac$16.01$en-US$telemetry$isDialog$$0" + f"{settings.app_path}/xlwings/alert?prompt=Exception(%27test%27)&title=Error&buttons=ok&mode=critical&callback=&_host_Info=Excel$Mac$16.01$en-US$telemetry$isDialog$$0" ) assert response.status_code == 200 assert ( @@ -33,7 +33,7 @@ def test_get_alert(): def test_custom_functions_meta(): - response = client.get("xlwings/custom-functions-meta") + response = client.get(f"{settings.app_path}/xlwings/custom-functions-meta") assert response.status_code == 200 # run via: pytest -s tests/test_router_xlwings.py::test_custom_functions_meta # print(repr(response.text)) @@ -47,23 +47,14 @@ def test_custom_functions_meta(): def test_custom_functions_code(): - response = client.get("xlwings/custom-functions-code") + response = client.get(f"{settings.app_path}/xlwings/custom-functions-code") assert response.status_code == 200 - assert 'window.location.origin + "/xlwings/custom-functions-call"' in response.text - - -def test_custom_functions_code_with_app_path(mocker): - mocker.patch.object(settings, "app_path", "/x/y") - response = client.get("xlwings/custom-functions-code") - assert response.status_code == 200 - assert ( - 'window.location.origin + "/x/y/xlwings/custom-functions-call"' in response.text - ) + assert f"{settings.app_path}/xlwings/custom-functions-call" in response.text def test_custom_functions_call(): response = client.post( - "/xlwings/custom-functions-call", + f"{settings.app_path}/xlwings/custom-functions-call", json={ "func_name": "hello", "args": [[["xlwings"]]], @@ -82,7 +73,7 @@ def test_custom_functions_call_with_invalid_entraid_token(mocker): mocker.patch("app.config.settings.auth_entraid_client_id", "mocked_client_id") response = client.post( - "/xlwings/custom-functions-call", + f"{settings.app_path}/xlwings/custom-functions-call", headers={"Authorization": "invalid token"}, json={ "func_name": "hello", @@ -100,7 +91,7 @@ def test_custom_functions_call_missing_roles(mocker): mocker.patch("app.config.settings.auth_providers", ["custom"]) mocker.patch("app.config.settings.auth_required_roles", ["role1"]) response = client.post( - "/xlwings/custom-functions-call", + f"{settings.app_path}/xlwings/custom-functions-call", headers={"Authorization": ""}, json={ "func_name": "hello", @@ -117,7 +108,7 @@ def test_custom_functions_call_missing_roles(mocker): def test_custom_functions_call_anonymous(mocker): response = client.post( - "/xlwings/custom-functions-call", + f"{settings.app_path}/xlwings/custom-functions-call", headers={"Authorization": ""}, json={ "func_name": "hello", @@ -137,7 +128,7 @@ def test_custom_scripts_call_with_invalid_entraid_token(mocker): mocker.patch("app.config.settings.auth_entraid_client_id", "mocked_client_id") response = client.post( - "/xlwings/custom-scripts-call/hello_world", + f"{settings.app_path}/xlwings/custom-scripts-call/hello_world", headers={"Authorization": "invalid token"}, json={ "client": "Office.js", @@ -161,7 +152,7 @@ def test_custom_scripts_call_missing_roles(mocker): mocker.patch("app.config.settings.auth_providers", ["custom"]) mocker.patch("app.config.settings.auth_required_roles", ["role1"]) response = client.post( - "/xlwings/custom-scripts-call/hello_world", + f"{settings.app_path}/xlwings/custom-scripts-call/hello_world", headers={"Authorization": "token"}, json={ "client": "Office.js", @@ -186,7 +177,7 @@ def test_custom_scripts_call_missing_authorization(mocker): mocker.patch("app.config.settings.auth_providers", ["custom"]) mocker.patch("app.models.User.is_authorized", return_value=False) response = client.post( - "/xlwings/custom-scripts-call/hello_world", + f"{settings.app_path}/xlwings/custom-scripts-call/hello_world", headers={"Authorization": "token"}, json={ "client": "Office.js", @@ -209,7 +200,7 @@ def test_custom_scripts_call_missing_authorization(mocker): def test_custom_scripts_call_anonymous(mocker): response = client.post( - "/xlwings/custom-scripts-call/hello_world", + f"{settings.app_path}/xlwings/custom-scripts-call/hello_world", headers={"Authorization": ""}, json={ "client": "Office.js",