Esempio n. 1
0
    def test_exists(self):
        """Testing method or function named "exists"."""
        # Add chart entry to database
        chart_name = data.hashstring(str(random()))
        chart_checksum = data.hashstring(str(random()))
        chart.insert_row(
            DbRowChart(name=chart_name, checksum=chart_checksum, enabled=0))

        # Make sure chart entry exists
        idx_chart = chart.exists(chart_checksum)

        # Create idx datapoint
        idx_datapoint = _idx_datapoint()

        # Subtest to make sure chart datapoint does not exist
        with self.subTest():
            result = chart_datapoint.exists(idx_chart, idx_datapoint)
            self.assertFalse(bool(result))

        # Add chart datapoint entry to database
        chart_datapoint.insert_row(
            DbRowChartDataPoint(idx_datapoint=idx_datapoint,
                                idx_chart=idx_chart,
                                enabled=0))

        # Make sure the chart datapoint exists
        result = chart_datapoint.exists(idx_chart, idx_datapoint)
        self.assertTrue(bool(result))
Esempio n. 2
0
    def test_idx_exists(self):
        """Testing method or function named "idx_exists"."""
        # Add chart entry to database
        chart_name = data.hashstring(str(random()))
        chart_checksum = data.hashstring(str(random()))
        chart.insert_row(
            DbRowChart(name=chart_name, checksum=chart_checksum, enabled=0))

        # Make sure chart entry exists
        idx_chart = chart.exists(chart_checksum)
        self.assertTrue(bool(idx_chart))

        # Create idx datapoint
        idx_datapoint = _idx_datapoint()

        # Add chart datapoint entry to database
        chart_datapoint.insert_row(
            DbRowChartDataPoint(idx_datapoint=idx_datapoint,
                                idx_chart=idx_chart,
                                enabled=0))

        # Make sure the chart datapoint exists
        idx_chart_datapoint = chart_datapoint.exists(idx_chart, idx_datapoint)

        # Verify that the index exists
        result = chart_datapoint.idx_exists(idx_chart_datapoint)
        self.assertTrue(result)
Esempio n. 3
0
    def test_insert_row(self):
        """Testing method or function named insert_row."""
        # Add an entry to the database
        chart_name = data.hashstring(str(random()))
        chart_checksum = data.hashstring(str(random()))
        chart.insert_row(
            DbRowChart(name=chart_name, checksum=chart_checksum, enabled=0))

        # Make sure it exists
        idx_chart = chart.exists(chart_checksum)

        # Verify the index exists
        result = chart.idx_exists(idx_chart)
        self.assertTrue(result)
Esempio n. 4
0
def _insert_chart():
    """Insert starting default entries into the Chart table.

    Args:
        None

    Returns:
        None

    """
    # Insert into Chart
    if chart.idx_exists(1) is False:
        chart.insert_row(
            DbRowChart(name='pattoo', checksum='pattoo', enabled=0))
Esempio n. 5
0
    def test_exists(self):
        """Testing method or function named exists."""
        # Create a translation
        chart_name = data.hashstring(str(random()))
        chart_checksum = data.hashstring(str(random()))

        # Make sure it does not exist
        result = chart.exists(chart_checksum)
        self.assertFalse(bool(result))

        # Add database row
        chart.insert_row(
            DbRowChart(name=chart_name, checksum=chart_checksum, enabled=0))

        # Make sure it exists
        result = chart.exists(chart_checksum)
        self.assertTrue(bool(result))
