Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions test/oauth2_session_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ def test_api_endpoint_url(self):
f'https://{TEST_DOMAIN}/api/v4/users/'
)

@mock.patch('bynder_sdk.oauth2.random.choice', return_value='a')
@mock.patch('requests_oauthlib.OAuth2Session.authorization_url')
def test_authorization_url(self, mocked_func):
def test_authorization_url(self, mocked_auth_url, mocked_choice):
self.session.authorization_url()
assert mocked_func.call_count == 1
mocked_auth_url.assert_called_once_with(
oauth2_url(TEST_DOMAIN, 'auth'),
state='aaaaaaaa'
)

@mock.patch('requests_oauthlib.OAuth2Session.fetch_token')
def test_fetch_token(self, mocked_func):
Expand All @@ -49,3 +53,28 @@ def test_fetch_token(self, mocked_func):
def test_user_agent_header(self):
# The UA header is contained within the session headers
assert UA_HEADER.items() <= self.session.headers.items()

def test_oauth2_url_auth_endpoint(self):
self.assertEqual(
oauth2_url(TEST_DOMAIN, 'auth'),
f'https://{TEST_DOMAIN}/v6/authentication/oauth2/auth',
)

def test_auto_refresh_url_set_on_init(self):
self.assertEqual(
self.session.auto_refresh_url,
oauth2_url(TEST_DOMAIN, 'token'),
)

@mock.patch('bynder_sdk.util.SessionMixin.post')
def test_post_https_url_withholds_token(self, mocked_post):
self.session.post('https://example.com/api')
mocked_post.assert_called_once_with(
'https://example.com/api',
withhold_token=True,
)

@mock.patch('bynder_sdk.util.SessionMixin.post')
def test_post_http_url_does_not_withhold_token(self, mocked_post):
self.session.post('http://example.com/api')
mocked_post.assert_called_once_with('http://example.com/api')