@@ -38,43 +38,49 @@ def backends():
38
38
39
39
40
40
@pytest .fixture
41
- def app ():
42
- oauth2 = OAuth2 ()
43
- application = FastAPI ()
44
- app_router = APIRouter ()
41
+ def get_app ():
42
+ def fixture_wrapper ( authentication : OAuth2 = None ):
43
+ if not authentication :
44
+ authentication = OAuth2 ()
45
45
46
- @ app_router . get ( "/user" )
47
- def user ( request : Request , _ : str = Depends ( oauth2 )):
48
- return request . user
46
+ oauth2 = authentication
47
+ application = FastAPI ()
48
+ app_router = APIRouter ()
49
49
50
- @app_router .get ("/auth" )
51
- def auth (request : Request ):
52
- access_token = request .auth .jwt_create ({
53
- "name" : "test" ,
54
- "sub" : "test" ,
55
- "id" : "test" ,
50
+ @app_router .get ("/user" )
51
+ def user (request : Request , _ : str = Depends (oauth2 )):
52
+ return request .user
53
+
54
+ @app_router .get ("/auth" )
55
+ def auth (request : Request ):
56
+ access_token = request .auth .jwt_create ({
57
+ "name" : "test" ,
58
+ "sub" : "test" ,
59
+ "id" : "test" ,
60
+ })
61
+ response = Response ()
62
+ response .set_cookie (
63
+ "Authorization" ,
64
+ value = f"Bearer { access_token } " ,
65
+ max_age = request .auth .expires ,
66
+ expires = request .auth .expires ,
67
+ httponly = request .auth .http ,
68
+ )
69
+ return response
70
+
71
+ application .include_router (app_router )
72
+ application .include_router (oauth2_router )
73
+ application .add_middleware (OAuth2Middleware , config = {
74
+ "allow_http" : True ,
75
+ "clients" : [
76
+ OAuth2Client (
77
+ backend = GithubOAuth2 ,
78
+ client_id = "test_id" ,
79
+ client_secret = "test_secret" ,
80
+ ),
81
+ ],
56
82
})
57
- response = Response ()
58
- response .set_cookie (
59
- "Authorization" ,
60
- value = f"Bearer { access_token } " ,
61
- max_age = request .auth .expires ,
62
- expires = request .auth .expires ,
63
- httponly = request .auth .http ,
64
- )
65
- return response
66
83
67
- application .include_router (app_router )
68
- application .include_router (oauth2_router )
69
- application .add_middleware (OAuth2Middleware , config = {
70
- "allow_http" : True ,
71
- "clients" : [
72
- OAuth2Client (
73
- backend = GithubOAuth2 ,
74
- client_id = "test_id" ,
75
- client_secret = "test_secret" ,
76
- ),
77
- ],
78
- })
84
+ return application
79
85
80
- return application
86
+ return fixture_wrapper
0 commit comments