diff options
author | alexv-smirnov <alex@ydb.tech> | 2023-12-01 12:02:50 +0300 |
---|---|---|
committer | alexv-smirnov <alex@ydb.tech> | 2023-12-01 13:28:10 +0300 |
commit | 0e578a4c44d4abd539d9838347b9ebafaca41dfb (patch) | |
tree | a0c1969c37f818c830ebeff9c077eacf30be6ef8 /contrib/python/requests-oauthlib/tests/test_oauth2_auth.py | |
parent | 84f2d3d4cc985e63217cff149bd2e6d67ae6fe22 (diff) | |
download | ydb-0e578a4c44d4abd539d9838347b9ebafaca41dfb.tar.gz |
Change "ya.make"
Diffstat (limited to 'contrib/python/requests-oauthlib/tests/test_oauth2_auth.py')
-rw-r--r-- | contrib/python/requests-oauthlib/tests/test_oauth2_auth.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/contrib/python/requests-oauthlib/tests/test_oauth2_auth.py b/contrib/python/requests-oauthlib/tests/test_oauth2_auth.py new file mode 100644 index 0000000000..accb561ef6 --- /dev/null +++ b/contrib/python/requests-oauthlib/tests/test_oauth2_auth.py @@ -0,0 +1,54 @@ +from __future__ import unicode_literals +import unittest + +from oauthlib.oauth2 import WebApplicationClient, MobileApplicationClient +from oauthlib.oauth2 import LegacyApplicationClient, BackendApplicationClient +from requests import Request +from requests_oauthlib import OAuth2 + + +class OAuth2AuthTest(unittest.TestCase): + def setUp(self): + self.token = { + "token_type": "Bearer", + "access_token": "asdfoiw37850234lkjsdfsdf", + "expires_in": "3600", + } + self.client_id = "foo" + self.clients = [ + WebApplicationClient(self.client_id), + MobileApplicationClient(self.client_id), + LegacyApplicationClient(self.client_id), + BackendApplicationClient(self.client_id), + ] + + def test_add_token_to_url(self): + url = "https://example.com/resource?foo=bar" + new_url = url + "&access_token=" + self.token["access_token"] + for client in self.clients: + client.default_token_placement = "query" + auth = OAuth2(client=client, token=self.token) + r = Request("GET", url, auth=auth).prepare() + self.assertEqual(r.url, new_url) + + def test_add_token_to_headers(self): + token = "Bearer " + self.token["access_token"] + for client in self.clients: + auth = OAuth2(client=client, token=self.token) + r = Request("GET", "https://i.b", auth=auth).prepare() + self.assertEqual(r.headers["Authorization"], token) + + def test_add_token_to_body(self): + body = "foo=bar" + new_body = body + "&access_token=" + self.token["access_token"] + for client in self.clients: + client.default_token_placement = "body" + auth = OAuth2(client=client, token=self.token) + r = Request("GET", "https://i.b", data=body, auth=auth).prepare() + self.assertEqual(r.body, new_body) + + def test_add_nonexisting_token(self): + for client in self.clients: + auth = OAuth2(client=client) + r = Request("GET", "https://i.b", auth=auth) + self.assertRaises(ValueError, r.prepare) |