Пример #1
0
def db_getidxdevice(value):
    """Get device data from the DB by idx value.

    Args:
        value: Index from the Device table

    Returns:
        Home Page

    """
    # Initialize key variables
    idx_device = int(value)

    # Get data from cache
    key = ('DB/Device/idx_device/{}'.format(idx_device))
    cache_value = CACHE.get(key)

    # Process cache miss
    if cache_value is None:
        query = db_device.GetIDXDevice(idx_device)
        data = query.everything()
        CACHE.set(key, data)
    else:
        data = cache_value

    # Return
    return jsonify(data)
Пример #2
0
 def test_init(self):
     """Testing method __init__."""
     # Test with non existent IDXDevice
     record = db_device.GetIDXDevice('bogus')
     self.assertEqual(record.exists(), False)
     self.assertEqual(record.devicename(), None)
     self.assertEqual(record.enabled(), None)
     self.assertEqual(record.description(), None)
     self.assertEqual(record.idx_device(), None)
Пример #3
0
def db_getidxdevice(value):
    """Get device data from the DB by idx value.

    Args:
        None

    Returns:
        Home Page

    """
    # Return
    query = db_device.GetIDXDevice(_integer(value))
    data = query.everything()
    return jsonify(data)
Пример #4
0
def db_getidxdevice(value):
    """Get device data from the DB by idx value.

    Args:
        value: Index from the Device table

    Returns:
        Home Page

    """
    # Initialize key variables
    idx_device = int(value)

    # Get data
    query = db_device.GetIDXDevice(idx_device)
    data = query.everything()

    # Return
    return jsonify(data)
Пример #5
0
class TestGetIDXDevice(unittest.TestCase):
    """Checks all functions and methods."""

    #########################################################################
    # General object setup
    #########################################################################

    # Setup database based on the config
    database = unittest_setup_db.TestData()

    # Define expected values
    expected = {}
    expected['idx_device'] = database.idx_device()
    expected['devicename'] = database.devicename()
    expected['description'] = database.device_description()
    expected['enabled'] = True
    expected['exists'] = True

    # Create device object
    good_device = db_device.GetIDXDevice(expected['idx_device'])

    def test_init(self):
        """Testing method __init__."""
        # Test with non existent IDXDevice
        record = db_device.GetIDXDevice('bogus')
        self.assertEqual(record.exists(), False)
        self.assertEqual(record.devicename(), None)
        self.assertEqual(record.enabled(), None)
        self.assertEqual(record.description(), None)
        self.assertEqual(record.idx_device(), None)

    def test_devicename(self):
        """Testing method devicename."""
        # Testing with known good value
        result = self.good_device.devicename()
        self.assertEqual(result, self.expected['devicename'])

        # Testing with known bad value
        expected = ('bogus')
        result = self.good_device.devicename()
        self.assertNotEqual(result, expected)

    def test_description(self):
        """Testing function description."""
        # Testing with known good value
        result = self.good_device.description()
        self.assertEqual(result, self.expected['description'])

        # Testing with known bad value
        expected = ('bogus')
        result = self.good_device.description()
        self.assertNotEqual(result, expected)

    def test_enabled(self):
        """Testing function enabled."""
        # Testing with known good value
        result = self.good_device.enabled()
        self.assertEqual(result, self.expected['enabled'])

        # Testing with known bad value
        expected = ('bogus')
        result = self.good_device.enabled()
        self.assertNotEqual(result, expected)

    def test_exists(self):
        """Testing function exists."""
        # Testing with known good value
        result = self.good_device.exists()
        self.assertEqual(result, True)

    def test_everything(self):
        """Testing method everything."""
        # Testing with known good value
        result = self.good_device.everything()
        for key, _ in self.expected.items():
            self.assertEqual(result[key], self.expected[key])

        # Test the number and names of keys
        keys = ['idx_device', 'devicename', 'description', 'enabled', 'exists']
        self.assertEqual(len(result), len(keys))
        for key in keys:
            self.assertEqual(key in result, True)
