示例#1
0
def datapoints_query():
    """Get datapoint data filtered by query string values.

    Args:
        None

    Returns:
        data: JSON data for the selected agent

    """
    # Initialize key variables
    id_datapoint = request.args.get('id_datapoint')
    idx_deviceagent = request.args.get('idx_deviceagent')
    base_type = request.args.get('base_type')

    if bool(id_datapoint) is True:
        query = db_datapoint.GetIDDatapoint(id_datapoint)
        intermediate = query.everything()
        data = []
        data.append(intermediate)

    elif bool(idx_deviceagent) is True:
        data = db_datapoint.listing(
            general.integerize(idx_deviceagent), base_type=base_type)

    else:
        abort(404)

    # Return
    return jsonify(data)
示例#2
0
def db_datapoint_getiddatapoint(value):
    """Get datapoint data from the DB by did value.

    Args:
        None

    Returns:
        Home Page

    """
    # Return
    query = db_datapoint.GetIDDatapoint(value)
    data = query.everything()
    return jsonify(data)
示例#3
0
 def test___init__(self):
     """Testing function __init__."""
     # Test with non existent AgentIDX
     record = db_datapoint.GetIDDatapoint(-1)
     self.assertEqual(record.exists(), False)
     self.assertEqual(record.enabled(), None)
     self.assertEqual(record.last_timestamp(), None)
     self.assertEqual(record.timefixed_value(), None)
     self.assertEqual(record.base_type(), None)
     self.assertEqual(record.billable(), None)
     self.assertEqual(record.agent_source(), None)
     self.assertEqual(record.idx_deviceagent(), None)
     self.assertEqual(record.id_datapoint(), None)
     self.assertEqual(record.idx_datapoint(), None)
     self.assertEqual(record.idx_department(), None)
     self.assertEqual(record.idx_billcode(), None)
     self.assertEqual(record.agent_label(), None)
示例#4
0
class TestGetID(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['id_datapoint'] = database.id_datapoint()
    expected['last_timestamp'] = database.timestamp()
    expected['idx_deviceagent'] = database.idx_deviceagent()
    expected['idx_datapoint'] = database.idx_datapoint()
    expected['idx_department'] = database.idx_department()
    expected['idx_billcode'] = database.idx_billcode()
    expected['agent_label'] = database.agent_label()
    expected['agent_source'] = database.agent_source()
    expected['enabled'] = True
    expected['exists'] = True
    expected['billable'] = False
    expected['base_type'] = 1
    expected['timefixed_value'] = None

    # Retrieve data
    testing = db_datapoint.GetIDDatapoint(expected['id_datapoint'])

    def test___init__(self):
        """Testing function __init__."""
        # Test with non existent AgentIDX
        record = db_datapoint.GetIDDatapoint(-1)
        self.assertEqual(record.exists(), False)
        self.assertEqual(record.enabled(), None)
        self.assertEqual(record.last_timestamp(), None)
        self.assertEqual(record.timefixed_value(), None)
        self.assertEqual(record.base_type(), None)
        self.assertEqual(record.billable(), None)
        self.assertEqual(record.agent_source(), None)
        self.assertEqual(record.idx_deviceagent(), None)
        self.assertEqual(record.id_datapoint(), None)
        self.assertEqual(record.idx_datapoint(), None)
        self.assertEqual(record.idx_department(), None)
        self.assertEqual(record.idx_billcode(), None)
        self.assertEqual(record.agent_label(), None)

    def test_exists(self):
        """Testing function exists."""
        # Testing with known good value
        result = self.testing.exists()
        self.assertEqual(result, self.expected['exists'])

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

    def test_last_timestamp(self):
        """Testing function last_timestamp."""
        # Testing with known good value
        result = self.testing.last_timestamp()
        self.assertEqual(result, self.expected['last_timestamp'])

    def test_timefixed_value(self):
        """Testing function timefixed_value."""
        # Testing with known good value
        result = self.testing.timefixed_value()
        self.assertEqual(result, self.expected['timefixed_value'])

    def test_base_type(self):
        """Testing function base_type."""
        # Testing with known good value
        result = self.testing.base_type()
        self.assertEqual(result, self.expected['base_type'])

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

    def test_billable(self):
        """Testing function billable."""
        # Testing with known good value
        result = self.testing.billable()
        self.assertEqual(result, self.expected['billable'])

    def test_agent_source(self):
        """Testing function agent_source."""
        # Testing with known good value
        result = self.testing.agent_source()
        self.assertEqual(result, self.expected['agent_source'])

    def test_idx_deviceagent(self):
        """Testing function idx_deviceagent."""
        # Testing with known good value
        result = self.testing.idx_deviceagent()
        self.assertEqual(result, self.expected['idx_deviceagent'])

    def test_id_datapoint(self):
        """Testing function id_datapoint."""
        # Testing with known good value
        result = self.testing.id_datapoint()
        self.assertEqual(result, self.expected['id_datapoint'])

    def test_idx_datapoint(self):
        """Testing function idx_datapoint."""
        # Testing with known good value
        result = self.testing.idx_datapoint()
        self.assertEqual(result, self.expected['idx_datapoint'])

    def test_idx_department(self):
        """Testing function idx_department."""
        # Testing with known good value
        result = self.testing.idx_department()
        self.assertEqual(result, self.expected['idx_department'])

    def test_idx_billcode(self):
        """Testing function idx_billcode."""
        # Testing with known good value
        result = self.testing.idx_billcode()
        self.assertEqual(result, self.expected['idx_billcode'])

    def test_agent_label(self):
        """Testing function agent_label."""
        # Testing with known good value
        result = self.testing.agent_label()
        self.assertEqual(result, self.expected['agent_label'])