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)
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'))
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())
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)
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'))
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'])
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'])
def testGetHostName(self, **mocks): """Test SCPreferences GetHostName.""" mocks['GetPathValue'].return_value = 'hostname' scp = systemconfig.SCPreferences() self.assertEqual('hostname', scp.GetComputerName())
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())
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'))
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'))
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('/'))
def testSaveNoSession(self, mock_scpc): """Test SCPreferences Save, no session.""" mock_scpc.return_value = None scp = systemconfig.SCPreferences() self.assertEqual(None, scp.Save())
def testInit(self, mock_scpc): """Test SCPreferences init.""" mock_scpc.return_value = 999 scp = systemconfig.SCPreferences() self.assertEqual(scp.session, 999)