-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add origin information to Checkbox JSON submission (new) (#1644)
* Create a function to retrieve version and packaging information * Use get_origin() to store origin information in submission JSON * Switch version 2020-12 of schema (from draft-06) This version is more up-to-date and allows to use conditions (if..then) * Remove client_version and checkbox_version and add origin into the JSON schema * Refactor Jinja2SessionStateExporter to set origin at init time By setting the origin at init, it is more readable and easier to write unit tests. * Update unit tests to use the new origin information * fix unit test + black formatting issues * Add extra required fields for the packaging section of origin field * Add "unknown" packaging type if none of the package check worked * Handle CalledProcessError as well FileNotFoundError is raised when the dpkg command is not available, but otherwise subprocess.check_output will raise CalledProcessError, which is handled in this commit.
- Loading branch information
Showing
7 changed files
with
209 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# This file is part of Checkbox. | ||
# | ||
# Copyright 2024 Canonical Ltd. | ||
# Written by: | ||
# Pierre Equoy <[email protected]> | ||
# | ||
# Checkbox is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License version 3, | ||
# as published by the Free Software Foundation. | ||
# | ||
# Checkbox is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with Checkbox. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from unittest import TestCase, mock | ||
|
||
import os | ||
from subprocess import CalledProcessError | ||
|
||
import plainbox | ||
|
||
|
||
class PlainboxInitTests(TestCase): | ||
@mock.patch.dict(os.environ, {"VIRTUAL_ENV": "test"}) | ||
def test_get_origin_venv(self): | ||
origin = plainbox.get_origin() | ||
self.assertEqual(origin["packaging"]["type"], "source") | ||
|
||
@mock.patch.dict(os.environ, {"SNAP_NAME": "test"}) | ||
def test_get_origin_snap(self): | ||
origin = plainbox.get_origin() | ||
self.assertEqual(origin["packaging"]["type"], "snap") | ||
|
||
@mock.patch.dict(os.environ, {}, clear=True) | ||
@mock.patch("subprocess.check_output") | ||
def test_get_origin_debian(self, mock_sp_check_output): | ||
mock_sp_check_output.return_value = ( | ||
"python3-checkbox-ng: /usr/lib/python3/dist-packages/plainbox\n" | ||
) | ||
origin = plainbox.get_origin() | ||
self.assertEqual(origin["packaging"]["type"], "debian") | ||
self.assertEqual(origin["packaging"]["name"], "python3-checkbox-ng") | ||
|
||
@mock.patch.dict(os.environ, {}, clear=True) | ||
@mock.patch("subprocess.check_output") | ||
def test_get_origin_exception(self, mock_sp_check_output): | ||
mock_sp_check_output.side_effect = FileNotFoundError | ||
origin = plainbox.get_origin() | ||
self.assertEqual(origin["packaging"]["type"], "unknown") | ||
mock_sp_check_output.side_effect = CalledProcessError(1, "error") | ||
origin = plainbox.get_origin() | ||
self.assertEqual(origin["packaging"]["type"], "unknown") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters