Пример #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()
Пример #2
0
    def test_last_pending_patch_missing(self, mock_sql):
        """Ensure None is returned when no patches match."""
        testdb = SktDb(self.database_file)
        mock_sql.connect().cursor().fetchone.return_value = None
        result = testdb.get_last_pending_patch('baseurl', 'project_id')

        self.assertIsNone(result)
Пример #3
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()
Пример #4
0
    def test_last_pending_patch(self, mock_sql):
        """Ensure get_last_pending_patch() returns a patch id."""
        testdb = SktDb(self.database_file)
        mock_sql.connect().cursor().fetchone.return_value = [1]
        result = testdb.get_last_pending_patch('baseurl', 'project_id')

        self.assertEqual(result, 1)
Пример #5
0
    def test_get_stable(self, mock_sql, mock_get_repoid):
        """Ensure get_stable() returns baseline_id."""
        testdb = SktDb(self.database_file)
        mock_get_repoid.return_value = 1
        mock_sql.connect().cursor().fetchone.return_value = [1]
        result = testdb.get_stable('baserepo_id')

        self.assertEqual(result, 1)
Пример #6
0
    def test_create_repoid(self, mock_sql):
        """Ensure __create_repoid() inserts into DB and retrieves a repoid."""
        # pylint: disable=W0212,E1101
        testdb = SktDb(self.database_file)
        mock_sql.connect().cursor().lastrowid = 1
        result = testdb._SktDb__create_repoid('git://example.com/repo')

        self.assertEqual(result, 1)
Пример #7
0
    def test_get_stable_empty(self, mock_sql, mock_get_repoid):
        """Ensure get_stable() returns None when results are empty."""
        testdb = SktDb(self.database_file)
        mock_get_repoid.return_value = 1
        mock_sql.connect().cursor().fetchone.return_value = None
        result = testdb.get_stable('baserepo_id')

        self.assertIsNone(result)
Пример #8
0
    def test_get_sourceid(self, mock_sql):
        """Ensure __get_sourceid() retrieves a patchsource id."""
        # pylint: disable=W0212,E1101
        testdb = SktDb(self.database_file)
        mock_sql.connect().cursor().fetchone.return_value = [1]
        result = testdb._SktDb__get_sourceid('git://example.com/repo', 10)

        self.assertEqual(result, 1)
Пример #9
0
    def test_get_repoid_missing(self, mock_sql):
        """Ensure __get_repoid() creates a repoid when it doesn't exist."""
        # pylint: disable=W0212,E1101
        testdb = SktDb(self.database_file)
        mock_sql.connect().cursor().fetchone.return_value = None
        mock_sql.connect().cursor().lastrowid = 1
        result = testdb._SktDb__get_repoid('git://example.com/repo')

        self.assertEqual(result, 1)
Пример #10
0
    def test_get_latest(self, mock_sql, mock_get_repoid):
        """Ensure __get_latest() returns a result."""
        # pylint: disable=W0212,E1101
        testdb = SktDb(self.database_file)
        mock_get_repoid.return_value = 1
        mock_sql.connect().cursor().fetchone.return_value = [1]
        result = testdb._SktDb__get_latest('baserepo_id')

        self.assertEqual(result, 1)
Пример #11
0
    def test_get_commitdate_empty(self, mock_sql, mock_get_repoid):
        """Ensure __get_commitdate() returns None when no baselines match."""
        # pylint: disable=W0212,E1101
        testdb = SktDb(self.database_file)
        mock_get_repoid.return_value = 1
        mock_sql.connect().cursor().fetchone.return_value = None
        result = testdb._SktDb__get_commitdate('baserepod', 'abcdef')

        self.assertIsNone(result)
Пример #12
0
    def test_get_latest_empty(self, mock_sql, mock_get_repoid):
        """Ensure __get_latest() returns None when results are empty."""
        # pylint: disable=W0212,E1101
        testdb = SktDb(self.database_file)
        mock_get_repoid.return_value = 1
        mock_sql.connect().cursor().fetchone.return_value = None
        result = testdb._SktDb__get_latest('baserepo_id')

        self.assertIsNone(result)
Пример #13
0
    def test_expired_pending_patches_empty(self, mock_sql, mock_get_sourceid):
        """Test with an empty list of expired pending patches."""
        # pylint: disable=invalid-name
        testdb = SktDb(self.database_file)

        mock_get_sourceid.return_value = '1'

        mock_sql.connect().cursor().fetchall.return_value = []
        result = testdb.get_expired_pending_patches('baseurl', 'project_id')

        self.assertEqual(result, [])
