systemconfig.SCPreferences

Here are the examples of the python api systemconfig.SCPreferences taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

19 Examples 7

Example 1

Project: macops Source File: systemconfig_test.py
Function: test_init
  @mock.patch.object(systemconfig, 'SCPreferencesCreate')
  def testInit(self, mock_scpc):
    """Test SCPreferences init."""
    mock_scpc.return_value = 999
    scp = systemconfig.SCPreferences()
    self.assertEqual(scp.session, 999)

Example 2

Project: macops Source File: systemconfig_test.py
Function: test_save
  @mock.patch.multiple(
      systemconfig, SCPreferencesCreate=mock.DEFAULT,
      SCPreferencesCommitChanges=mock.DEFAULT,
      SCPreferencesApplyChanges=mock.DEFAULT)
  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())

Example 3

Project: macops Source File: systemconfig_test.py
  @mock.patch.object(systemconfig, 'SCPreferencesCreate')
  def testSaveNoSession(self, mock_scpc):
    """Test SCPreferences Save, no session."""
    mock_scpc.return_value = None
    scp = systemconfig.SCPreferences()
    self.assertEqual(None, scp.Save())

Example 4

Project: macops Source File: systemconfig_test.py
  @mock.patch.multiple(
      systemconfig, SCPreferencesCreate=mock.DEFAULT,
      SCPreferencesCommitChanges=mock.DEFAULT)
  def testSaveCommitFailed(self, **mocks):
    """Test SCPreferences Save, commit failed."""
    mocks['SCPreferencesCreate'].return_value = 'session'
    mocks['SCPreferencesCommitChanges'].return_value = False
    scp = systemconfig.SCPreferences()
    self.assertRaises(systemconfig.SysconfigError, scp.Save)

Example 5

Project: macops Source File: systemconfig_test.py
  @mock.patch.multiple(
      systemconfig, SCPreferencesCreate=mock.DEFAULT,
      SCPreferencesCommitChanges=mock.DEFAULT,
      SCPreferencesApplyChanges=mock.DEFAULT)
  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)

Example 6

Project: macops Source File: systemconfig_test.py
  @mock.patch.multiple(systemconfig,
                       SCPreferencesCreate=mock.DEFAULT,
                       SCPreferencesPathGetValue=mock.DEFAULT)
  def testGetPathValueNoMatchingValue(self, **mocks):
    """Test SCPreferences GetPathValue, no matching value."""
    mocks['SCPreferencesCreate'].return_value = 'session'
    mocks['SCPreferencesPathGetValue'].return_value = {'not_it': 'value'}
    scp = systemconfig.SCPreferences()
    self.assertEqual(None, scp.GetPathValue('/some/path'))

Example 7

Project: macops Source File: systemconfig_test.py
  @mock.patch.multiple(systemconfig,
                       SCPreferencesCreate=mock.DEFAULT,
                       SCPreferencesPathGetValue=mock.DEFAULT)
  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('/'))

Example 8

Project: macops Source File: systemconfig_test.py
  @mock.patch.multiple(systemconfig,
                       SCPreferencesCreate=mock.DEFAULT,
                       SCPreferencesPathGetValue=mock.DEFAULT)
  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'))

Example 9

Project: macops Source File: systemconfig_test.py
  @mock.patch.multiple(systemconfig,
                       SCPreferencesCreate=mock.DEFAULT,
                       SCPreferencesPathGetValue=mock.DEFAULT,
                       SCPreferencesPathSetValue=mock.DEFAULT)
  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'))

Example 10

Project: macops Source File: systemconfig_test.py
  @mock.patch.multiple(systemconfig,
                       SCPreferencesCreate=mock.DEFAULT,
                       SCPreferencesPathGetValue=mock.DEFAULT,
                       SCPreferencesPathSetValue=mock.DEFAULT,
                       NSMutableDictionary=mock.DEFAULT)
  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'))

Example 11

Project: macops Source File: systemconfig_test.py
  @mock.patch.multiple(systemconfig.SCPreferences,
                       GetPathValue=mock.DEFAULT, SetPathValue=mock.DEFAULT)
  @mock.patch.multiple(systemconfig, SCPreferencesCreate=mock.DEFAULT)
  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())

