def testAppend(self): dc = DeviceConfigurations() try: dc.append(self.config_one) except Exception, e: logging.error('FAILURE: append failed ' + str(dc.getContexts()) + ': ' + str(e))
def testConfigInstantiate(self): dc = None dc = DeviceConfigurations() dc.setConfig(self.config_line) a = dc.getContexts() assert len(a) == 1 and a[ 0] == default_context, 'single config on intantiate doenst work'
def testDiffDifferent(self): dc1 = None dc2 = None dc1 = DeviceConfigurations() dc1.setConfig(self.config_line) dc2 = DeviceConfigurations() dc2.append(self.config_three) diff = dc1.diff(dc2) assert len(diff) > 0, 'diff() of different failed'
def testDiffSame(self): dc1 = None dc2 = None dc1 = DeviceConfigurations() dc1.setConfig(self.config_line) dc2 = DeviceConfigurations() dc2.setConfig(self.config_line) diff = dc1.diff(dc2) assert len(diff) == 0, 'diff() of same failed'
def testCmpSame(self): dc1 = None dc2 = None dc1 = DeviceConfigurations() dc1.setConfig(self.config_line) dc2 = DeviceConfigurations() dc2.setConfig(self.config_line) assert cmp(dc1, dc2) == 0, 'cmp() with same failed'
def testCmpDifferent(self): dc1 = None dc2 = None dc1 = DeviceConfigurations() dc1.setConfig(self.config_line) dc2 = DeviceConfigurations() dc2.append(self.config_two) c = cmp(dc1, dc2) assert not c == 0, 'cmp() with different failed (' + str( c) + '): \ndc1=' + str(dc1) + "\ndc2=" + str(dc2)
def testDiffSame(self): store = ConfigurationStorage(dbhost=self._dbhost, dbname=self._dbname, user=self._dbuser, passwd=self._dbpasswd) config_one = DeviceConfigurations() config_one.setConfig(["hello there\n", "this is a test"]) config_two = DeviceConfigurations() config_two.setConfig(["hello there\n", "this is a test"]) ret = store.isChanged(config_one, config_two) #logging.warn( diff ) assert ret == False, "same configs showed different diffs"
def testBAppendDeviceConfigurations(self): """ add configurations to deviceconfigurations object """ dc = DeviceConfigurations() conf = Configuration() conf.set(['hello there\n', 'this is a test']) #conf.setContext( 'context_one' ) dc.append(conf) confResult = dc.getConfig('system') conf2 = Configuration() conf2.set(['hi there\n', 'this is also a test']) conf2.setContext('context_two') dc.append(conf2) confResult2 = dc.getConfig('context_two') #logging.warn( "confResult.get()[0]: " + confResult.get()[0] ) assert confResult.get()[0] == 'hello there\n' \ and confResult2.get()[0] == 'hi there\n'
def testDetermineMergedContexts(self): store = ConfigurationStorage(dbhost=self._dbhost, dbname=self._dbname, user=self._dbuser, passwd=self._dbpasswd) # create a device configuration o bject from teh raw strings config_one = DeviceConfigurations() config_one.setConfig(["hello there\n", "this is a test"]) # construct a device configuration ob ject from a configuration object config_two = DeviceConfigurations() conf = Configuration() conf.set(["hello there\n", "this is a test"]) conf.setContext('something_else') config_two.append(conf) array = store.determineMergedContexts(config_one, config_two) assert array == ['something_else', 'system' ], 'determining merged contexts failed: ' + str(array)
def testContext(self): dc = DeviceConfigurations() string = 'test_context' dc.setConfig(self.config_one, context=string) assert dc.getContexts()[0] == string, 'context names do not match'
def testDefaultContext(self): dc = DeviceConfigurations() assert dc.default_context == default_context, 'default context changed'
def testInit(self): dc = None try: dc = DeviceConfigurations() except Exception, e: pass