Example #1
0
    def test_update_baseline(self, mock_sql, mock_get_repoid,
                             mock_get_baselineresult, mock_log):
        """Ensure baseline is updated when current result is newer."""
        # pylint: disable=too-many-arguments
        testdb = SktDb(self.database_file)

        mock_get_repoid.return_value = '1'
        mock_get_baselineresult.return_value = 1
        result = TestResult.SUCCESS

        testdb.update_baseline('baserepo', 'abcdef', '2018-06-01', result, '1')

        # Ensure a debug log was written
        mock_log.assert_called()

        execute_call_args = mock_sql.connect().cursor().execute.call_args[0]
        # Check if we have a proper UPDATE query executed
        self.assertIn('UPDATE baseline', execute_call_args[0])
        # Check the arguments of the final query
        self.assertTupleEqual(
            (mock_sql.connect().cursor().lastrowid, 'abcdef', '1'),
            execute_call_args[1]
        )

        # Ensure the data was committed to the database
        mock_sql.connect().commit.assert_called()
Example #2
0
    def test_update_baseline_new(self, mock_sql, mock_get_repoid,
                                 mock_get_baselineresult, mock_log):
        """Ensure new baslines are created when one doesn't exist."""
        # pylint: disable=too-many-arguments
        testdb = SktDb(self.database_file)

        mock_get_repoid.return_value = '1'
        mock_get_baselineresult.return_value = None
        result = TestResult.SUCCESS

        testdb.update_baseline('baserepo', 'abcd', '2018-06-01', result, '1')

        # Ensure a debug log was written
        mock_log.assert_called()

        execute_call_args = mock_sql.connect().cursor().execute.call_args[0]
        # Check if we have a proper INSERT query executed
        self.assertIn('INSERT INTO baseline', execute_call_args[0])
        # Check the arguments of the final query
        self.assertTupleEqual(
            ('1', 'abcd', '2018-06-01', mock_sql.connect().cursor().lastrowid),
            execute_call_args[1]
        )

        # Ensure the data was committed to the database
        mock_sql.connect().commit.assert_called()