Esempio n. 6
0
    def test_exists(self):
        """Testing method or function named "exists"."""
        # Add user entry to database
        uname = data.hashstring(str(random()))
        passwrd = data.hashstring(str(random()))
        salt_ = data.hashstring(str(random()))
        f_name = data.hashstring(str(random()))
        l_name = data.hashstring(str(random()))
        user.insert_row(
            DbRowUser(
                username=uname,
                password=passwrd,
                first_name=f_name,
                role=0,
                password_expired=1,
                last_name=l_name,
                enabled=0,
            ))
        # Make sure user entry exists
        idx_user = user.exists(uname)

        # Add chart entry to database
        chart_name = data.hashstring(str(random()))
        chart_checksum = data.hashstring(str(random()))
        chart.insert_row(
            DbRowChart(name=chart_name, checksum=chart_checksum, enabled=0))

        # Make sure chart entry exists
        idx_chart = chart.exists(chart_checksum)

        # Make sure favorite does not exist
        result = favorite.exists(idx_chart, idx_user)
        self.assertFalse(bool(result))

        # Add favorite to database
        favorite.insert_row(
            DbRowFavorite(idx_chart=idx_chart,
                          idx_user=idx_user,
                          order=0,
                          enabled=0))

        # Make sure favorite exists
        result = favorite.exists(idx_chart, idx_user)
        self.assertTrue(bool(result))
Esempio n. 7
0
    def test_idx_exists(self):
        """Testing method or function named "idx_exists"."""
        # Add user entry to database
        uname = data.hashstring(str(random()))
        passwrd = data.hashstring(str(random()))
        f_name = data.hashstring(str(random()))
        l_name = data.hashstring(str(random()))
        user.insert_row(
            DbRowUser(username=uname,
                      password=passwrd,
                      first_name=f_name,
                      last_name=l_name,
                      user_type=1,
                      change_password=1,
                      enabled=0))

        # Make sure user entry exists
        idx_user = user.exists(uname)
        self.assertTrue(bool(idx_user))

        # Add chart entry to database
        chart_name = data.hashstring(str(random()))
        chart_checksum = data.hashstring(str(random()))
        chart.insert_row(
            DbRowChart(name=chart_name, checksum=chart_checksum, enabled=0))

        # Make sure chart entry exists
        idx_chart = chart.exists(chart_checksum)
        self.assertTrue(bool(idx_chart))

        # Add favorite to database
        favorite.insert_row(
            DbRowFavorite(idx_chart=idx_chart,
                          idx_user=idx_user,
                          order=0,
                          enabled=0))

        # Make sure the favorite exists
        idx_favorite = favorite.exists(idx_chart, idx_user)

        # Verify that the index exists
        result = favorite.idx_exists(idx_favorite)
        self.assertTrue(result)
Esempio n. 8
0
def idx_datapoint(pattoo_db_record):
    """Get the db DataPoint.idx_datapoint value for a PattooDBrecord object.

    Args:
        pattoo_db_record: PattooDBrecord object

    Returns:
        _idx_datapoint: DataPoint._idx_datapoint value. None if unsuccessful

    """
    # Initialize key variables
    checksum = pattoo_db_record.pattoo_checksum
    data_type = pattoo_db_record.pattoo_data_type
    polling_interval = pattoo_db_record.pattoo_agent_polling_interval
    agent_id = pattoo_db_record.pattoo_agent_id
    agent_target = pattoo_db_record.pattoo_agent_polled_target
    agent_program = pattoo_db_record.pattoo_agent_program

    # Create an entry in the database Checksum table
    _idx_datapoint = checksum_exists(checksum)
    if bool(_idx_datapoint) is False:
        # Create a record in the Agent table
        idx_agent = agent.idx_agent(agent_id, agent_target, agent_program)

        # Create a record in the DataPoint table
        insert_row(checksum, data_type, polling_interval, idx_agent)
        _idx_datapoint = checksum_exists(checksum)

        # Create a record in the Chart table
        chart_checksum = data_.hashstring('{}{}'.format(
            random.random(), checksum))
        chart.insert_row(
            DbRowChart(name='', checksum=chart_checksum, enabled=1))
        idx_chart = chart.exists(chart_checksum)

        # Create a record in the ChartDataPoint table
        chart_datapoint.insert_row(
            DbRowChartDataPoint(idx_chart=idx_chart,
                                idx_datapoint=_idx_datapoint,
                                enabled=1))

    # Return
    return _idx_datapoint