Skip to content

Commit

Permalink
make tests compatible with app_path
Browse files Browse the repository at this point in the history
  • Loading branch information
fzumstein committed Nov 8, 2024
1 parent b8d847b commit 21475e3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
12 changes: 6 additions & 6 deletions tests/test_router_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<DisplayName DefaultValue="Test Project [qa]" />' in response.text
Expand All @@ -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 '<DisplayName DefaultValue="Test Project" />' in response.text
Expand All @@ -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 '<bt:String id="Functions.Namespace" DefaultValue="" />' 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 '<bt:String id="Functions.Namespace" DefaultValue="QA" />' in response.text


def test_entraid_auth_deactivated():
response = client.get("/manifest")
response = client.get(f"{settings.app_path}/manifest")
assert "<WebApplicationInfo>" not in response.text


Expand All @@ -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 "<WebApplicationInfo>" in response.text
3 changes: 2 additions & 1 deletion tests/test_router_taskpane.py
Original file line number Diff line number Diff line change
@@ -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 "<h1>Example Task Pane</h1>" in response.text
33 changes: 12 additions & 21 deletions tests/test_router_xlwings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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))
Expand All @@ -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"]]],
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 21475e3

Please sign in to comment.