Skip to content

Commit 0efd0f9

Browse files
committed
Fixed oauth_authorization_uri creation and added a test.
1 parent 512e57e commit 0efd0f9

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

bunq/sdk/http/http_util.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33

44
class HttpUtil:
5-
# Query constants.
6-
QUERY_FORMAT = "%s=%s"
7-
QUERY_DELIMITER = "&"
5+
QUERY_FORMAT = '{}={}'
6+
QUERY_DELIMITER = '&'
87

98
@classmethod
109
def create_query_string(cls, all_parameter: Dict[str, str]):

bunq/sdk/model/core/oauth_authorization_uri.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
class OauthAuthorizationUri(BunqModel):
1313
# 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?{}"
1616

1717
# Field constants
1818
FIELD_RESPONSE_TYPE = "response_type"
@@ -38,17 +38,22 @@ def create(cls,
3838
state: str = None) -> OauthAuthorizationUri:
3939
all_request_parameter = {
4040
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()
4342
}
4443

44+
if client.client_id is not None:
45+
all_request_parameter[cls.FIELD_CLIENT_ID] = client.client_id
46+
4547
if state is not None:
4648
all_request_parameter[cls.FIELD_STATE] = state
4749

4850
return OauthAuthorizationUri(
4951
cls.determine_auth_uri_format().format(HttpUtil.create_query_string(all_request_parameter))
5052
)
5153

54+
def get_authorization_uri(self) -> str:
55+
return self._authorization_uri
56+
5257
def is_all_field_none(self) -> bool:
5358
if self._authorization_uri is None:
5459
return True
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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)

0 commit comments

Comments
 (0)