Esempio n. 1
0
 def test_get_all_agents(self):
     """Testing function get_all_agents."""
     # Testing with known good value
     result = db_agent.get_all_agents()
     self.assertEqual(isinstance(result, list), True)
     self.assertEqual(result[0]['idx_agent'], self.expected['idx_agent'])
     self.assertEqual(result[0]['exists'], self.expected['exists'])
     self.assertEqual(result[0]['enabled'], self.expected['enabled'])
     self.assertEqual(result[0]['idx_agentname'],
                      self.expected['idx_agentname'])
Esempio n. 2
0
def db_agent_get_all_agents():
    """Get all agent data from the DB.

    Args:
        None

    Returns:
        Agent data

    """
    # Return
    data = db_agent.get_all_agents()
    return jsonify(data)
Esempio n. 3
0
def agents_query():
    """Get Agent data from the DB by id_agent value.

    Args:
        None

    Returns:
        data: JSON data for the selected agent

    """
    # Initialize key variables
    id_agent = request.args.get('id_agent')

    if bool(id_agent) is True:
        # Process id_datapoint request
        query = db_agent.GetIDAgent(id_agent)
        data = [query.everything()]
    else:
        data = db_agent.get_all_agents()

    # Return
    return jsonify(data)
Esempio n. 4
0
def agents_query():
    """Get Agent data from the DB by id_agent value.

    Args:
        None

    Returns:
        data: JSON data for the selected agent

    """
    # Initialize key variables
    id_agent = request.args.get('id_agent')

    if bool(id_agent) is True:
        # Process id_datapoint request
        key = ('DB/Agent/id_agent/{}'.format(id_agent))
        cache_value = CACHE.get(key)

        # Process cache miss
        if cache_value is None:
            query = db_agent.GetIDAgent(id_agent)
            data = query.everything()
            CACHE.set(key, data)
        else:
            data = cache_value
    else:
        # Process general request
        key = ('DB/Agent/id_agent')
        cache_value = CACHE.get(key)

        # Process cache miss
        if cache_value is None:
            data = db_agent.get_all_agents()
            CACHE.set(key, data)
        else:
            data = cache_value

    # Return
    return jsonify(data)