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
12 changes: 1 addition & 11 deletions cyclonedx/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@
from sortedcontainers import SortedSet

from .._internal.compare import ComparableTuple as _ComparableTuple
from ..exception.model import (
InvalidLocaleTypeException,
InvalidUriException,
NoPropertiesProvidedException,
UnknownHashTypeException,
)
from ..exception.model import InvalidLocaleTypeException, InvalidUriException, UnknownHashTypeException
from ..exception.serialization import CycloneDxDeserializationException, SerializationOfUnexpectedValueException
from ..schema.schema import (
SchemaVersion1Dot0,
Expand Down Expand Up @@ -1180,11 +1175,6 @@ def __init__(
name: Optional[str] = None,
email: Optional[str] = None,
) -> None:
if not timestamp and not name and not email:
raise NoPropertiesProvidedException(
'At least one of `timestamp`, `name` or `email` must be provided for an `IdentifiableAction`.'
)

self.timestamp = timestamp
self.name = name
self.email = email
Expand Down
23 changes: 1 addition & 22 deletions cyclonedx/model/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from .._internal.bom_ref import bom_ref_from_str as _bom_ref_from_str
from .._internal.compare import ComparablePackageURL as _ComparablePackageURL, ComparableTuple as _ComparableTuple
from .._internal.hash import file_sha1sum as _file_sha1sum
from ..exception.model import InvalidOmniBorIdException, InvalidSwhidException, NoPropertiesProvidedException
from ..exception.model import InvalidOmniBorIdException, InvalidSwhidException
from ..exception.serialization import (
CycloneDxDeserializationException,
SerializationOfUnexpectedValueException,
Expand Down Expand Up @@ -82,11 +82,6 @@ def __init__(
committer: Optional[IdentifiableAction] = None,
message: Optional[str] = None,
) -> None:
if not uid and not url and not author and not committer and not message:
raise NoPropertiesProvidedException(
'At least one of `uid`, `url`, `author`, `committer` or `message` must be provided for a `Commit`.'
)

self.uid = uid
self.url = url
self.author = author
Expand Down Expand Up @@ -208,11 +203,6 @@ def __init__(
licenses: Optional[Iterable[License]] = None,
copyright: Optional[Iterable[Copyright]] = None,
) -> None:
if not licenses and not copyright:
raise NoPropertiesProvidedException(
'At least one of `licenses` or `copyright` must be supplied for a `ComponentEvidence`.'
)

self.licenses = licenses or [] # type:ignore[assignment]
self.copyright = copyright or [] # type:ignore[assignment]

Expand Down Expand Up @@ -442,11 +432,6 @@ def __init__(
text: Optional[AttachedText] = None,
url: Optional[XsUri] = None,
) -> None:
if not text and not url:
raise NoPropertiesProvidedException(
'At least one of `text` or `url` must be provided for a `Diff`.'
)

self.text = text
self.url = url

Expand Down Expand Up @@ -624,12 +609,6 @@ def __init__(
patches: Optional[Iterable[Patch]] = None,
notes: Optional[str] = None,
) -> None:
if not ancestors and not descendants and not variants and not commits and not patches and not notes:
raise NoPropertiesProvidedException(
'At least one of `ancestors`, `descendants`, `variants`, `commits`, `patches` or `notes` must be '
'provided for `Pedigree`'
)

self.ancestors = ancestors or [] # type:ignore[assignment]
self.descendants = descendants or [] # type:ignore[assignment]
self.variants = variants or [] # type:ignore[assignment]
Expand Down
5 changes: 0 additions & 5 deletions cyclonedx/model/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from sortedcontainers import SortedSet

from .._internal.compare import ComparableTuple as _ComparableTuple
from ..exception.model import NoPropertiesProvidedException
from . import XsUri


Expand Down Expand Up @@ -54,10 +53,6 @@ def __init__(
name: Optional[str] = None,
url: Optional[XsUri] = None,
) -> None:
if not name and not url:
raise NoPropertiesProvidedException(
'Neither `name` nor `url` were provided - at least one must be provided.'
)
self.name = name
self.url = url

Expand Down
30 changes: 6 additions & 24 deletions cyclonedx/model/vulnerability.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class BomTargetVersionRange:
`version` and `version_range` are mutually exclusive.

.. note::
See the CycloneDX schema: https://cyclonedx.org/docs/1.6/#type_vulnerabilityType
See the CycloneDX schema: https://cyclonedx.org/docs/1.6/xml/#type_vulnerabilityType
"""

def __init__(
Expand Down Expand Up @@ -219,7 +219,7 @@ class VulnerabilityAnalysis:
Class that models the `analysis` sub-element of the `vulnerabilityType` complex type.

.. note::
See the CycloneDX schema: https://cyclonedx.org/docs/1.6/#type_vulnerabilityType
See the CycloneDX schema: https://cyclonedx.org/docs/1.6/xml/#type_vulnerabilityType
"""

def __init__(
Expand All @@ -229,11 +229,6 @@ def __init__(
responses: Optional[Iterable[ImpactAnalysisResponse]] = None,
detail: Optional[str] = None,
) -> None:
if not state and not justification and not responses and not detail:
raise NoPropertiesProvidedException(
'At least one of state, justification, responses or detail must be provided for VulnerabilityAnalysis '
'- none supplied'
)
self.state = state
self.justification = justification
self.responses = responses or [] # type:ignore[assignment]
Expand Down Expand Up @@ -408,18 +403,14 @@ class VulnerabilitySource:
This type is used for multiple purposes in the CycloneDX schema.

.. note::
See the CycloneDX schema: https://cyclonedx.org/docs/1.6/#type_vulnerabilitySourceType
See the CycloneDX schema: https://cyclonedx.org/docs/1.6/xml/#type_vulnerabilitySourceType
"""

def __init__(
self, *,
name: Optional[str] = None,
url: Optional[XsUri] = None,
) -> None:
if not name and not url:
raise NoPropertiesProvidedException(
'Either name or url must be provided for a VulnerabilitySource - neither provided'
)
self.name = name
self.url = url

Expand Down Expand Up @@ -480,7 +471,7 @@ class VulnerabilityReference:
intelligence.

.. note::
See the CycloneDX schema: https://cyclonedx.org/docs/1.6/#type_vulnerabilityType
See the CycloneDX schema: https://cyclonedx.org/docs/1.6/xml/#type_vulnerabilityType
"""

def __init__(
Expand Down Expand Up @@ -723,7 +714,7 @@ class VulnerabilityRating:
1.4 - see https://github.com/CycloneDX/specification/blob/master/schema/ext/vulnerability-1.0.xsd.

.. note::
See `ratingType` in https://cyclonedx.org/docs/1.6/#ratingType
See `ratingType` in https://cyclonedx.org/docs/1.6/xml/#ratingType

.. warning::
As part of implementing support for CycloneDX schema version 1.4, the three score types defined in the schema
Expand All @@ -741,11 +732,6 @@ def __init__(
vector: Optional[str] = None,
justification: Optional[str] = None,
) -> None:
if not source and not score and not severity and not method and not vector and not justification:
raise NoPropertiesProvidedException(
'At least one property must be provided when creating a VulnerabilityRating - none supplied.'
)

self.source = source
self.score = score
self.severity = severity
Expand Down Expand Up @@ -861,18 +847,14 @@ class VulnerabilityCredits:
extension (in XML only).

.. note::
See the CycloneDX schema: https://cyclonedx.org/docs/1.6/#type_vulnerabilityType
See the CycloneDX schema: https://cyclonedx.org/docs/1.6/xml/#type_vulnerabilityType
"""

def __init__(
self, *,
organizations: Optional[Iterable[OrganizationalEntity]] = None,
individuals: Optional[Iterable[OrganizationalContact]] = None,
) -> None:
if not organizations and not individuals:
raise NoPropertiesProvidedException(
'One of `organizations` or `individuals` must be populated - neither were'
)
self.organizations = organizations or [] # type:ignore[assignment]
self.individuals = individuals or [] # type:ignore[assignment]

Expand Down
10 changes: 2 additions & 8 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@
from ddt import ddt, named_data

from cyclonedx._internal.compare import ComparableTuple
from cyclonedx.exception.model import (
InvalidLocaleTypeException,
InvalidUriException,
NoPropertiesProvidedException,
UnknownHashTypeException,
)
from cyclonedx.exception.model import InvalidLocaleTypeException, InvalidUriException, UnknownHashTypeException
from cyclonedx.model import (
Copyright,
Encoding,
Expand Down Expand Up @@ -309,8 +304,7 @@ def test_sort(self) -> None:
class TestModelIdentifiableAction(TestCase):

def test_no_params(self) -> None:
with self.assertRaises(NoPropertiesProvidedException):
IdentifiableAction()
IdentifiableAction() # Does not raise `NoPropertiesProvidedException`

def test_same(self) -> None:
ts = datetime.datetime.utcnow()
Expand Down
13 changes: 4 additions & 9 deletions tests/test_model_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from typing import List
from unittest import TestCase

from cyclonedx.exception.model import NoPropertiesProvidedException
from cyclonedx.model import (
AttachedText,
Copyright,
Expand Down Expand Up @@ -57,8 +56,7 @@
class TestModelCommit(TestCase):

def test_no_parameters(self) -> None:
with self.assertRaises(NoPropertiesProvidedException):
Commit()
Commit() # Does not raise `NoPropertiesProvidedException`

def test_same(self) -> None:
ia_comitter = IdentifiableAction(timestamp=datetime.datetime.utcnow(), name='The Committer')
Expand Down Expand Up @@ -287,8 +285,7 @@ def test_nested_components_2(self) -> None:
class TestModelComponentEvidence(TestCase):

def test_no_params(self) -> None:
with self.assertRaises(NoPropertiesProvidedException):
ComponentEvidence()
ComponentEvidence() # Does not raise `NoPropertiesProvidedException`

def test_same_1(self) -> None:
ce_1 = ComponentEvidence(copyright=[Copyright(text='Commercial')])
Expand All @@ -312,8 +309,7 @@ def test_not_same_1(self) -> None:
class TestModelDiff(TestCase):

def test_no_params(self) -> None:
with self.assertRaises(NoPropertiesProvidedException):
Diff()
Diff() # Does not raise `NoPropertiesProvidedException`

def test_same(self) -> None:
at = AttachedText(content='A very long diff')
Expand Down Expand Up @@ -437,8 +433,7 @@ def test_sort(self) -> None:
class TestModelPedigree(TestCase):

def test_no_params(self) -> None:
with self.assertRaises(NoPropertiesProvidedException):
Pedigree()
Pedigree() # does not raise `NoPropertiesProvidedException`

def test_same_1(self) -> None:
p1 = get_pedigree_1()
Expand Down
4 changes: 1 addition & 3 deletions tests/test_model_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

from unittest import TestCase

from cyclonedx.exception.model import NoPropertiesProvidedException
from cyclonedx.model import XsUri
from cyclonedx.model.issue import IssueClassification, IssueType, IssueTypeSource
from tests import reorder
Expand Down Expand Up @@ -63,8 +62,7 @@ def test_sort(self) -> None:
class TestModelIssueTypeSource(TestCase):

def test_no_params(self) -> None:
with self.assertRaises(NoPropertiesProvidedException):
IssueTypeSource()
IssueTypeSource() # Does not raise `NoPropertiesProvidedException`

def test_same(self) -> None:
its_1 = IssueTypeSource(name='The Source', url=XsUri('https://cyclonedx.org'))
Expand Down