22
33import importlib .metadata
44
5+ import asyncio
56import pytest
7+ from .common import _is_async
68
79import save_and_restore_api
810from save_and_restore_api import SaveRestoreAPI as SaveRestoreAPI_Threads
@@ -19,6 +21,36 @@ def test_version():
1921 assert importlib .metadata .version ("save_and_restore_api" ) == save_and_restore_api .__version__
2022
2123
24+ # fmt: off
25+ @pytest .mark .parametrize ("library" , ["THREADS" , "ASYNC" ])
26+ @pytest .mark .parametrize ("username, password, roles" , [
27+ (admin_username , admin_password , ["ROLE_SAR-ADMIN" ]),
28+ (user_username , user_password , ["ROLE_SAR-USER" ]),
29+ (read_username , read_password , []),
30+ ])
31+ # fmt: on
32+ def test_login_01 (username , password , roles , library ):
33+ if not _is_async (library ):
34+ SR = SaveRestoreAPI_Threads (base_url = base_url , timeout = 2 )
35+ SR .set_auth (username = user_username , password = user_password )
36+ SR .open ()
37+ response = SR .login (username = username , password = password )
38+ SR .close ()
39+ assert response ["userName" ] == username
40+ assert response ["roles" ] == roles
41+ else :
42+ async def testing ():
43+ SR = SaveRestoreAPI_Threads (base_url = base_url , timeout = 2 )
44+ SR .set_auth (username = user_username , password = user_password )
45+ SR .open ()
46+ response = SR .login (username = username , password = password )
47+ SR .close ()
48+ assert response ["userName" ] == username
49+ assert response ["roles" ] == roles
50+
51+ asyncio .run (testing ())
52+
53+
2254def test_comm ():
2355 SR = SaveRestoreAPI_Threads (base_url = base_url , timeout = 2 )
2456 SR .set_auth (username = user_username , password = user_password )
0 commit comments