|
14 | 14 | #
|
15 | 15 | # SPDX-License-Identifier: Apache-2.0
|
16 | 16 | # Copyright (c) OWASP Foundation. All Rights Reserved.
|
17 |
| - |
18 |
| - |
| 17 | +import warnings |
19 | 18 | from typing import Callable, Tuple
|
20 | 19 | from unittest import TestCase
|
21 | 20 | from uuid import uuid4
|
|
31 | 30 | from cyclonedx.model.license import DisjunctiveLicense
|
32 | 31 | from cyclonedx.model.lifecycle import LifecyclePhase, NamedLifecycle, PredefinedLifecycle
|
33 | 32 | from cyclonedx.model.tool import Tool
|
| 33 | +from cyclonedx.output.json import JsonV1Dot6 |
34 | 34 | from tests._data.models import (
|
35 | 35 | get_bom_component_licenses_invalid,
|
36 | 36 | get_bom_component_nested_licenses_invalid,
|
@@ -139,6 +139,21 @@ def test_empty_bom(self) -> None:
|
139 | 139 | self.assertFalse(bom.services)
|
140 | 140 | self.assertFalse(bom.external_references)
|
141 | 141 |
|
| 142 | + def test_root_component_only_bom(self) -> None: |
| 143 | + with warnings.catch_warnings(record=True) as w: |
| 144 | + warnings.simplefilter('always') |
| 145 | + bom = Bom(metadata=BomMetaData(component=Component(name='test', version='1.2'))) |
| 146 | + _ = JsonV1Dot6(bom).output_as_string() |
| 147 | + self.assertEqual(len(w), 0) |
| 148 | + |
| 149 | + def test_warning_missing_dependency(self) -> None: |
| 150 | + with self.assertWarns(expected_warning=UserWarning) as w: |
| 151 | + bom = Bom(metadata=BomMetaData(component=Component(name='root_component', version='1.2'))) |
| 152 | + bom.components.add(Component(name='test2', version='4.2')) |
| 153 | + _ = JsonV1Dot6(bom).output_as_string() |
| 154 | + self.assertEqual(len(w.warnings), 1) |
| 155 | + self.assertIn('has no defined dependencies ', str(w.warnings[0])) |
| 156 | + |
142 | 157 | def test_empty_bom_defined_serial(self) -> None:
|
143 | 158 | serial_number = uuid4()
|
144 | 159 | bom = Bom(serial_number=serial_number)
|
|
0 commit comments