Skip to content

Commit dd965da

Browse files
committed
Add tests in tests/_data/models.py, remove current
1 parent 3c9f234 commit dd965da

14 files changed

+209
-63
lines changed

tests/_data/models.py

+20
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,26 @@ def get_bom_for_issue540_duplicate_components() -> Bom:
14371437
bom.register_dependency(component1, [component3])
14381438
return bom
14391439

1440+
1441+
def get_bom_for_issue799_organizational_entity_bom_ref() -> Bom:
1442+
"""regression test for issue #799
1443+
see https://github.com/CycloneDX/cyclonedx-python-lib/issues/799
1444+
"""
1445+
return _make_bom(
1446+
metadata=BomMetaData(
1447+
tools=ToolRepository(
1448+
services=(
1449+
Service(name='service-1',
1450+
provider=OrganizationalEntity(
1451+
name='org-1',
1452+
bom_ref=BomRef('bom-ref-1'),
1453+
)),
1454+
)
1455+
)
1456+
)
1457+
)
1458+
1459+
14401460
# ---
14411461

14421462

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" ?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.0" version="1">
3+
<components/>
4+
</bom>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" ?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.1" serialNumber="urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac" version="1">
3+
<components/>
4+
</bom>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"metadata": {
3+
"timestamp": "2023-01-07T13:44:32.312678+00:00",
4+
"tools": [
5+
{
6+
"name": "service-1"
7+
}
8+
]
9+
},
10+
"serialNumber": "urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac",
11+
"version": 1,
12+
"$schema": "http://cyclonedx.org/schema/bom-1.2b.schema.json",
13+
"bomFormat": "CycloneDX",
14+
"specVersion": "1.2"
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" ?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.2" serialNumber="urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac" version="1">
3+
<metadata>
4+
<timestamp>2023-01-07T13:44:32.312678+00:00</timestamp>
5+
<tools>
6+
<tool>
7+
<name>service-1</name>
8+
</tool>
9+
</tools>
10+
</metadata>
11+
</bom>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"metadata": {
3+
"timestamp": "2023-01-07T13:44:32.312678+00:00",
4+
"tools": [
5+
{
6+
"name": "service-1"
7+
}
8+
]
9+
},
10+
"serialNumber": "urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac",
11+
"version": 1,
12+
"$schema": "http://cyclonedx.org/schema/bom-1.3a.schema.json",
13+
"bomFormat": "CycloneDX",
14+
"specVersion": "1.3"
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" ?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.3" serialNumber="urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac" version="1">
3+
<metadata>
4+
<timestamp>2023-01-07T13:44:32.312678+00:00</timestamp>
5+
<tools>
6+
<tool>
7+
<name>service-1</name>
8+
</tool>
9+
</tools>
10+
</metadata>
11+
</bom>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"metadata": {
3+
"timestamp": "2023-01-07T13:44:32.312678+00:00",
4+
"tools": [
5+
{
6+
"name": "service-1"
7+
}
8+
]
9+
},
10+
"serialNumber": "urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac",
11+
"version": 1,
12+
"$schema": "http://cyclonedx.org/schema/bom-1.4.schema.json",
13+
"bomFormat": "CycloneDX",
14+
"specVersion": "1.4"
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" ?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.4" serialNumber="urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac" version="1">
3+
<metadata>
4+
<timestamp>2023-01-07T13:44:32.312678+00:00</timestamp>
5+
<tools>
6+
<tool>
7+
<name>service-1</name>
8+
</tool>
9+
</tools>
10+
</metadata>
11+
</bom>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"metadata": {
3+
"timestamp": "2023-01-07T13:44:32.312678+00:00",
4+
"tools": {
5+
"services": [
6+
{
7+
"name": "service-1",
8+
"provider": {
9+
"bom-ref": "bom-ref-1",
10+
"name": "org-1"
11+
}
12+
}
13+
]
14+
}
15+
},
16+
"properties": [
17+
{
18+
"name": "key1",
19+
"value": "val1"
20+
},
21+
{
22+
"name": "key2",
23+
"value": "val2"
24+
}
25+
],
26+
"serialNumber": "urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac",
27+
"version": 1,
28+
"$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json",
29+
"bomFormat": "CycloneDX",
30+
"specVersion": "1.5"
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" ?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.5" serialNumber="urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac" version="1">
3+
<metadata>
4+
<timestamp>2023-01-07T13:44:32.312678+00:00</timestamp>
5+
<tools>
6+
<services>
7+
<service>
8+
<provider bom-ref="bom-ref-1">
9+
<name>org-1</name>
10+
</provider>
11+
<name>service-1</name>
12+
</service>
13+
</services>
14+
</tools>
15+
</metadata>
16+
<properties>
17+
<property name="key1">val1</property>
18+
<property name="key2">val2</property>
19+
</properties>
20+
</bom>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"metadata": {
3+
"timestamp": "2023-01-07T13:44:32.312678+00:00",
4+
"tools": {
5+
"services": [
6+
{
7+
"name": "service-1",
8+
"provider": {
9+
"bom-ref": "bom-ref-1",
10+
"name": "org-1"
11+
}
12+
}
13+
]
14+
}
15+
},
16+
"properties": [
17+
{
18+
"name": "key1",
19+
"value": "val1"
20+
},
21+
{
22+
"name": "key2",
23+
"value": "val2"
24+
}
25+
],
26+
"serialNumber": "urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac",
27+
"version": 1,
28+
"$schema": "http://cyclonedx.org/schema/bom-1.6.schema.json",
29+
"bomFormat": "CycloneDX",
30+
"specVersion": "1.6"
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" ?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.6" serialNumber="urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac" version="1">
3+
<metadata>
4+
<timestamp>2023-01-07T13:44:32.312678+00:00</timestamp>
5+
<tools>
6+
<services>
7+
<service>
8+
<provider bom-ref="bom-ref-1">
9+
<name>org-1</name>
10+
</provider>
11+
<name>service-1</name>
12+
</service>
13+
</services>
14+
</tools>
15+
</metadata>
16+
<properties>
17+
<property name="key1">val1</property>
18+
<property name="key2">val2</property>
19+
</properties>
20+
</bom>

