File tree Expand file tree Collapse file tree 3 files changed +37
-7
lines changed Expand file tree Collapse file tree 3 files changed +37
-7
lines changed Original file line number Diff line number Diff line change 2
2
3
3
4
4
class HttpUtil :
5
- # Query constants.
6
- QUERY_FORMAT = "%s=%s"
7
- QUERY_DELIMITER = "&"
5
+ QUERY_FORMAT = '{}={}'
6
+ QUERY_DELIMITER = '&'
8
7
9
8
@classmethod
10
9
def create_query_string (cls , all_parameter : Dict [str , str ]):
Original file line number Diff line number Diff line change 11
11
12
12
class OauthAuthorizationUri (BunqModel ):
13
13
# Auth constants.
14
- AUTH_URI_FORMAT_SANDBOX = "https://oauth.sandbox.bunq.com/auth?%s "
15
- AUTH_URI_FORMAT_PRODUCTION = "https://oauth.bunq.com/auth?%s "
14
+ AUTH_URI_FORMAT_SANDBOX = "https://oauth.sandbox.bunq.com/auth?{} "
15
+ AUTH_URI_FORMAT_PRODUCTION = "https://oauth.bunq.com/auth?{} "
16
16
17
17
# Field constants
18
18
FIELD_RESPONSE_TYPE = "response_type"
@@ -38,17 +38,22 @@ def create(cls,
38
38
state : str = None ) -> OauthAuthorizationUri :
39
39
all_request_parameter = {
40
40
cls .FIELD_REDIRECT_URI : redirect_uri ,
41
- cls .FIELD_RESPONSE_TYPE : response_type .value ,
42
- cls .FIELD_CLIENT_ID : client .client_id
41
+ cls .FIELD_RESPONSE_TYPE : response_type .name .lower ()
43
42
}
44
43
44
+ if client .client_id is not None :
45
+ all_request_parameter [cls .FIELD_CLIENT_ID ] = client .client_id
46
+
45
47
if state is not None :
46
48
all_request_parameter [cls .FIELD_STATE ] = state
47
49
48
50
return OauthAuthorizationUri (
49
51
cls .determine_auth_uri_format ().format (HttpUtil .create_query_string (all_request_parameter ))
50
52
)
51
53
54
+ def get_authorization_uri (self ) -> str :
55
+ return self ._authorization_uri
56
+
52
57
def is_all_field_none (self ) -> bool :
53
58
if self ._authorization_uri is None :
54
59
return True
Original file line number Diff line number Diff line change
1
+ from bunq .sdk .context .bunq_context import BunqContext
2
+ from bunq .sdk .model .core .oauth_authorization_uri import OauthAuthorizationUri
3
+ from bunq .sdk .model .core .oauth_response_type import OauthResponseType
4
+ from bunq .sdk .model .generated .endpoint import OauthClient
5
+ from tests .bunq_test import BunqSdkTestCase
6
+
7
+
8
+ class TestOauthAuthorizationUri (BunqSdkTestCase ):
9
+ _TEST_EXPECT_URI = 'https://oauth.sandbox.bunq.com/auth?redirect_uri=redirecturi&response_type=code&state=state'
10
+ _TEST_REDIRECT_URI = 'redirecturi'
11
+ _TEST_STATUS = 'status'
12
+ _TEST_STATE = 'state'
13
+
14
+ @classmethod
15
+ def setUpClass (cls ) -> None :
16
+ BunqContext .load_api_context (cls ._get_api_context ())
17
+
18
+ def test_oauth_authorization_uri_create (self ) -> None :
19
+ uri = OauthAuthorizationUri .create (
20
+ OauthResponseType (OauthResponseType .CODE ),
21
+ self ._TEST_REDIRECT_URI ,
22
+ OauthClient (self ._TEST_STATUS ),
23
+ self ._TEST_STATE
24
+ ).get_authorization_uri ()
25
+
26
+ self .assertEqual (self ._TEST_EXPECT_URI , uri )
You can’t perform that action at this time.
0 commit comments