Files
deb-python-oauth2client/tests/test_util.py
Jon Wayne Parrott 969b130eb0 Credentials keep track of scopes.
* Added new attributes scopes and token_info_uri to OAuth2Credentials.
* Added method OAuth2Credentials.has_scopes to test which scopes the credentials have.
* OAuth2WebServerFlow now passes in the authorized scopes when constructing OAuth2Credentials.
* Added method Oauth2Credentials.refresh_scopes, which gets the canonical list of scopes from the OAuth2 tokeninfo service.
* Added new utility function string_to_scopes, the inverse of scopes_to_string.

This will fix #228 when merged.
2015-08-13 12:42:27 -07:00

58 lines
1.4 KiB
Python

"""Unit tests for oauth2client.util."""
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
import unittest
from oauth2client import util
class ScopeToStringTests(unittest.TestCase):
def test_iterables(self):
cases = [
('', ''),
('', ()),
('', []),
('', ('', )),
('', ['', ]),
('a', ('a', )),
('b', ['b', ]),
('a b', ['a', 'b']),
('a b', ('a', 'b')),
('a b', 'a b'),
('a b', (s for s in ['a', 'b'])),
]
for expected, case in cases:
self.assertEqual(expected, util.scopes_to_string(case))
class StringToScopeTests(unittest.TestCase):
def test_conversion(self):
cases = [
(['a', 'b'], ['a', 'b']),
('', []),
('a', ['a']),
('a b c d e f', ['a', 'b', 'c', 'd', 'e', 'f']),
]
for case, expected in cases:
self.assertEqual(expected, util.string_to_scopes(case))
class KeyConversionTests(unittest.TestCase):
def test_key_conversions(self):
d = {'somekey': 'some value', 'another': 'something else', 'onemore': 'foo'}
tuple_key = util.dict_to_tuple_key(d)
# the resulting key should be naturally sorted
self.assertEqual(
(('another', 'something else'),
('onemore', 'foo'),
('somekey', 'some value')),
tuple_key)
# check we get the original dictionary back
self.assertEqual(d, dict(tuple_key))