-
-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fastapi_auth_partner: clean test and add missing index
- Loading branch information
1 parent
80af604
commit 819aeee
Showing
4 changed files
with
39 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import json | ||
from contextlib import contextmanager | ||
from functools import partial | ||
|
||
from requests import Response | ||
|
@@ -14,26 +13,21 @@ | |
from ..routers.auth import auth_router | ||
|
||
|
||
@tagged("post_install", "-at_install") | ||
class TestAuth(FastAPITransactionCase): | ||
class CommonTestAuth(FastAPITransactionCase): | ||
@classmethod | ||
def setUpClass(cls) -> None: | ||
super().setUpClass() | ||
cls.demo_app = cls.env.ref("fastapi_auth_partner.fastapi_endpoint_demo") | ||
cls.env = cls.env(context=dict(cls.env.context, test_queue_job_no_delay=True)) | ||
cls.default_fastapi_router = auth_router | ||
|
||
@contextmanager | ||
def _create_test_auth_client(self): | ||
demo_app = self.env.ref("fastapi_auth_partner.fastapi_endpoint_demo") | ||
with self._create_test_client( | ||
demo_app._get_app(), | ||
dependency_overrides={fastapi_endpoint: partial(lambda a: a, demo_app)}, | ||
env=self.env, | ||
) as test_client: | ||
yield test_client | ||
cls.default_fastapi_app = cls.demo_app._get_app() | ||
cls.default_fastapi_dependency_overrides = { | ||
fastapi_endpoint: partial(lambda a: a, cls.demo_app) | ||
} | ||
cls.default_fastapi_odoo_env = cls.env | ||
|
||
def _register_partner(self): | ||
with self._create_test_auth_client() as test_client: | ||
with self._create_test_client() as test_client: | ||
response: Response = test_client.post( | ||
"/auth/register", | ||
content=json.dumps( | ||
|
@@ -46,35 +40,42 @@ def _register_partner(self): | |
) | ||
return response | ||
|
||
def _login(self, test_client): | ||
response: Response = test_client.post( | ||
"/auth/login", | ||
content=json.dumps( | ||
{ | ||
"login": "[email protected]", | ||
"password": "supersecret", | ||
} | ||
), | ||
) | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
return response | ||
|
||
|
||
@tagged("post_install", "-at_install") | ||
class TestAuth(CommonTestAuth): | ||
def test_register(self): | ||
response = self._register_partner() | ||
self.assertEqual(response.status_code, status.HTTP_201_CREATED) | ||
self.assertEqual(response.json(), {"login": "[email protected]"}) | ||
|
||
def test_login(self): | ||
self._register_partner() | ||
with self._create_test_auth_client() as test_client: | ||
response: Response = test_client.post( | ||
"/auth/login", | ||
content=json.dumps( | ||
{ | ||
"login": "[email protected]", | ||
"password": "supersecret", | ||
} | ||
), | ||
) | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
with self._create_test_client() as test_client: | ||
response = self._login(test_client) | ||
self.assertEqual(response.json(), {"login": "[email protected]"}) | ||
|
||
def test_logout(self): | ||
self._register_partner() | ||
with self._create_test_auth_client() as test_client: | ||
with self._create_test_client() as test_client: | ||
response: Response = test_client.post("/auth/logout") | ||
self.assertEqual(response.status_code, status.HTTP_205_RESET_CONTENT) | ||
|
||
def test_request_reset_password(self): | ||
self._register_partner() | ||
with self._create_test_auth_client() as test_client: | ||
with self._create_test_client() as test_client: | ||
response: Response = test_client.post( | ||
"/auth/request_reset_password", | ||
content=json.dumps({"login": "[email protected]"}), | ||
|