Skip to content

Commit 790f5ff

Browse files
committed
wip: serialization tests to XMl passing for 1.4
Signed-off-by: Paul Horton <[email protected]>
1 parent e711c87 commit 790f5ff

13 files changed

+185
-94
lines changed

cyclonedx/model/bom.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def supplier(self, supplier: Optional[OrganizationalEntity]) -> None:
173173
self._supplier = supplier
174174

175175
@property # type: ignore[misc]
176-
@serializable.xml_array(serializable.XmlArraySerializationType.FLAT, '')
176+
@serializable.xml_array(serializable.XmlArraySerializationType.FLAT, 'licenses')
177177
@serializable.xml_sequence(7)
178178
def licenses(self) -> "SortedSet[LicenseChoice]":
179179
"""
@@ -475,11 +475,11 @@ def register_dependency(self, target: Dependable, depends_on: Optional[Iterable[
475475

476476
if _d and depends_on:
477477
_d.dependencies = _d.dependencies + set(
478-
map(lambda _d: Dependency(ref=_d), depends_on)) if depends_on else []
479-
else:
478+
map(lambda _d: Dependency(ref=_d.bom_ref), depends_on)) if depends_on else []
479+
elif not _d:
480480
self._dependencies.add(Dependency(
481481
ref=target.bom_ref,
482-
dependencies=list(map(lambda _d: Dependency(ref=_d), depends_on)) if depends_on else []
482+
dependencies=list(map(lambda _d: Dependency(ref=_d.bom_ref), depends_on)) if depends_on else []
483483
))
484484

485485
def urn(self) -> str:
@@ -508,6 +508,8 @@ def validate(self) -> bool:
508508

509509
dependency_diff = all_dependency_bom_refs - all_bom_refs
510510
if len(dependency_diff) > 0:
511+
print(f'All Bom Refs: {all_bom_refs}')
512+
print(f'All Dep Bom Refs: {all_dependency_bom_refs}')
511513
raise UnknownComponentDependencyException(
512514
f'One or more Components have Dependency references to Components/Services that are not known in this '
513515
f'BOM. They are: {dependency_diff}')

cyclonedx/model/component.py

+20-10
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@
2727
from packageurl import PackageURL # type: ignore
2828
from sortedcontainers import SortedSet
2929

30-
from cyclonedx.serialization import BomRefHelper
31-
3230
from ..exception.model import NoPropertiesProvidedException
33-
from ..serialization import PackageUrl
31+
from ..serialization import BomRefHelper, PackageUrl
3432
from . import (
3533
AttachedText,
3634
ComparableTuple,
@@ -74,7 +72,8 @@ def __init__(self, *, uid: Optional[str] = None, url: Optional[XsUri] = None,
7472
self.committer = committer
7573
self.message = message
7674

77-
@property
75+
@property # type: ignore[misc]
76+
@serializable.xml_sequence(1)
7877
def uid(self) -> Optional[str]:
7978
"""
8079
A unique identifier of the commit. This may be version control specific. For example, Subversion uses revision
@@ -89,7 +88,8 @@ def uid(self) -> Optional[str]:
8988
def uid(self, uid: Optional[str]) -> None:
9089
self._uid = uid
9190

92-
@property
91+
@property # type: ignore[misc]
92+
@serializable.xml_sequence(2)
9393
def url(self) -> Optional[XsUri]:
9494
"""
9595
The URL to the commit. This URL will typically point to a commit in a version control system.
@@ -103,7 +103,8 @@ def url(self) -> Optional[XsUri]:
103103
def url(self, url: Optional[XsUri]) -> None:
104104
self._url = url
105105

106-
@property
106+
@property # type: ignore[misc]
107+
@serializable.xml_sequence(3)
107108
def author(self) -> Optional[IdentifiableAction]:
108109
"""
109110
The author who created the changes in the commit.
@@ -117,7 +118,8 @@ def author(self) -> Optional[IdentifiableAction]:
117118
def author(self, author: Optional[IdentifiableAction]) -> None:
118119
self._author = author
119120

120-
@property
121+
@property # type: ignore[misc]
122+
@serializable.xml_sequence(4)
121123
def committer(self) -> Optional[IdentifiableAction]:
122124
"""
123125
The person who committed or pushed the commit
@@ -131,7 +133,8 @@ def committer(self) -> Optional[IdentifiableAction]:
131133
def committer(self, committer: Optional[IdentifiableAction]) -> None:
132134
self._committer = committer
133135

134-
@property
136+
@property # type: ignore[misc]
137+
@serializable.xml_sequence(5)
135138
def message(self) -> Optional[str]:
136139
"""
137140
The text description of the contents of the commit.
@@ -378,7 +381,8 @@ def diff(self) -> Optional[Diff]:
378381
def diff(self, diff: Optional[Diff]) -> None:
379382
self._diff = diff
380383

