def test_records(self): """Testing method / function records.""" # Initialize key variables pattoo_values = create_cache() # Read data from directory cache = Cache() all_records = cache.records() # Test self.assertEqual(len(all_records), 1) self.assertEqual(len(all_records[0]), 1) result = all_records[0][0] self.assertEqual(result.pattoo_key, pattoo_values['pattoo_key']) self.assertEqual(result.pattoo_data_type, 99) self.assertEqual(result.pattoo_value, pattoo_values['pattoo_value']) self.assertEqual(result.pattoo_agent_polled_target, pattoo_values['pattoo_agent_polled_target']) self.assertEqual(result.pattoo_agent_program, pattoo_values['pattoo_agent_program']) self.assertEqual(result.pattoo_agent_hostname, pattoo_values['pattoo_agent_hostname']) self.assertEqual(result.pattoo_agent_polling_interval, '20000') self.assertEqual(result.pattoo_metadata, []) self.assertEqual(result.pattoo_agent_id, pattoo_values['pattoo_agent_id']) # Purge cache to make sure there are no extraneous files cache.purge()
def test_purge(self): """Testing method / function purge.""" # Initialize key variables config = ServerConfig() cache_directory = config.agent_cache_directory(PATTOO_API_AGENT_NAME) # Initialize key variables _ = create_cache() # Test result = files.read_json_files(cache_directory) self.assertTrue(bool(result)) # Test - Purge cache = Cache() cache.purge() # Test result = files.read_json_files(cache_directory, die=False) self.assertFalse(bool(result))
def test_process_cache(self): """Testing method / function process_cache.""" # Initialize key variables polling_interval = 20 _pi = polling_interval * 1000 _ = create_cache() # Read data from directory cache = Cache() all_records = cache.records() # Test self.assertEqual(len(all_records), 1) self.assertEqual(len(all_records[0]), 1) pdbr = all_records[0][0] # Datapoint should not exist before ingest checksum = pdbr.pattoo_checksum timestamp = pdbr.pattoo_timestamp value = pdbr.pattoo_value self.assertFalse(datapoint.checksum_exists(checksum)) # Ingest using process_cache result = files_test.process_cache(fileage=0) self.assertTrue(result) # Test (checksum should exist) idx_datapoint = datapoint.checksum_exists(checksum) self.assertTrue(bool(idx_datapoint)) # Test (Single data entry should exist) obj = datapoint.DataPoint(idx_datapoint) result = obj.data(timestamp, timestamp) self.assertEqual(len(result), 1) key_pair = result[0] self.assertEqual(key_pair['timestamp'], times.normalized_timestamp(_pi, timestamp)) self.assertEqual(key_pair['value'], value)