Skip to content

Commit 4cf29f1

Browse files
authored
Add new stock report to export submission.json (new) (#1827)
* Add new stock report to export submission.json * Update the documentation to include new stock report * Test that the new config is problem-free
1 parent 213432c commit 4cf29f1

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

checkbox-ng/checkbox_ng/launcher/stages.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,28 @@ def _prepare_stock_report(self, report):
532532
self.sa.config.update_from_another(
533533
additional_config, new_origin
534534
)
535+
elif report == "submission_json":
536+
exporter = "json"
537+
file_ext = ".json"
538+
path = self._get_submission_file_path(file_ext)
539+
os.makedirs(os.path.dirname(path), exist_ok=True)
540+
template = textwrap.dedent(
541+
"""
542+
[transport:{exporter}_file]
543+
path = {path}
544+
type = file
545+
[exporter:{exporter}]
546+
unit = com.canonical.plainbox::{exporter}
547+
[report:2_{exporter}_file]
548+
exporter = {exporter}
549+
forced = yes
550+
transport = {exporter}_file
551+
"""
552+
)
553+
additional_config = Configuration.from_text(
554+
template.format(exporter=exporter, path=path), new_origin
555+
)
556+
self.sa.config.update_from_another(additional_config, new_origin)
535557

536558
def _get_submission_file_path(self, file_ext):
537559
# LP:1585326 maintain isoformat but removing ':' chars that cause

checkbox-ng/checkbox_ng/launcher/test_stages.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def get_parametric_sections(section):
146146
)
147147

148148
@mock.patch("os.makedirs")
149-
def test__prepare_stock_report(self, makedirs):
149+
def test__prepare_stock_report_submission_files(self, makedirs):
150150
self_mock = mock.MagicMock()
151151
self_mock._get_submission_file_path = partial(
152152
ReportsStage._get_submission_file_path, self_mock
@@ -157,3 +157,20 @@ def test__prepare_stock_report(self, makedirs):
157157

158158
self.assertEqual(self_mock.sa.config.update_from_another.call_count, 3)
159159
self.assertTrue(makedirs.called)
160+
161+
@mock.patch("os.makedirs")
162+
def test__prepare_stock_report_submission_json(self, makedirs):
163+
self_mock = mock.MagicMock()
164+
self_mock._get_submission_file_path = partial(
165+
ReportsStage._get_submission_file_path, self_mock
166+
)
167+
self_mock.base_dir = "~/.local/share"
168+
169+
ReportsStage._prepare_stock_report(self_mock, "submission_json")
170+
171+
# called to adopt the generated config
172+
self_mock_update_from_another = self_mock.sa.config.update_from_another
173+
self.assertEqual(self_mock_update_from_another.call_count, 1)
174+
config = self_mock_update_from_another.call_args[0][0]
175+
self.assertFalse(config.get_problems())
176+
self.assertTrue(makedirs.called)

docs/reference/launcher.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ future.
102102
* ``certification``: Send results to certification site
103103
* ``certification-staging``: Send results to staging version of
104104
certification site
105+
* ``submission_json``: Writes the ``submission.json`` to ``$XDG_DATA_HOME``
106+
(or ``~/.local/share`` if it is not defined)
105107

106108
If you don't want to have any stock report automatically generated use
107109
``none`` as the value.

0 commit comments

Comments
 (0)