381-
@property
384+
@property # type: ignore[misc]
385+
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'issue')
382386
def resolves(self) -> "SortedSet[IssueType]":
383387
"""
384388
Optional list of issues resolved by this patch.
@@ -443,6 +447,7 @@ def __init__(self, *, ancestors: Optional[Iterable['Component']] = None,
443447

444448
@property # type: ignore[misc]
445449
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'component')
450+
@serializable.xml_sequence(1)
446451
def ancestors(self) -> "SortedSet['Component']":
447452
"""
448453
Describes zero or more components in which a component is derived from. This is commonly used to describe forks
@@ -464,6 +469,7 @@ def ancestors(self, ancestors: Iterable['Component']) -> None:
464469

465470
@property # type: ignore[misc]
466471
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'component')
472+
@serializable.xml_sequence(2)
467473
def descendants(self) -> "SortedSet['Component']":
468474
"""
469475
Descendants are the exact opposite of ancestors. This provides a way to document all forks (and their forks) of
@@ -480,6 +486,7 @@ def descendants(self, descendants: Iterable['Component']) -> None:
480486

481487
@property # type: ignore[misc]
482488
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'component')
489+
@serializable.xml_sequence(3)
483490
def variants(self) -> "SortedSet['Component']":
484491
"""
485492
Variants describe relations where the relationship between the components are not known. For example, if
@@ -497,6 +504,7 @@ def variants(self, variants: Iterable['Component']) -> None:
497504

498505
@property # type: ignore[misc]
499506
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'commit')
507+
@serializable.xml_sequence(4)
500508
def commits(self) -> "SortedSet[Commit]":
501509
"""
502510
A list of zero or more commits which provide a trail describing how the component deviates from an ancestor,
@@ -513,6 +521,7 @@ def commits(self, commits: Iterable[Commit]) -> None:
513521

514522
@property # type: ignore[misc]
515523
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'patch')
524+
@serializable.xml_sequence(5)
516525
def patches(self) -> "SortedSet[Patch]":
517526
"""
518527
A list of zero or more patches describing how the component deviates from an ancestor, descendant, or variant.
@@ -527,7 +536,8 @@ def patches(self) -> "SortedSet[Patch]":
527536
def patches(self, patches: Iterable[Patch]) -> None:
528537
self._patches = SortedSet(patches)
529538

530-
@property
539+
@property # type: ignore[misc]
540+
@serializable.xml_sequence(6)
531541
def notes(self) -> Optional[str]:
532542
"""
533543
Notes, observations, and other non-structured commentary describing the components pedigree.

cyclonedx/model/impact_analysis.py

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# SPDX-License-Identifier: Apache-2.0
1818
# Copyright (c) OWASP Foundation. All Rights Reserved.
1919

20+
import serializable
2021
from enum import Enum
2122

2223
"""
@@ -29,6 +30,7 @@
2930
"""
3031

3132

33+
@serializable.serializable_enum
3234
class ImpactAnalysisAffectedStatus(str, Enum):
3335
"""
3436
Enum object that defines the permissible impact analysis affected states.
@@ -50,6 +52,7 @@ class ImpactAnalysisAffectedStatus(str, Enum):
5052
UNKNOWN = 'unknown'
5153

5254

55+
@serializable.serializable_enum
5356
class ImpactAnalysisJustification(str, Enum):
5457
"""
5558
Enum object that defines the rationale of why the impact analysis state was asserted.
@@ -69,6 +72,7 @@ class ImpactAnalysisJustification(str, Enum):
6972
REQUIRES_ENVIRONMENT = 'requires_environment'
7073

7174

75+
@serializable.serializable_enum
7276
class ImpactAnalysisResponse(str, Enum):
7377
"""
7478
Enum object that defines the valid rationales as to why the impact analysis state was asserted.
@@ -84,6 +88,7 @@ class ImpactAnalysisResponse(str, Enum):
8488
WORKAROUND_AVAILABLE = 'workaround_available'
8589

8690

91+
@serializable.serializable_enum
8792
class ImpactAnalysisState(str, Enum):
8893
"""
8994
Enum object that defines the permissible impact analysis states.

0 commit comments

Comments
 (0)