def test_valid(self): """Testing function valid.""" # Initialize key variables devicename = self.data['devicename'] id_agent = self.data['id_agent'] last_timestamp = self.data['timestamp'] # Drop the database and create tables unittest_setup_db.TestData() # Add record to the database record = Agent(id_agent=general.encode(id_agent)) database = db.Database() database.add(record, 1040) # Test must be good as DeviceAgent last_timestamp not updated result = validate._CheckDuplicates(self.data) self.assertEqual(result.valid(), True) # Get idx_agent value from database data = db_agent.GetIDAgent(id_agent) idx_agent = data.idx_agent() # Add record to the database record = Device(devicename=general.encode(devicename)) database = db.Database() database.add(record, 1024) # Test must be good as DeviceAgent last_timestamp not updated result = validate._CheckDuplicates(self.data) self.assertEqual(result.valid(), True) # Get idx of newly added device device_info = db_device.GetDevice(devicename) idx_device = device_info.idx_device() # Update DeviceAgent table if hagent.device_agent_exists(idx_device, idx_agent) is False: # Add to DeviceAgent table record = DeviceAgent(idx_device=idx_device, idx_agent=idx_agent) database = db.Database() database.add(record, 1055) # Test must be good as DeviceAgent last_timestamp not updated result = validate._CheckDuplicates(self.data) self.assertEqual(result.valid(), True) # Update database with timestamp database = db.Database() session = database.session() record = session.query(DeviceAgent).filter( and_(DeviceAgent.idx_device == idx_device, DeviceAgent.idx_agent == idx_agent)).one() record.last_timestamp = last_timestamp database.commit(session, 1044) # Test must fail as DeviceAgent last_timestamp not updated result = validate._CheckDuplicates(self.data) self.assertEqual(result.valid(), False)
def test___init__(self): """Testing function __init__.""" # Test with value that is not a dict result = validate._CheckDuplicates('string') self.assertEqual(result.valid(), False)