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 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 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 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)