def test_assign(self): """Testing method / function assign.""" # Add an entry to the database name = data.hashstring(str(random())) pair_xlate_group.insert_row(name) # Make sure it exists idx_pair_xlate_group = pair_xlate_group.exists(name) # Verify the index exists result = pair_xlate_group.idx_exists(idx_pair_xlate_group) self.assertTrue(result) # Prepare for adding an entry to the database agent_id = data.hashstring(str(random())) agent_target = data.hashstring(str(random())) agent_program = data.hashstring(str(random())) # Make sure it does not exist result = agent.exists(agent_id, agent_target) self.assertFalse(bool(result)) # Add an entry to the database agent.insert_row(agent_id, agent_target, agent_program) idx_agent = agent.exists(agent_id, agent_target) # Assign agent.assign(idx_agent, idx_pair_xlate_group) # Get assigned idx_pair_xlate_group for the agent group with db.db_query(20099) as session: result = session.query(Agent.idx_pair_xlate_group).filter( Agent.idx_agent == idx_agent).one() idx_new = result.idx_pair_xlate_group self.assertEqual(idx_pair_xlate_group, idx_new)
def test_idx_pair_xlate_group(self): """Testing method / function idx_pair_xlate_group.""" # Create a new PairXlateGroup entry translation = data.hashstring(str(random())) pair_xlate_group.insert_row(translation) idx_pair_xlate_group = pair_xlate_group.exists(translation) # Add an entry to the database translation = data.hashstring(str(random())) agent_group.insert_row(translation) # Make sure it exists idx_agent_group = agent_group.exists(translation) # Assign AgentGroup agent_group.assign(idx_agent_group, idx_pair_xlate_group) # Add an entry to the database agent_id = data.hashstring(str(random())) agent_target = data.hashstring(str(random())) agent_program = data.hashstring(str(random())) agent.insert_row(agent_id, agent_target, agent_program) idx_agent = agent.exists(agent_id, agent_target) # Assign Agent got AgentGroup agent.assign(idx_agent, idx_agent_group) # Test result = agent.idx_pair_xlate_group(agent_id) self.assertEqual(result, idx_pair_xlate_group)
def _process_agent(args): """Process agent cli arguments. Args: args: CLI arguments Returns: None """ # Validate parameters if bool(agent_group.idx_exists(args.idx_agent_group)) is False: log_message = ('idx_agent_group "{}" not found.'.format( args.idx_agent_group)) log.log2die(20068, log_message) if bool(agent.idx_exists(args.idx_agent)) is False: log_message = ('idx_agent "{}" not found.'.format(args.idx_agent)) log.log2die(20060, log_message) # Assign agent.assign(args.idx_agent, args.idx_agent_group)
def test_assign(self): """Testing method / function assign.""" # Create a new AgentGroup entry translation = data.hashstring(str(random())) agent_group.insert_row(translation) idx_agent_group = agent_group.exists(translation) # Prepare for adding an entry to the database agent_id = data.hashstring(str(random())) agent_target = data.hashstring(str(random())) agent_program = data.hashstring(str(random())) # Make sure it does not exist result = agent.exists(agent_id, agent_target) self.assertFalse(bool(result)) # Add an entry to the database agent.insert_row(agent_id, agent_target, agent_program) idx_agent = agent.exists(agent_id, agent_target) # Get current idx_agent for the agent with db.db_query(20001) as session: result = session.query(Agent.idx_agent_group).filter( Agent.idx_agent == idx_agent).one() idx_original = result.idx_agent_group self.assertNotEqual(idx_agent_group, idx_original) # Assign agent.assign(idx_agent, idx_agent_group) # Get current idx_agent_group for the agent group with db.db_query(20099) as session: result = session.query(Agent.idx_agent_group).filter( Agent.idx_agent == idx_agent).one() idx_new = result.idx_agent_group self.assertEqual(idx_agent_group, idx_new)