Skip to content

Commit 96930a3

Browse files
committed
fix(ci): fix failing fastapi and spp_api_v2 tests
- fastapi: create demo data in test setUpClass if not loaded - spp_api_v2: add pyjwt to external_dependencies - requirements.txt: regenerated with pyjwt
1 parent 34fc393 commit 96930a3

File tree

3 files changed

+66
-6
lines changed

3 files changed

+66
-6
lines changed

fastapi/tests/test_fastapi.py

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import unittest
66
from contextlib import contextmanager
77

8-
from odoo import sql_db
8+
from odoo import Command, sql_db
99
from odoo.tests.common import HttpCase
1010
from odoo.tools import mute_logger
1111

@@ -19,13 +19,71 @@ class FastAPIHttpCase(HttpCase):
1919
@classmethod
2020
def setUpClass(cls):
2121
super().setUpClass()
22-
cls.fastapi_demo_app = cls.env.ref("fastapi.fastapi_endpoint_demo")
23-
cls.fastapi_multi_demo_app = cls.env.ref("fastapi.fastapi_endpoint_multislash_demo")
22+
cls.fastapi_demo_app = cls._get_or_create_demo_endpoint(
23+
"fastapi.fastapi_endpoint_demo",
24+
name="Fastapi Demo Endpoint",
25+
root_path="/fastapi_demo",
26+
)
27+
cls.fastapi_multi_demo_app = cls._get_or_create_demo_endpoint(
28+
"fastapi.fastapi_endpoint_multislash_demo",
29+
name="Fastapi Multi-Slash Demo Endpoint",
30+
root_path="/fastapi/demo-multi",
31+
)
2432
cls.fastapi_apps = cls.fastapi_demo_app + cls.fastapi_multi_demo_app
2533
cls.fastapi_apps._handle_registry_sync()
2634
lang = cls.env["res.lang"].with_context(active_test=False).search([("code", "=", "fr_BE")])
2735
lang.active = True
2836

37+
@classmethod
38+
def _get_or_create_demo_endpoint(cls, xml_id, name, root_path):
39+
"""Get demo endpoint from XML ID or create it if missing (demo data not loaded)."""
40+
try:
41+
return cls.env.ref(xml_id)
42+
except ValueError:
43+
demo_user = cls._get_or_create_demo_user()
44+
endpoint = cls.env["fastapi.endpoint"].create(
45+
{
46+
"name": name,
47+
"app": "demo",
48+
"root_path": root_path,
49+
"demo_auth_method": "http_basic",
50+
"user_id": demo_user.id,
51+
}
52+
)
53+
cls.env["ir.model.data"].create(
54+
{
55+
"name": xml_id.split(".")[-1],
56+
"module": "fastapi",
57+
"model": "fastapi.endpoint",
58+
"res_id": endpoint.id,
59+
}
60+
)
61+
return endpoint
62+
63+
@classmethod
64+
def _get_or_create_demo_user(cls):
65+
"""Get or create the demo app user."""
66+
try:
67+
return cls.env.ref("fastapi.my_demo_app_user")
68+
except ValueError:
69+
runner_group = cls.env.ref("fastapi.group_fastapi_endpoint_runner")
70+
user = cls.env["res.users"].create(
71+
{
72+
"name": "My Demo Endpoint User",
73+
"login": "my_demo_app_user",
74+
"groups_id": [Command.set([runner_group.id])],
75+
}
76+
)
77+
cls.env["ir.model.data"].create(
78+
{
79+
"name": "my_demo_app_user",
80+
"module": "fastapi",
81+
"model": "res.users",
82+
"res_id": user.id,
83+
}
84+
)
85+
return user
86+
2987
@contextmanager
3088
def _mocked_commit(self):
3189
with unittest.mock.patch.object(sql_db.TestCursor, "commit", return_value=None) as mocked_commit:
@@ -78,9 +136,7 @@ def assert_exception_processed(
78136
expected_status_code: int,
79137
) -> None:
80138
with self._mocked_commit() as mocked_commit:
81-
route = (
82-
"/fastapi_demo/demo/exception?" f"exception_type={exception_type.value}&error_message={error_message}"
83-
)
139+
route = f"/fastapi_demo/demo/exception?exception_type={exception_type.value}&error_message={error_message}"
84140
response = self.url_open(route, timeout=200)
85141
mocked_commit.assert_not_called()
86142
self.assertDictEqual(

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ numpy>=1.22.2
1212
openpyxl
1313
parse-accept-language
1414
pydantic
15+
pyjwt
1516
pyproj
1617
python-dateutil
1718
python-magic

spp_api_v2/__manifest__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
"license": "LGPL-3",
99
"development_status": "Stable",
1010
"maintainers": ["jeremi", "gonzalesedwin1123", "reichie020212", "emjay0921"],
11+
"external_dependencies": {
12+
"python": ["pyjwt"],
13+
},
1114
"depends": [
1215
"base",
1316
"fastapi",

0 commit comments

Comments
 (0)