Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions checkbox-support/checkbox_support/manifest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
Support interfaces related manifest.json

Copyright (C) 2025 Canonical Ltd.

Authors: Massimiliano Girardi <massimiliano.girardi@canonical.com>

This program 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.

This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
"""

import json
from contextlib import suppress
from collections import defaultdict


def get_manifest() -> defaultdict:
to_r = defaultdict(bool)
with suppress(FileNotFoundError):
with open("/var/tmp/checkbox-ng/machine-manifest.json") as f:
to_r.update(json.load(f))
return to_r
40 changes: 40 additions & 0 deletions checkbox-support/checkbox_support/tests/test_manifest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This file is part of Checkbox.
#
# Copyright 2025 Canonical Ltd.
# Written by:
# Massimiliano Girardi <massimiliano.giardi@canonical.com>
#
# 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
from unittest.mock import patch, mock_open, MagicMock

from checkbox_support.manifest import get_manifest


class TestManifest(TestCase):
def test_manifest_present(self):
mock_file = mock_open(
read_data='{"com.canonical.certification::some": true}'
)
with patch("builtins.open", mock_file) as _:
manifest = get_manifest()
self.assertTrue(manifest["com.canonical.certification::some"])
self.assertFalse(manifest["com.canonical.certification::other"])

@patch("builtins.open", new=MagicMock(side_effect=FileNotFoundError))
def test_manifest_not_present(self):
manifest = get_manifest()

self.assertFalse(manifest["com.canonical.certification::some"])
self.assertFalse(manifest["com.canonical.certification::other"])
Loading