blob: 2d67316772ebaaef419a5914562b77df739206d8 [file] [log] [blame]
Joe Gregorio5cf5d122012-11-16 16:36:12 -05001"""Unit tests for oauth2client.util."""
2
3__author__ = 'jcgregorio@google.com (Joe Gregorio)'
4
5import unittest
6
7from oauth2client import util
8
9
10class 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 Gregorioe2233cd2013-01-24 15:46:23 -050028
29
30class 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))