def setUp(self): self.sm = BTreeScopeManager() self.client = 'client_key' self.access = 'access_key'
class BTreeScopeManagerTestCase(unittest.TestCase): """ Test the storage and retrieval of client and access key specific scopes. """ def setUp(self): self.sm = BTreeScopeManager() self.client = 'client_key' self.access = 'access_key' def test_0000_base(self): self.assertRaises(KeyError, self.sm.delClientScope, self.client) self.assertRaises(KeyError, self.sm.delAccessScope, self.access) self.assertRaises(KeyError, self.sm.getClientScope, self.client) self.assertRaises(KeyError, self.sm.getAccessScope, self.access) self.assertTrue( self.sm.getClientScope(self.client, default=None) is None) self.assertTrue( self.sm.getAccessScope(self.access, default=None) is None) def test_0010_set_get(self): scope1 = 'http://example.com/scope.1' scope2 = 'http://example.com/scope.2' self.sm.setClientScope(self.client, scope1) self.assertEqual(self.sm.getClientScope(self.client), scope1) self.sm.setAccessScope(self.access, scope2) self.assertEqual(self.sm.getAccessScope(self.access), scope2) def test_0011_set_duplicate(self): scope1 = 'http://example.com/scope.1' scope2 = 'http://example.com/scope.2' self.sm.setClientScope(self.client, scope1) self.assertRaises(KeyExistsError, self.sm.setClientScope, self.client, scope1) self.sm.setAccessScope(self.access, scope2) self.assertRaises(KeyExistsError, self.sm.setAccessScope, self.access, scope2) def test_0020_del(self): scope1 = 'http://example.com/scope.1' scope2 = 'http://example.com/scope.2' self.sm.setClientScope(self.client, scope1) self.sm.delClientScope(self.client) # Can "hide" exception using optional parameter like get/set. self.sm.delClientScope(self.client, None) self.sm.setClientScope(self.client, scope2) self.assertEqual(self.sm.getClientScope(self.client), scope2) self.sm.setAccessScope(self.access, scope1) # This may be considered dangerous as this does not tie into the # access token in any way. Subclasses may need to handle this # to ensure the content owner is aware of scope changes. self.sm.delAccessScope(self.access) # New scope is updated. self.sm.setAccessScope(self.access, scope2) self.assertEqual(self.sm.getAccessScope(self.access), scope2)