Esempio n. 1
0
 def testSaveApplyFailed(self, **mocks):
     """Test SCPreferences Save, apply failed."""
     mocks['SCPreferencesCreate'].return_value = 'session'
     mocks['SCPreferencesCommitChanges'].return_value = True
     mocks['SCPreferencesApplyChanges'].return_value = False
     scp = systemconfig.SCPreferences()
     self.assertRaises(systemconfig.SysconfigError, scp.Save)
Esempio n. 2
0
 def testSetPathValueNewPath(self, **mocks):
     """Test SCPreferences SetPathValue, new path created."""
     mocks['SCPreferencesCreate'].return_value = 'session'
     mocks['SCPreferencesPathGetValue'].return_value = None
     mocks['NSMutableDictionary'].alloc().init.return_value = {}
     scp = systemconfig.SCPreferences()
     self.assertEqual(None, scp.SetPathValue('/some/path', 'newval'))
Esempio n. 3
0
 def testSave(self, **mocks):
     """Test SCPreferences Save success."""
     mocks['SCPreferencesCreate'].return_value = 'session'
     mocks['SCPreferencesCommitChanges'].return_value = True
     mocks['SCPreferencesApplyChanges'].return_value = True
     scp = systemconfig.SCPreferences()
     self.assertEqual(None, scp.Save())
Esempio n. 4
0
 def testSetHostName(self, **mocks):
     """Test SCPreferences SetHostName."""
     mocks['GetPathValue'].return_value = 'hostname'
     scp = systemconfig.SCPreferences()
     self.assertEqual(None, scp.SetComputerName('newname'))
     self.assertEqual(None, scp.SetComputerName('hostname'))
     # Only called once from 'newname'
     self.assertEqual(1, mocks['SetPathValue'].call_count)
Esempio n. 5
0
 def testGetPathValue(self, mock_osp, **mocks):
     """Test SCPreferences GetPathValue."""
     mocks['SCPreferencesCreate'].return_value = 'session'
     mock_osp.basename.return_value = 'path'
     mock_osp.dirname.return_value = '/some'
     mocks['SCPreferencesPathGetValue'].return_value = {'path': 'value'}
     scp = systemconfig.SCPreferences()
     self.assertEqual('value', scp.GetPathValue('/some/path'))
Esempio n. 6
0
 def testSetProxyDisableProxy(self, **mocks):
     """Test SCPreferences SetProxy, disabled, default proxy."""
     interfaces = {
         'interface': {
             'Proxies': {
                 'ProxyAutoConfigEnable': 1,
                 'ProxyAutoConfigURLString': 'url'
             }
         }
     }
     mocks['GetPathValue'].return_value = interfaces
     scp = systemconfig.SCPreferences()
     self.assertEqual(None, scp.SetProxy(enable=False))
     self.assertEqual(
         0, interfaces['interface']['Proxies']['ProxyAutoConfigEnable'])
Esempio n. 7
0
 def testSetProxy(self, **mocks):
     """Test SCPreferences SetProxy, enabled, default proxy."""
     interfaces = {
         'interface': {
             'Proxies': {
                 'ProxyAutoConfigEnable': 0,
                 'ProxyAutoConfigURLString': 'url'
             }
         }
     }
     mocks['GetPathValue'].return_value = interfaces
     interfaces['interface']['ProxyAutoConfigEnable'] = 1
     interfaces['interface']['ProxyAutoConfigURLString'] = (
         systemconfig.CORP_PROXY)
     scp = systemconfig.SCPreferences()
     self.assertEqual(None, scp.SetProxy())
     self.assertEqual(
         1, interfaces['interface']['Proxies']['ProxyAutoConfigEnable'])
     self.assertEqual(
         systemconfig.CORP_PROXY,
         interfaces['interface']['Proxies']['ProxyAutoConfigURLString'])
Esempio n. 8
0
 def testGetHostName(self, **mocks):
     """Test SCPreferences GetHostName."""
     mocks['GetPathValue'].return_value = 'hostname'
     scp = systemconfig.SCPreferences()
     self.assertEqual('hostname', scp.GetComputerName())
Esempio n. 9
0
 def testSetProxyNoInterfacesWithProxySupport(self, **mocks):
     """Test SCPreferences SetProxy, no interfaces that support proxies found."""
     interfaces = {'interface': {'nope': 0}}
     mocks['GetPathValue'].return_value = interfaces
     scp = systemconfig.SCPreferences()
     self.assertEqual(None, scp.SetProxy())
Esempio n. 10
0
 def testSetPathValue(self, **mocks):
     """Test SCPreferences SetPathValue."""
     mocks['SCPreferencesCreate'].return_value = 'session'
     mocks['SCPreferencesPathGetValue'].return_value = {'path': 'value'}
     scp = systemconfig.SCPreferences()
     self.assertEqual(None, scp.SetPathValue('/some/path', 'newval'))
Esempio n. 11
0
 def testGetPathValueNoMatchingPath(self, **mocks):
     """Test SCPreferences GetPathValue, no matching path."""
     mocks['SCPreferencesCreate'].return_value = 'session'
     mocks['SCPreferencesPathGetValue'].return_value = None
     scp = systemconfig.SCPreferences()
     self.assertEqual(None, scp.GetPathValue('/some/path'))
Esempio n. 12
0
 def testGetPathValueWholeTree(self, **mocks):
     """Test SCPreferences GetPathValue, get whole tree."""
     mocks['SCPreferencesCreate'].return_value = 'session'
     mocks['SCPreferencesPathGetValue'].return_value = 'whole tree'
     scp = systemconfig.SCPreferences()
     self.assertEqual('whole tree', scp.GetPathValue('/'))
Esempio n. 13
0
 def testSaveNoSession(self, mock_scpc):
     """Test SCPreferences Save, no session."""
     mock_scpc.return_value = None
     scp = systemconfig.SCPreferences()
     self.assertEqual(None, scp.Save())
Esempio n. 14
0
 def testInit(self, mock_scpc):
     """Test SCPreferences init."""
     mock_scpc.return_value = 999
     scp = systemconfig.SCPreferences()
     self.assertEqual(scp.session, 999)