def test_insert_rows(self): """Testing method / function insert_rows.""" # Initialize key variables key = data.hashstring(str(random())) value = data.hashstring(str(random())) result = pair.pair_exists(key, value) self.assertFalse(result) # Create entry and check pair.insert_rows((key, value)) result = pair.pair_exists(key, value) self.assertTrue(bool(result)) self.assertTrue(isinstance(result, int))
def test_insert_rows(self): """Testing method / function insert_rows.""" # Initialize key variables polling_interval = 1 checksum = data.hashstring(str(random())) key = data.hashstring(str(random())) value = data.hashstring(str(random())) # Create a new Agent entry 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) # Insert values in tables pair.insert_rows((key, value)) idx_pair = pair.pair_exists(key, value) datapoint.insert_row(checksum, DATA_FLOAT, polling_interval, idx_agent) idx_datapoint = datapoint.checksum_exists(checksum) # Create entry and check result = glue.glue_exists(idx_datapoint, idx_pair) self.assertFalse(result) glue.insert_rows(idx_datapoint, idx_pair) result = glue.glue_exists(idx_datapoint, idx_pair) self.assertTrue(bool(result)) self.assertTrue(isinstance(result, int))
def test_idx_pairs(self): """Testing method / function idx_pairs.""" # Initialize key variables checksum = data.hashstring(str(random())) polling_interval = 1 keypairs = [] idx_pairs = [] for _ in range(0, 10): time.sleep(0.05) key = data.hashstring(str(random())) value = data.hashstring(str(random())) keypairs.append((key, value)) # Create a new Agent entry 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) # Insert values in tables pair.insert_rows(keypairs) datapoint.insert_row(checksum, DATA_FLOAT, polling_interval, idx_agent) idx_datapoint = datapoint.checksum_exists(checksum) # Test for key, value in keypairs: idx_pairs.append(pair.pair_exists(key, value)) glue.insert_rows(idx_datapoint, idx_pairs) result = glue.idx_pairs(idx_datapoint) self.assertEqual(len(result), len(idx_pairs)) for idx_pair in idx_pairs: self.assertTrue(idx_pair in result)
def test_pairs(self): """Testing method / function pairs.""" pair1 = ('key1', data.hashstring(str(random()))) pair2 = ('key2', data.hashstring(str(random()))) pap = 'y' # Create a PattooDBrecord record = PattooDBrecord(pattoo_checksum='1', pattoo_key='3', pattoo_agent_id=4, pattoo_agent_polling_interval=1, pattoo_timestamp=5, pattoo_data_type=DATA_FLOAT, pattoo_value=6, pattoo_agent_polled_target='x', pattoo_agent_program=pap, pattoo_agent_hostname='z', pattoo_metadata=[pair1, pair2]) # Pairs shouldn't exist self.assertFalse( pair.pair_exists(get.make_key(pap, pair1[0]), pair1[1])) self.assertFalse( pair.pair_exists(get.make_key(pap, pair2[0]), pair2[1])) # Insert items result = get.pairs(record) self.assertTrue(pair.pair_exists(get.make_key(pap, pair1[0]), pair1[1])) self.assertTrue(pair.pair_exists(get.make_key(pap, pair2[0]), pair2[1])) self.assertTrue( pair.pair_exists(get.make_key(pap, pair1[0]), pair1[1]) in result) self.assertTrue( pair.pair_exists(get.make_key(pap, pair2[0]), pair2[1]) in result)
def test_multiprocess_pairs(self): """Testing method / function multiprocess_pairs.""" # Initialize key variables items = make_records() records = items['records'] # Key-value pair should not exist for record in records: key = record.pattoo_key value = record.pattoo_value result = pair.pair_exists(key, value) self.assertFalse(result) # Insert pairs as necessary process = ingest_data.Records([records]) process.multiprocess_pairs() # Key-value pair should exist for record in records: key = record.pattoo_key value = record.pattoo_value result = pair.pair_exists(key, value) self.assertFalse(result)
def test_idx_pairs(self): """Testing method / function idx_pairs.""" # Initialize key variables keypairs = [] idx_pairs = [] for _ in range(0, 10): time.sleep(0.05) key = data.hashstring(str(random())) value = data.hashstring(str(random())) keypairs.append((key, value)) # Insert values in tables pair.insert_rows(keypairs) # Test for key, value in keypairs: idx_pairs.append(pair.pair_exists(key, value)) result = pair.idx_pairs(keypairs) self.assertEqual(len(result), len(idx_pairs)) for idx_pair in idx_pairs: self.assertTrue(idx_pair in result)