def test_del_valid(self): # Write on value and delete it data = RPD_DB() core = db.operational.t_CCAPCapabilities() core.is_principal = True core.ip_addr = '2.2.2.2' core.is_active = True data.set_val(['oper', 'CCAPCapabilities'], core) data.del_val(['oper', 'CCAPCapabilities', '2.2.2.2', 'is_active']) self.assertIsNone( data.get_val(['oper', 'CCAPCapabilities', 'is_active']))
def test_db_file_update(self): """Insert/delete CCAPCores and check if DB file was updated.""" data = RPD_DB() self.assertNotIn('is_active', open(data.DB_FNAME).read()) core = db.operational.t_CCAPCapabilities() core.is_active = True core.ip_addr = "1.1.1.1" data.set_val(['oper', 'CCAPCapabilities'], core) self.assertIn('is_active', open(data.DB_FNAME).read()) data.del_val(['oper', 'CCAPCapabilities', '1.1.1.1']) self.assertNotIn('is_active', open(data.DB_FNAME).read())
def test_del_unset(self): # Create one value and delete another value, which was not set data = RPD_DB() core = db.operational.t_CCAPCapabilities() core.is_principal = True core.ip_addr = '2.2.2.2' data.set_val(['oper', 'CCAPCapabilities'], core) data.del_val(['oper', 'CCAPCapabilities', '2.2.2.2', 'is_active']) self.assertIsNone( data.get_val(['oper', 'CCAPCapabilities', '2.2.2.2', 'is_active'])) self.assertTrue( data.get_val( ['oper', 'CCAPCapabilities', '2.2.2.2', 'is_principal']))
def test_delete_repeated(self): """Delete repeated object & leaves in it.""" data = RPD_DB() self._create_repeated_list(data) # Delete leaf data.del_val([ 'cfg', 'DsOfdmProfile', 2, 'DsOfdmSubcarrierModulation', 21, 'Modulation' ]) self.assertIsNone( data.get_val([ 'cfg', 'DsOfdmProfile', 2, 'DsOfdmSubcarrierModulation', 21, 'Modulation' ])) self.assertIsNotNone( data.get_val( ['cfg', 'DsOfdmProfile', 2, 'DsOfdmSubcarrierModulation', 21])) # Delete key leaf => forbidden with self.assertRaises(DBKeyError): data.del_val([ 'cfg', 'DsOfdmProfile', 1, 'DsOfdmSubcarrierModulation', 11, 'StartSubcarrierId' ]) # Delete last (one) element from repeated list data.del_val( ['cfg', 'DsOfdmProfile', 1, 'DsOfdmSubcarrierModulation', 11]) value = data.get_val( ['cfg', 'DsOfdmProfile', 1, 'DsOfdmSubcarrierModulation']) self.assertIsNone(value) # Delete list of elements value = data.get_val( ['cfg', 'DsOfdmProfile', 2, 'DsOfdmSubcarrierModulation']) self.assertEqual(len(value), 2) data.del_val(['cfg', 'DsOfdmProfile', 2, 'DsOfdmSubcarrierModulation']) value = data.get_val( ['cfg', 'DsOfdmProfile', 2, 'DsOfdmSubcarrierModulation']) self.assertIsNone(value) # Delete config data.del_val(['cfg']) value = data.get_val(['cfg']) self.assertIsNone(value)
def test_trees_merge_no_conflicts(self): data = RPD_DB() data.data.Clear() c = self._create_filled_cfg() # Add one element, merge again and check if value was not overwritten data.data.cfg.RpdCapabilities.NumBdirPorts = 5 data.merge_from_tree(['cfg'], c) str1 = data.data.cfg.SerializeToString() str2 = c.SerializeToString() self.assertNotEqual(str1, str2) self.assertEqual( data.get_val(['cfg', 'RpdCapabilities', 'NumBdirPorts']), 5) # Delete additional item, check if buffers are same now data.del_val(['cfg', 'RpdCapabilities', 'NumBdirPorts']) str1 = data.data.cfg.SerializeToString() self.assertEqual(str1, str2)
def test_path_invalid(self): # Delete with wrong path data = RPD_DB() # If parent (oper) has no children, then exception is not raised, # because parent exists and we don't have reason to check children data.del_val(['oper', 'CCAPCapabilities', 'test']) self.assertIsNone(data.get_val(['oper', 'CCAPCapabilities', 'test'])) core = db.operational.t_CCAPCapabilities() core.is_active = True core.ip_addr = '2.2.2.2' data.set_val(['oper', 'CCAPCapabilities'], core) # Deleting from repeated list, element, which does not exist data.del_val(['oper', 'CCAPCapabilities', 'test']) # Deleting from path, which is invalid with self.assertRaises(DBKeyError): data.del_val(['oper', 'test']) # Getting value from repeated list, path is valid data.del_val(['oper', 'CCAPCapabilities', 'test']) # Getting value from invalid path with self.assertRaises(DBKeyError): data.get_val(['oper', 'test']) with self.assertRaises(DBKeyError): data.set_val(['oper', 'CCAPCapabilities', 'test'], True)