def test_13_machine_resolver(self): # create the machineresolver and a config entry mr = MachineResolver("mr1", "mrtype1") mr_id = mr.save() self.assertTrue(mr_id > 0, mr_id) mrc = MachineResolverConfig(resolver="mr1", Key="key1", Value="value1") mrc.save() self.assertTrue(mrc > 0) # check that the config entry exist db_mrconf = MachineResolverConfig.query.filter( MachineResolverConfig.resolver_id == mr_id).first() self.assertTrue(db_mrconf is not None) # add a config value by ID mrc = MachineResolverConfig(resolver_id=mr_id, Key="key2", Value="v2") mrc.save() self.assertTrue(mrc > 0) # update config MachineResolverConfig(resolver_id=mr_id, Key="key2", Value="new value").save() # check if the value is updated. new_config = MachineResolverConfig.query.filter( MachineResolverConfig.Key == "key2").first() self.assertTrue(new_config.Value == "new value", new_config.Value) # Connect a machine to a token mt_id = MachineToken(machineresolver_id=mr_id, machine_id="client1", serial="serial1123", application="SSH").save() self.assertTrue(mt_id > 0, mt_id) # Connect another machine to a token token_id = Token.query.filter_by(serial="serial1123").first().id mt_id2 = MachineToken(machineresolver="mr1", machine_id="client2", token_id=token_id, application="LUKS").save() self.assertTrue(mt_id2 > mt_id, (mt_id2, mt_id)) # get the token that contains the machines db_token = Token.query.filter_by(serial="serial1123").first() # check the length of the machine list of the token self.assertTrue(len(db_token.machine_list) == 2, db_token.machine_list) machine2 = db_token.machine_list[1].machine_id self.assertTrue(machine2 == "client2", (machine2, db_token.machine_list)) # delete the machine resolver db_mr = MachineResolver.query.filter( MachineResolver.name == "mr1").first() db_mr.delete() # check that there is no machine resolver and no config entry db_mr = MachineResolver.query.filter( MachineResolver.name == "mr1").first() self.assertTrue(db_mr is None) db_mrconf = MachineResolverConfig.query.filter( MachineResolverConfig.resolver_id == mr_id).first() self.assertTrue(db_mrconf is None)
def test_13_machine_resolver(self): # create the machineresolver and a config entry mr = MachineResolver("mr1", "mrtype1") mr_id = mr.save() self.assertTrue(mr_id > 0, mr_id) mrc = MachineResolverConfig(resolver="mr1", Key="key1", Value="value1") mrc.save() self.assertTrue(mrc > 0) # check that the config entry exist db_mrconf = MachineResolverConfig.query.filter( MachineResolverConfig.resolver_id == mr_id).first() self.assertTrue(db_mrconf is not None) # add a config value by ID mrc = MachineResolverConfig(resolver_id=mr_id, Key="key2", Value="v2") mrc.save() self.assertTrue(mrc > 0) # update config MachineResolverConfig(resolver_id=mr_id, Key="key2", Value="new value").save() # check if the value is updated. new_config = MachineResolverConfig.query.filter( MachineResolverConfig.Key=="key2").first() self.assertTrue(new_config.Value == "new value", new_config.Value) # Connect a machine to a token mt_id = MachineToken(machineresolver_id=mr_id, machine_id="client1", serial="serial1123", application="SSH").save() self.assertTrue(mt_id > 0, mt_id) # Connect another machine to a token token_id = Token.query.filter_by(serial="serial1123").first().id mt_id2 = MachineToken(machineresolver="mr1", machine_id="client2", token_id=token_id, application="LUKS").save() self.assertTrue(mt_id2 > mt_id, (mt_id2, mt_id)) # get the token that contains the machines db_token = Token.query.filter_by(serial="serial1123").first() # check the length of the machine list of the token self.assertTrue(len(db_token.machine_list) == 2, db_token.machine_list) machine2 = db_token.machine_list[1].machine_id self.assertTrue(machine2 == "client2", (machine2, db_token.machine_list)) # delete the machine resolver db_mr = MachineResolver.query.filter(MachineResolver.name == "mr1").first() db_mr.delete() # check that there is no machine resolver and no config entry db_mr = MachineResolver.query.filter(MachineResolver.name == "mr1").first() self.assertTrue(db_mr is None) db_mrconf = MachineResolverConfig.query.filter( MachineResolverConfig.resolver_id == mr_id).first() self.assertTrue(db_mrconf is None)