Пример #6
0
class APITestCase(unittest.TestCase):
    """Checks all functions and methods."""

    #########################################################################
    # General object setup
    #########################################################################

    # Setup database based on the config
    database = unittest_setup_db.TestData()

    # Define expected values
    expected = {}
    expected['values'] = database.values()
    expected['idx_device'] = database.idx_device()
    expected['idx_deviceagent'] = database.idx_deviceagent()
    expected['agent'] = database.agent()
    expected['devicename'] = database.devicename()
    expected['id_agent'] = database.id_agent()
    expected['agent_label'] = database.agent_label()

    # Retrieve data
    test_object = db_device.GetIDXDevice(expected['idx_device'])

    def setUp(self):
        """Setup the environment prior to testing."""
        # Test mode
        API.config['TESTING'] = True
        self.API = API.test_client()

    def test_lastcontacts(self):
        """Testing method / function lastcontacts."""
        # Initialize key variables
        precision = 5

        #######################################################################
        # Try with secondsago = 3600
        #######################################################################

        # Clear the memory cache
        CACHE.clear()

        # Get results for up to an hour ago
        uri = '/infoset/api/v1/lastcontacts?secondsago=3600'
        response = self.API.get(uri)
        results = json.loads(response.get_data(as_text=True))

        # Test
        self.assertEqual(isinstance(results, list), True)

        # First item in expected should be the most recent contact.
        # Expected['values'] is sorted by timestamp.
        expected = self.expected['values'][0]
        result = results[0]

        self.assertEqual(result['timestamp'], expected['timestamp'])
        self.assertEqual(
            round(result['value'], precision),
            round(expected['value'], precision))

        #######################################################################
        # Try with secondsago = 60 (No values expected)
        #######################################################################

        # Clear the memory cache
        CACHE.clear()

        # Get results for up to a minute ago
        uri = '/infoset/api/v1/lastcontacts?secondsago=60'
        response = self.API.get(uri)
        results = json.loads(response.get_data(as_text=True))

        # Test
        self.assertEqual(isinstance(results, list), True)
        self.assertEqual(bool(results), False)

        #######################################################################
        # Try with ts_start = 0
        #######################################################################

        # Clear the memory cache
        CACHE.clear()

        # Get results
        uri = '/infoset/api/v1/lastcontacts?ts_start=0'
        response = self.API.get(uri)
        results = json.loads(response.get_data(as_text=True))

        # Test
        self.assertEqual(isinstance(results, list), True)

        # First item in expected should be the most recent contact.
        # Expected['values'] is sorted by timestamp.
        expected = self.expected['values'][0]
        result = results[0]

        self.assertEqual(result['timestamp'], expected['timestamp'])
        self.assertEqual(
            round(result['value'], precision),
            round(expected['value'], precision))

        #######################################################################
        # Try with ts_start = an hour ago
        #######################################################################

        # Clear the memory cache
        CACHE.clear()

        # Get results for up to an hour ago
        ts_start = int(datetime.utcnow().timestamp()) - 3600
        uri = '/infoset/api/v1/lastcontacts?ts_start={}'.format(ts_start)
        response = self.API.get(uri)
        results = json.loads(response.get_data(as_text=True))

        # Test
        self.assertEqual(isinstance(results, list), True)

        # First item in expected should be the most recent contact.
        # Expected['values'] is sorted by timestamp.
        expected = self.expected['values'][0]
        result = results[0]

        self.assertEqual(result['timestamp'], expected['timestamp'])
        self.assertEqual(
            round(result['value'], precision),
            round(expected['value'], precision))

        #######################################################################
        # Try with ts_start = a minute ago
        #######################################################################

        # Clear the memory cache
        CACHE.clear()

        # Get results for up to an hour ago
        ts_start = int(datetime.utcnow().timestamp()) - 60
        uri = '/infoset/api/v1/lastcontacts?ts_start={}'.format(ts_start)
        response = self.API.get(uri)
        results = json.loads(response.get_data(as_text=True))

        # Test type of result
        self.assertEqual(isinstance(results, list), True)
        self.assertEqual(bool(results), False)

    def test_id_agents(self):
        """Testing method / function id_agents."""
        # Initialize key variables
        precision = 5

        #######################################################################
        # Try with default values
        #######################################################################

        # Clear the memory cache
        CACHE.clear()

        # Get results for up to an hour ago
        uri = '/infoset/api/v1/lastcontacts/id_agents'
        response = self.API.get(uri)
        results = json.loads(response.get_data(as_text=True))

        # Further testing
        result = results[0]
        self.assertEqual(result['agent'], self.expected['agent'])
        self.assertEqual(result['devicename'], self.expected['devicename'])
        self.assertEqual(result['id_agent'], self.expected['id_agent'])
        self.assertEqual('timeseries' in result, True)

        # First item in expected should be the most recent contact.
        # Expected['values'] is sorted by timestamp.
        expected = self.expected['values'][0]

        # We should only have a single result to test
        for agent_label, data_dict in result['timeseries'].items():
            # Test match for agent_label
            self.assertEqual(agent_label, self.expected['agent_label'])

            for key, value in data_dict.items():
                # Test presence of timeseries values
                if key == 'timestamp':
                    self.assertEqual(value, expected['timestamp'])
                elif key == 'value':
                    self.assertEqual(
                        round(value, precision),
                        round(expected['value'], precision))

        #######################################################################
        # Try with secondsago = 3600
        #######################################################################

        # Clear the memory cache
        CACHE.clear()

        # Get results for up to an hour ago
        uri = '/infoset/api/v1/lastcontacts/id_agents?secondsago=3600'
        response = self.API.get(uri)
        results = json.loads(response.get_data(as_text=True))

        # Further testing
        result = results[0]
        self.assertEqual(result['agent'], self.expected['agent'])
        self.assertEqual(result['devicename'], self.expected['devicename'])
        self.assertEqual(result['id_agent'], self.expected['id_agent'])
        self.assertEqual('timeseries' in result, True)

        # First item in expected should be the most recent contact.
        # Expected['values'] is sorted by timestamp.
        expected = self.expected['values'][0]

        # We should only have a single result to test
        for agent_label, data_dict in result['timeseries'].items():
            # Test match for agent_label
            self.assertEqual(agent_label, self.expected['agent_label'])

            for key, value in data_dict.items():
                # Test presence of timeseries values
                if key == 'timestamp':
                    self.assertEqual(value, expected['timestamp'])
                elif key == 'value':
                    self.assertEqual(
                        round(value, precision),
                        round(expected['value'], precision))

        #######################################################################
        # Try with secondsago = 60 (No response expected)
        #######################################################################

        # Clear the memory cache
        CACHE.clear()

        # Get results for up to an hour ago
        uri = '/infoset/api/v1/lastcontacts/id_agents?secondsago=60'
        response = self.API.get(uri)
        results = json.loads(response.get_data(as_text=True))

        # Test
        self.assertEqual(isinstance(results, list), True)
        self.assertEqual(bool(results), False)

        #######################################################################
        # Try with ts_star = 0
        #######################################################################

        # Clear the memory cache
        CACHE.clear()

        # Get results for up to an hour ago
        uri = '/infoset/api/v1/lastcontacts/id_agents?ts_start=0'
        response = self.API.get(uri)
        results = json.loads(response.get_data(as_text=True))

        # Further testing
        result = results[0]
        self.assertEqual(result['agent'], self.expected['agent'])
        self.assertEqual(result['devicename'], self.expected['devicename'])
        self.assertEqual(result['id_agent'], self.expected['id_agent'])
        self.assertEqual('timeseries' in result, True)

        # First item in expected should be the most recent contact.
        # Expected['values'] is sorted by timestamp.
        expected = self.expected['values'][0]

        # We should only have a single result to test
        for agent_label, data_dict in result['timeseries'].items():
            # Test match for agent_label
            self.assertEqual(agent_label, self.expected['agent_label'])

            for key, value in data_dict.items():
                # Test presence of timeseries values
                if key == 'timestamp':
                    self.assertEqual(value, expected['timestamp'])
                elif key == 'value':
                    self.assertEqual(
                        round(value, precision),
                        round(expected['value'], precision))

        #######################################################################
        # Try with ts_start = an hour ago
        #######################################################################

        # Clear the memory cache
        CACHE.clear()

        # Get results for up to an hour ago
        ts_start = int(datetime.utcnow().timestamp()) - 3600
        uri = (
            '/infoset/api/v1/lastcontacts/id_agents?ts_start={}'
            ''.format(ts_start))
        response = self.API.get(uri)
        results = json.loads(response.get_data(as_text=True))

        # Further testing
        result = results[0]
        self.assertEqual(result['agent'], self.expected['agent'])
        self.assertEqual(result['devicename'], self.expected['devicename'])
        self.assertEqual(result['id_agent'], self.expected['id_agent'])
        self.assertEqual('timeseries' in result, True)

        # First item in expected should be the most recent contact.
        # Expected['values'] is sorted by timestamp.
        expected = self.expected['values'][0]

        # We should only have a single result to test
        for agent_label, data_dict in result['timeseries'].items():
            # Test match for agent_label
            self.assertEqual(agent_label, self.expected['agent_label'])

            for key, value in data_dict.items():
                # Test presence of timeseries values
                if key == 'timestamp':
                    self.assertEqual(value, expected['timestamp'])
                elif key == 'value':
                    self.assertEqual(
                        round(value, precision),
                        round(expected['value'], precision))

        #######################################################################
        # Try with ts_start = 15 minutes ago (No values expected)
        #######################################################################

        # Clear the memory cache
        CACHE.clear()

        # Get results for up to an hour ago
        ts_start = int(datetime.utcnow().timestamp()) - 900
        uri = (
            '/infoset/api/v1/lastcontacts/id_agents?ts_start={}'
            ''.format(ts_start))
        response = self.API.get(uri)
        results = json.loads(response.get_data(as_text=True))

        # Test
        self.assertEqual(isinstance(results, list), True)
        self.assertEqual(bool(results), False)

    def test_deviceagents(self):
        """Testing method / function deviceagents."""
        # Initialize key variables
        precision = 5

        #######################################################################
        # Try with secondsago = 3600
        #######################################################################

        # Clear the memory cache
        CACHE.clear()

        # Get results for up to an hour ago
        uri = (
            '/infoset/api/v1/lastcontacts/deviceagents/{}?secondsago=3600'
            ''.format(self.expected['idx_deviceagent']))
        response = self.API.get(uri)
        results = json.loads(response.get_data(as_text=True))

        # Test
        self.assertEqual(isinstance(results, list), True)

        # First item in expected should be the most recent contact.
        # Expected['values'] is sorted by timestamp.
        expected = self.expected['values'][0]
        result = results[0]

        self.assertEqual(result['timestamp'], expected['timestamp'])
        self.assertEqual(
            round(result['value'], precision),
            round(expected['value'], precision))

        #######################################################################
        # Try with secondsago = 60 (No response expected)
        #######################################################################

        # Clear the memory cache
        CACHE.clear()

        # Get results for up to an hour ago
        uri = (
            '/infoset/api/v1/lastcontacts/deviceagents/{}?secondsago=60'
            ''.format(self.expected['idx_deviceagent']))
        response = self.API.get(uri)
        results = json.loads(response.get_data(as_text=True))

        # Test
        self.assertEqual(isinstance(results, list), True)
        self.assertEqual(bool(results), False)

        #######################################################################
        # Try with ts_star = 0
        #######################################################################

        # Clear the memory cache
        CACHE.clear()

        # Get results for up to an hour ago
        uri = (
            '/infoset/api/v1/lastcontacts/deviceagents/{}?ts_start=0'
            ''.format(self.expected['idx_deviceagent']))
        response = self.API.get(uri)
        results = json.loads(response.get_data(as_text=True))

        # Test
        self.assertEqual(isinstance(results, list), True)

        # First item in expected should be the most recent contact.
        # Expected['values'] is sorted by timestamp.
        expected = self.expected['values'][0]
        result = results[0]

        self.assertEqual(result['timestamp'], expected['timestamp'])
        self.assertEqual(
            round(result['value'], precision),
            round(expected['value'], precision))

        #######################################################################
        # Try with ts_start = an hour ago
        #######################################################################

        # Clear the memory cache
        CACHE.clear()

        # Get results for up to an hour ago
        ts_start = int(datetime.utcnow().timestamp()) - 3600
        uri = (
            '/infoset/api/v1/lastcontacts/deviceagents/{}?ts_start={}'
            ''.format(self.expected['idx_deviceagent'], ts_start))
        response = self.API.get(uri)
        results = json.loads(response.get_data(as_text=True))

        # Test
        self.assertEqual(isinstance(results, list), True)

        # First item in expected should be the most recent contact.
        # Expected['values'] is sorted by timestamp.
        expected = self.expected['values'][0]
        result = results[0]

        self.assertEqual(result['timestamp'], expected['timestamp'])
        self.assertEqual(
            round(result['value'], precision),
            round(expected['value'], precision))

        #######################################################################
        # Try with ts_start = 15 minutes ago (No values expected)
        #######################################################################

        # Clear the memory cache
        CACHE.clear()

        # Get results for up to an hour ago
        ts_start = int(datetime.utcnow().timestamp()) - 900
        uri = (
            '/infoset/api/v1/lastcontacts/deviceagents/{}?ts_start={}'
            ''.format(self.expected['idx_deviceagent'], ts_start))
        response = self.API.get(uri)
        results = json.loads(response.get_data(as_text=True))

        # Test
        self.assertEqual(isinstance(results, list), True)
        self.assertEqual(bool(results), False)

    def test_devicename_agents(self):
        """Testing method / function devicename_agents."""
        # Initialize key variables
        precision = 5

        #######################################################################
        # Try with secondsago = 3600
        #######################################################################

        # Clear the memory cache
        CACHE.clear()

        # Get results for up to an hour ago
        uri = (
            '/infoset/api/v1/lastcontacts/devicenames/{}/id_agents/{}'
            '?secondsago=3600'
            ''.format(self.expected['devicename'], self.expected['id_agent']))
        response = self.API.get(uri)
        results = json.loads(response.get_data(as_text=True))

        # Test
        self.assertEqual(isinstance(results, list), True)

        # First item in expected should be the most recent contact.
        # Expected['values'] is sorted by timestamp.
        expected = self.expected['values'][0]
        result = results[0]

        self.assertEqual(result['timestamp'], expected['timestamp'])
        self.assertEqual(
            round(result['value'], precision),
            round(expected['value'], precision))

        #######################################################################
        # Try with secondsago = 60 (No response expected)
        #######################################################################

        # Clear the memory cache
        CACHE.clear()

        # Get results for up to an hour ago
        uri = (
            '/infoset/api/v1/lastcontacts/devicenames/{}/id_agents/{}'
            '?secondsago=60'
            ''.format(self.expected['devicename'], self.expected['id_agent']))
        response = self.API.get(uri)
        results = json.loads(response.get_data(as_text=True))

        # Test
        self.assertEqual(isinstance(results, list), True)
        self.assertEqual(bool(results), False)

        #######################################################################
        # Try with ts_star = 0
        #######################################################################

        # Clear the memory cache
        CACHE.clear()

        # Get results for up to an hour ago
        uri = (
            '/infoset/api/v1/lastcontacts/devicenames/{}/id_agents/{}'
            '?ts_start=0'
            ''.format(self.expected['devicename'], self.expected['id_agent']))
        response = self.API.get(uri)
        results = json.loads(response.get_data(as_text=True))

        # Test
        self.assertEqual(isinstance(results, list), True)

        # First item in expected should be the most recent contact.
        # Expected['values'] is sorted by timestamp.
        expected = self.expected['values'][0]
        result = results[0]

        self.assertEqual(result['timestamp'], expected['timestamp'])
        self.assertEqual(
            round(result['value'], precision),
            round(expected['value'], precision))

        #######################################################################
        # Try with ts_start = an hour ago
        #######################################################################

        # Clear the memory cache
        CACHE.clear()

        # Get results for up to an hour ago
        ts_start = int(datetime.utcnow().timestamp()) - 3600
        uri = (
            '/infoset/api/v1/lastcontacts/devicenames/{}/id_agents/{}'
            '?ts_start={}'
            ''.format(
                self.expected['devicename'],
                self.expected['id_agent'],
                ts_start))
        response = self.API.get(uri)
        results = json.loads(response.get_data(as_text=True))

        # Test
        self.assertEqual(isinstance(results, list), True)

        # First item in expected should be the most recent contact.
        # Expected['values'] is sorted by timestamp.
        expected = self.expected['values'][0]
        result = results[0]

        self.assertEqual(result['timestamp'], expected['timestamp'])
        self.assertEqual(
            round(result['value'], precision),
            round(expected['value'], precision))

        #######################################################################
        # Try with ts_start = 15 minutes ago (No values expected)
        #######################################################################

        # Clear the memory cache
        CACHE.clear()

        # Get results for up to an hour ago
        ts_start = int(datetime.utcnow().timestamp()) - 900
        uri = (
            '/infoset/api/v1/lastcontacts/devicenames/{}/id_agents/{}'
            '?ts_start={}'
            ''.format(
                self.expected['devicename'],
                self.expected['id_agent'],
                ts_start))
        response = self.API.get(uri)
        results = json.loads(response.get_data(as_text=True))

        # Test
        self.assertEqual(isinstance(results, list), True)
        self.assertEqual(bool(results), False)

    def test__start_timestamp(self):
        """Testing method / function _start_timestamp."""
        # Tested by other unittests here
        pass
