1
1
import pytest , sys , asyncio
2
- from hypercorn .config import Config
3
- from hypercorn .asyncio import serve
4
2
from os .path import dirname , join , abspath
5
- from src .app import create_app
6
3
#from src.main import app
7
4
from quart_cors import cors
8
5
sys .path .insert (0 , abspath (join (dirname (__file__ ), '../src' )))
9
6
from common .Authentication import Authentication
10
- pytest_plugins = ('pytest_asyncio' ,)
11
7
12
- @pytest .fixture ()
13
- async def app_context ():
14
- config = Config ()
15
- config .bind = ["localhost:4433" ]
16
- config .insecure_bind = ["localhost:8080" ]
17
- config .worker_class = "asyncio"
18
- config .alt_svc_headers = ["h3=\" :443\" ; ma=3600, h3-29=\" :443\" ; ma=3600" ]
19
- config .loglevel = "DEBUG"
20
- config .quic_bind = ["localhost:4433" ]
21
- app = create_app ()
22
- app = cors (app , allow_credentials = True , allow_origin = "https://localhost:4433" )
23
- asyncio .run (serve (app , config ))
24
- async with app .app_context () as app_context :
25
- yield app_context
26
- @pytest .mark .asyncio
27
- async def test_tokengeneration_pass (app_context ):
8
+ def test_tokengeneration_pass ():
28
9
""" JWT token generation should pass with valid user input parameter """
29
10
token = Authentication .generate_token ("test_user" )
30
11
assert type (token ) is str
31
12
assert token != ""
32
- @ pytest . mark . asyncio
33
- async def test_tokengeneration_fail (app_context ):
13
+
14
+ def test_tokengeneration_fail ():
34
15
""" JWT token generation should fail without valid user input parameter """
35
16
with pytest .raises (Exception ) as e :
36
17
token = Authentication .generate_token ("" )
37
18
assert "Invalid user id!" in str (e .value )
38
- @ pytest . mark . asyncio
39
- async def test_tokendecoding_pass (app_context ):
19
+
20
+ def test_tokendecoding_pass ():
40
21
""" JWT token decoding should pass with valid user input parameter """
41
22
token = Authentication .generate_token ("test_user" )
42
23
assert type (token ) is str
@@ -49,8 +30,8 @@ async def test_tokendecoding_pass(app_context):
49
30
assert decode ["data" ]["user_id" ] == "test_user"
50
31
expect = dict (data = dict (user_id = "test_user" ), error = dict ())
51
32
assert decode == expect
52
- @ pytest . mark . asyncio
53
- async def test_tokendecoding_fail (app_context ):
33
+
34
+ def test_tokendecoding_fail ():
54
35
""" JWT token decoding should fail without valid user input parameter """
55
36
with pytest .raises (Exception ) as e :
56
37
token = Authentication .decode_token ("" )
0 commit comments