Esempio n. 1
0
    def test_process_db_records(self):
        """Testing method / function process_db_records."""
        # Initialize key variables
        items = make_records()
        timestamps = items['timestamps']
        records = items['records']
        expected = items['expected']
        checksum = items['checksum']

        # Entry should not exist
        result = datapoint.checksum_exists(checksum)
        self.assertFalse(result)

        # Create key-pair values in the database
        kvps = get.key_value_pairs(records)
        pair.insert_rows(kvps)

        # Insert
        ingest_data.process_db_records(records)

        # Get data from database
        idx_datapoint = datapoint.checksum_exists(checksum)
        _dp = datapoint.DataPoint(idx_datapoint)
        ts_start = min(timestamps)
        ts_stop = max(timestamps)
        results = _dp.data(ts_start, ts_stop)

        # Test
        for index, result in enumerate(results):
            self.assertEqual(result['value'], expected[index]['value'])
            self.assertEqual(result['timestamp'], expected[index]['timestamp'])
Esempio n. 2
0
    def test_multiprocess_data(self):
        """Testing method / function multiprocess_data."""
        # Initialize key variables
        items = make_records()
        timestamps = items['timestamps']
        records = items['records']
        expected = items['expected']
        checksum = items['checksum']

        # Entry should not exist
        result = datapoint.checksum_exists(checksum)
        self.assertFalse(result)

        # Test
        process = ingest_data.Records([records])
        process.multiprocess_pairs()
        process.multiprocess_data()

        # Get data from database
        idx_datapoint = datapoint.checksum_exists(checksum)
        _dp = datapoint.DataPoint(idx_datapoint)
        ts_start = min(timestamps)
        ts_stop = max(timestamps)
        results = _dp.data(ts_start, ts_stop)

        # Test
        for index, result in enumerate(results):
            self.assertEqual(result['value'], expected[index]['value'])
            self.assertEqual(result['timestamp'], expected[index]['timestamp'])
Esempio n. 3
0
    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)