Пример #7
0
 def test___init__(self):
     """Testing function __init__."""
     # Test with non existent DeviceIDX
     record = db_device.GetIDXDevice('bogus')
     self.assertEqual(record.exists(), False)
Пример #8
0
class TestGetDevice(unittest.TestCase):
    """Checks all functions and methods."""

    #########################################################################
    # General object setup
    #########################################################################

    # Intstantiate a good agent
    idx_device_good = 1
    expected = unittest_db.setup_db_device()

    # Create device object
    good_device = db_device.GetIDXDevice(idx_device_good)

    def test___init__(self):
        """Testing function __init__."""
        # Test with non existent DeviceIDX
        record = db_device.GetIDXDevice('bogus')
        self.assertEqual(record.exists(), False)

    def test_idx_device(self):
        """Testing method idx_device."""
        # Testing with known good value
        result = self.good_device.idx_device()
        self.assertEqual(result, self.expected['idx_device'])

        # Testing with known bad value
        expected = ('bogus')
        result = self.good_device.devicename()
        self.assertNotEqual(result, expected)

    def test_exists(self):
        """Testing function exists."""
        # Testing with known good value
        result = self.good_device.exists()
        self.assertEqual(result, True)

    def test_description(self):
        """Testing function description."""
        # Testing with known good value
        result = self.good_device.description()
        self.assertEqual(result, self.expected['description'])

        # Testing with known bad value
        expected = ('bogus')
        result = self.good_device.description()
        self.assertNotEqual(result, expected)

    def test_enabled(self):
        """Testing function enabled."""
        # Testing with known good value
        result = self.good_device.enabled()
        self.assertEqual(result, self.expected['enabled'])

        # Testing with known bad value
        expected = ('bogus')
        result = self.good_device.enabled()
        self.assertNotEqual(result, expected)

    def test_ip_address(self):
        """Testing function ip_address."""
        # Testing with known good value
        result = self.good_device.ip_address()
        self.assertEqual(result, self.expected['ip_address'])

        # Testing with known bad value
        expected = ('bogus')
        result = self.good_device.ip_address()
        self.assertNotEqual(result, expected)