Пример #14
0
    def test_set_patchset_pending(self, mock_sql, mock_log):
        """Ensure patches are added to the pendingpatch table."""
        testdb = SktDb(self.database_file)
        testdb.set_patchset_pending('baseurl', '1', [('1', '2018-06-04')])

        mock_sql.connect().cursor().executemany.assert_called_once()
        mock_sql.connect().commit.assert_called()
        mock_log.assert_called_once()

        # Check if we have a proper INSERT query executed
        execute_call_args = mock_sql.connect().cursor().executemany.\
            call_args[0]
        self.assertIn('INSERT OR REPLACE INTO pendingpatches',
                      execute_call_args[0])
Пример #15
0
    def test_commit_patch(self, mock_sql, mock_get_sourceid, mock_log):
        """Ensure __commit_patch() creates/updates a patch record."""
        # pylint: disable=W0212,E1101
        testdb = SktDb(self.database_file)
        mock_get_sourceid.return_value = '1'
        testdb._SktDb__commit_patch('1', '2', '3', '4', '5', '6')

        # Check if we have a proper INSERT query executed
        execute_call_args = mock_sql.connect().cursor().execute.call_args[0]
        self.assertIn('INSERT OR REPLACE INTO patch', execute_call_args[0])
        self.assertTupleEqual(('1', '2', '3', '1', '6'), execute_call_args[1])

        mock_log.assert_called()

        # Ensure the data was committed to the database
        mock_sql.connect().commit.assert_called()
Пример #16
0
    def test_commit_series_empty_db(self, mock_sql, mock_get_sourceid,
                                    mock_commit_patch, mock_log):
        """Ensure commit_series() creates patch records with empty testdb."""
        # pylint: disable=invalid-name,W0212,E1101
        testdb = SktDb(self.database_file)

        mock_get_sourceid.return_value = '1'
        mock_commit_patch.return_value = None
        mock_sql.connect().cursor().fetchone.return_value = None

        patches = [(['patch_id'], 'patch_name', 'patch_url', 'base_url',
                    'project_id', 'patch_date')]
        testdb.commit_series(patches)

        mock_get_sourceid.assert_called_once()
        mock_commit_patch.assert_called_once()
        mock_log.assert_called()

        # Ensure the data was committed to the database
        mock_sql.connect().commit.assert_called()
Пример #17
0
    def test_unset_patchset_pending(self, mock_sql, mock_get_sourceid,
                                    mock_log):
        """Ensure patches are removed from the pendingpatch table."""
        # pylint: disable=W0212,E1101
        testdb = SktDb(self.database_file)
        mock_get_sourceid.return_value = 1

        testdb._SktDb__unset_patchset_pending('baseurl', ['1'])

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

        # Check if we have a proper DELETE query executed
        execute_call_args = mock_sql.connect().cursor().executemany.\
            call_args[0]
        self.assertIn('DELETE FROM pendingpatches', execute_call_args[0])
        self.assertEqual([('baseurl', '1')], execute_call_args[1])

        # Ensure the data was committed to the database
        mock_sql.connect().commit.assert_called()
Пример #18
0
    def test_commit_testrun(self, mock_sql, mock_log):
        """Ensure __commit_testrun() creates a testrun record."""
        # pylint: disable=W0212,E1101
        testdb = SktDb(self.database_file)

        result = mock.Mock()
        result.value = 'ok'

        mock_sql.connect().cursor().lastrowid = 1
        result = testdb._SktDb__commit_testrun(result, '2')

        self.assertEqual(result, 1)

        # Check if we have a proper INSERT query executed
        execute_call_args = mock_sql.connect().cursor().execute.call_args[0]
        self.assertIn('INSERT INTO testrun', execute_call_args[0])
        self.assertTupleEqual(('ok', '2'), execute_call_args[1])

        mock_log.assert_called()

        # Ensure the data was committed to the database
        mock_sql.connect().commit.assert_called()
Пример #19
0
    def test_db_create_already_exists(self):
        """Ensure SktDb() creates a database file when it doesn't exist."""
        sqlite3.connect(self.database_file)
        SktDb(self.database_file)

        self.assertTrue(os.path.isfile(self.database_file))