1# Copyright 2015 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import unittest 6 7from dashboard import namespaced_stored_object 8from dashboard import stored_object 9from dashboard import testing_common 10 11 12class NamespacedStoredObjectTest(testing_common.TestCase): 13 14 def setUp(self): 15 super(NamespacedStoredObjectTest, self).setUp() 16 testing_common.SetIsInternalUser('internal@chromium.org', True) 17 testing_common.SetIsInternalUser('foo@chromium.org', False) 18 19 def tearDown(self): 20 super(NamespacedStoredObjectTest, self).tearDown() 21 self.UnsetCurrentUser() 22 23 def testSet_InternalUser_InternalVersionSet(self): 24 self.SetCurrentUser('internal@chromium.org') 25 namespaced_stored_object.Set('foo', 12345) 26 self.assertEqual(12345, stored_object.Get('internal_only__foo')) 27 self.assertIsNone(stored_object.Get('externally_visible__foo')) 28 29 def testSet_ExternalUser_ExternalVersionSet(self): 30 self.SetCurrentUser('foo@chromium.org') 31 namespaced_stored_object.Set('foo', 12345) 32 self.assertIsNone(stored_object.Get('internal_only__foo')) 33 self.assertEqual(12345, stored_object.Get('externally_visible__foo')) 34 35 def testSetExternal_InternalUser_ExternalVersionSet(self): 36 self.SetCurrentUser('internal@chromium.org') 37 namespaced_stored_object.SetExternal('foo', 12345) 38 self.assertIsNone(stored_object.Get('internal_only__foo')) 39 self.assertEqual(12345, stored_object.Get('externally_visible__foo')) 40 41 def testGet_NothingSet_NoneReturned(self): 42 self.assertIsNone(namespaced_stored_object.Get('foo')) 43 44 def testGet_InternalUser_InternalVersionReturned(self): 45 self.SetCurrentUser('internal@chromium.org') 46 stored_object.Set('internal_only__foo', [1, 2, 3]) 47 stored_object.Set('externally_visible__foo', [4, 5, 6]) 48 self.assertEqual([1, 2, 3], namespaced_stored_object.Get('foo')) 49 50 def testGet_ExternalUser_ExternalVersionReturned(self): 51 self.SetCurrentUser('foo@chromium.org') 52 stored_object.Set('internal_only__foo', [1, 2, 3]) 53 stored_object.Set('externally_visible__foo', [4, 5, 6]) 54 self.assertEqual([4, 5, 6], namespaced_stored_object.Get('foo')) 55 56 def testGetExternal_InternalUser_ExternalVersionReturned(self): 57 self.SetCurrentUser('internal@chromium.org') 58 stored_object.Set('internal_only__foo', [1, 2, 3]) 59 stored_object.Set('externally_visible__foo', [4, 5, 6]) 60 self.assertEqual([4, 5, 6], namespaced_stored_object.GetExternal('foo')) 61 62 def testDelete_BothVersionsDeleted(self): 63 stored_object.Set('internal_only__foo', [1, 2, 3]) 64 stored_object.Set('externally_visible__foo', [4, 5, 6]) 65 namespaced_stored_object.Delete('foo') 66 self.assertIsNone(stored_object.Get('internal_only__foo')) 67 self.assertIsNone(stored_object.Get('externally_visible__foo')) 68 69 70if __name__ == '__main__': 71 unittest.main() 72