Пример #9
0
 def test_init(self):
     """Testing method __init__."""
     # Test with non existent IDXDevice
     record = db_device.GetIDXDevice('bogus')
     self.assertEqual(record.exists(), False)
Пример #10
0
class APITestCase(unittest.TestCase):
    """Checks all functions and methods."""

    #########################################################################
    # General object setup
    #########################################################################

    # Setup database based on the config
    database = unittest_setup_db.TestData()

    # Define expected values
    expected = {}
    expected['idx_device'] = database.idx_device()
    expected['idx_agent'] = database.idx_agent()

    # Retrieve data
    test_object = db_device.GetIDXDevice(expected['idx_device'])

    def setUp(self):
        """Setup the environment prior to testing."""
        # Test mode
        API.config['TESTING'] = True
        self.API = API.test_client()

    def test_db_getidxdevice(self):
        """Testing method / function db_getidxdevice."""
        # Clear the memory cache
        CACHE.clear()

        # Get results
        uri = (
            '/infoset/api/v1/devices/{}'.format(self.expected['idx_device'])
        )
        response = self.API.get(uri)
        result = json.loads(response.get_data(as_text=True))

        # Verify reponse code
        self.assertEqual(response.status_code, 200)

        # Verify response content
        self.assertEqual(isinstance(result, dict), True)
        self.assertEqual(result['description'], self.test_object.description())
        self.assertEqual(result['exists'], self.test_object.exists())
        self.assertEqual(result['enabled'], self.test_object.enabled())
        self.assertEqual(result['idx_device'], self.test_object.idx_device())
        self.assertEqual(
            result['devicename'], self.test_object.devicename())

        # Test the number and names of keys
        keys = [
            'idx_device', 'devicename', 'description', 'enabled', 'exists']
        self.assertEqual(len(result), len(keys))
        for key in keys:
            self.assertEqual(key in result, True)

    def test_db_deviceagent_indices(self):
        """Testing method / function db_deviceagent_agentindices."""
        # Clear the memory cache
        CACHE.clear()

        # Get results
        uri = (
            '/infoset/api/v1/devices/{}/agents'
            ''.format(self.expected['idx_device'])
        )
        response = self.API.get(uri)
        result = json.loads(response.get_data(as_text=True))

        # Verify reponse code
        self.assertEqual(response.status_code, 200)

        # Verify response content
        self.assertEqual(isinstance(result, list), True)
        self.assertEqual(len(result), 1)
        self.assertEqual(result, [self.expected['idx_agent']])