Example 12

Project: macops Source File: systemconfig_test.py
  @mock.patch.multiple(systemconfig.SCPreferences,
                       GetPathValue=mock.DEFAULT, SetPathValue=mock.DEFAULT)
  @mock.patch.multiple(systemconfig, SCPreferencesCreate=mock.DEFAULT)
  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'])

Example 13

Project: macops Source File: systemconfig_test.py
Function: testgetcomputername
  @mock.patch.multiple(systemconfig.SCPreferences, GetPathValue=mock.DEFAULT)
  @mock.patch.multiple(systemconfig, SCPreferencesCreate=mock.DEFAULT)
  def testGetComputerName(self, **mocks):
    """Test SCPreferences GetComputerName."""
    mocks['GetPathValue'].return_value = 'computer'
    scp = systemconfig.SCPreferences()
    self.assertEqual('computer', scp.GetComputerName())

Example 14

Project: macops Source File: systemconfig_test.py
Function: testgetlocalname
  @mock.patch.multiple(systemconfig.SCPreferences, GetPathValue=mock.DEFAULT)
  @mock.patch.multiple(systemconfig, SCPreferencesCreate=mock.DEFAULT)
  def testGetLocalName(self, **mocks):
    """Test SCPreferences GetLocalName."""
    mocks['GetPathValue'].return_value = 'localname'
    scp = systemconfig.SCPreferences()
    self.assertEqual('localname', scp.GetComputerName())

Example 15

Project: macops Source File: systemconfig_test.py
Function: test_get_host_name
  @mock.patch.multiple(systemconfig.SCPreferences, GetPathValue=mock.DEFAULT)
  @mock.patch.multiple(systemconfig, SCPreferencesCreate=mock.DEFAULT)
  def testGetHostName(self, **mocks):
    """Test SCPreferences GetHostName."""
    mocks['GetPathValue'].return_value = 'hostname'
    scp = systemconfig.SCPreferences()
    self.assertEqual('hostname', scp.GetComputerName())

Example 16

Project: macops Source File: systemconfig_test.py
  @mock.patch.multiple(systemconfig.SCPreferences, GetPathValue=mock.DEFAULT,
                       SetPathValue=mock.DEFAULT)
  @mock.patch.multiple(systemconfig, SCPreferencesCreate=mock.DEFAULT)
  def testSetComputerName(self, **mocks):
    """Test SCPreferences SetComputerName."""
    mocks['GetPathValue'].return_value = 'computername'
    scp = systemconfig.SCPreferences()
    self.assertEqual(None, scp.SetComputerName('newname'))
    self.assertEqual(None, scp.SetComputerName('computername'))
    # Only called once from 'newname'
    self.assertEqual(1, mocks['SetPathValue'].call_count)

Example 17

Project: macops Source File: systemconfig_test.py
  @mock.patch.multiple(systemconfig.SCPreferences, GetPathValue=mock.DEFAULT,
                       SetPathValue=mock.DEFAULT)
  @mock.patch.multiple(systemconfig, SCPreferencesCreate=mock.DEFAULT)
  def testSetLocalName(self, **mocks):
    """Test SCPreferences SetLocalName."""
    mocks['GetPathValue'].return_value = 'localname'
    scp = systemconfig.SCPreferences()
    self.assertEqual(None, scp.SetComputerName('newname'))
    self.assertEqual(None, scp.SetComputerName('localname'))
    # Only called once from 'newname'
    self.assertEqual(1, mocks['SetPathValue'].call_count)

Example 18

Project: macops Source File: systemconfig_test.py
Function: test_set_hostname
  @mock.patch.multiple(systemconfig.SCPreferences, GetPathValue=mock.DEFAULT,
                       SetPathValue=mock.DEFAULT)
  @mock.patch.multiple(systemconfig, SCPreferencesCreate=mock.DEFAULT)
  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)

Example 19

Project: macops Source File: systemconfig_test.py
  @mock.patch.multiple(systemconfig.SCPreferences,
                       GetPathValue=mock.DEFAULT, SetPathValue=mock.DEFAULT)
  @mock.patch.multiple(systemconfig, SCPreferencesCreate=mock.DEFAULT)
  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'])