Joe Gregorio | 5cf5d12 | 2012-11-16 16:36:12 -0500 | [diff] [blame] | 1 | """Unit tests for oauth2client.util.""" |
| 2 | |
| 3 | __author__ = 'jcgregorio@google.com (Joe Gregorio)' |
| 4 | |
| 5 | import unittest |
| 6 | |
| 7 | from oauth2client import util |
| 8 | |
| 9 | |
| 10 | class ScopeToStringTests(unittest.TestCase): |
| 11 | |
| 12 | def test_iterables(self): |
| 13 | cases = [ |
| 14 | ('', ''), |
| 15 | ('', ()), |
| 16 | ('', []), |
| 17 | ('', ('', )), |
| 18 | ('', ['', ]), |
| 19 | ('a', ('a', )), |
| 20 | ('b', ['b', ]), |
| 21 | ('a b', ['a', 'b']), |
| 22 | ('a b', ('a', 'b')), |
| 23 | ('a b', 'a b'), |
| 24 | ('a b', (s for s in ['a', 'b'])), |
| 25 | ] |
| 26 | for expected, case in cases: |
| 27 | self.assertEqual(expected, util.scopes_to_string(case)) |
Joe Gregorio | e2233cd | 2013-01-24 15:46:23 -0500 | [diff] [blame] | 28 | |
| 29 | |
| 30 | class KeyConversionTests(unittest.TestCase): |
| 31 | |
| 32 | def test_key_conversions(self): |
| 33 | d = {'somekey': 'some value', 'another': 'something else', 'onemore': 'foo'} |
| 34 | tuple_key = util.dict_to_tuple_key(d) |
| 35 | |
| 36 | # the resulting key should be naturally sorted |
| 37 | self.assertEqual( |
| 38 | (('another', 'something else'), |
| 39 | ('onemore', 'foo'), |
| 40 | ('somekey', 'some value')), |
| 41 | tuple_key) |
| 42 | |
| 43 | # check we get the original dictionary back |
| 44 | self.assertEqual(d, dict(tuple_key)) |