tests/test_model.py

+1-63
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from uuid import UUID
2323

2424
from ddt import ddt, named_data
25-
from sortedcontainers import SortedSet
2625

2726
from cyclonedx._internal.compare import ComparableTuple
2827
from cyclonedx.exception.model import InvalidLocaleTypeException, InvalidUriException, UnknownHashTypeException
@@ -40,7 +39,7 @@
4039
XsUri,
4140
)
4241
from cyclonedx.model.bom_ref import BomRef
43-
from cyclonedx.model.contact import OrganizationalContact, OrganizationalEntity, PostalAddress
42+
from cyclonedx.model.contact import OrganizationalContact
4443
from cyclonedx.model.issue import IssueClassification, IssueType, IssueTypeSource
4544
from tests import reorder
4645

@@ -464,67 +463,6 @@ def test_sort(self) -> None:
464463
self.assertListEqual(sorted_contacts, expected_contacts)
465464

466465

467-
class TestModelOrganizationalEntity(TestCase):
468-
def test_init_with_bom_ref(self) -> None:
469-
contacts = [
470-
OrganizationalContact(name='a', email='a', phone='a'),
471-
OrganizationalContact(name='b', email='a', phone='a'),
472-
]
473-
OrganizationalEntity(
474-
bom_ref=BomRef('dummy-bom-ref'),
475-
name='dummy-organizational-entity',
476-
contacts=contacts,
477-
address=PostalAddress(
478-
country='dummy-country',
479-
region='dummy-region',
480-
),
481-
)
482-
483-
def test_init_without_bom_ref(self) -> None:
484-
contacts = [
485-
OrganizationalContact(name='a', email='a', phone='a'),
486-
OrganizationalContact(name='b', email='a', phone='a'),
487-
]
488-
OrganizationalEntity(
489-
name='dummy-organizational-entity',
490-
contacts=contacts,
491-
address=PostalAddress(
492-
country='dummy-country',
493-
region='dummy-region',
494-
),
495-
)
496-
497-
def test_init_from_json(self) -> None:
498-
bom_ref = 'Example'
499-
name = 'Example'
500-
urls = [
501-
'https://example.com/'
502-
]
503-
specification = {
504-
'name': name,
505-
'url': urls,
506-
'bom-ref': bom_ref
507-
}
508-
entity = OrganizationalEntity.from_json(specification)
509-
assert entity.name == name
510-
assert entity.urls == SortedSet([XsUri(url) for url in urls])
511-
assert entity.bom_ref == BomRef(bom_ref)
512-
assert len(entity.urls) == 1
513-
assert next(iter(entity.urls)) == XsUri(urls[0])
514-
515-
def test_init_from_json_without_url(self) -> None:
516-
bom_ref = 'Example'
517-
name = 'Example'
518-
specification = {
519-
'name': name,
520-
'bom-ref': bom_ref
521-
}
522-
entity = OrganizationalEntity.from_json(specification)
523-
assert entity.name == name
524-
assert entity.urls == SortedSet()
525-
assert entity.bom_ref == BomRef(bom_ref)
526-
527-
528466
class TestModelXsUri(TestCase):
529467

530468
# URI samples taken from http://www.datypic.com/sc/xsd/t-xsd_anyURI.html

0 commit comments

Comments
 (0)