15
15
# SPDX-License-Identifier: Apache-2.0
16
16
17
17
import json
18
+ import os
18
19
from unittest import TestCase
19
20
from xml .etree import ElementTree
20
21
26
27
27
28
28
29
class TestE2EEnvironment (TestCase ):
30
+ _our_package_version : str
31
+
32
+ @classmethod
33
+ def setUpClass (cls ) -> None :
34
+ with open (os .path .join (os .path .realpath (os .path .join (os .path .dirname (os .path .realpath (__file__ )), '../' )),
35
+ 'VERSION' )) as _our_version :
36
+ cls ._our_package_version = _our_version .read ()
37
+
38
+ _our_version .close ()
29
39
30
40
def test_json_defaults (self ):
31
41
outputter : Json = get_instance (bom = Bom .from_parser (EnvironmentParser ()), output_format = OutputFormat .JSON )
32
42
bom_json = json .loads (outputter .output_as_string ())
33
43
component_this_library = next (
34
- (
x for x in bom_json [
'components' ]
if x [
'purl' ]
== 'pkg:pypi/[email protected] ' ),
None
44
+ (x for x in bom_json ['components' ] if
45
+ x ['purl' ] == 'pkg:pypi/cyclonedx-python-lib@{}' .format (TestE2EEnvironment ._our_package_version )), None
35
46
)
36
47
37
48
self .assertTrue ('author' in component_this_library .keys (), 'author is missing from JSON BOM' )
38
49
self .assertEqual (component_this_library ['author' ], 'Sonatype Community' )
39
50
self .assertEqual (component_this_library ['name' ], 'cyclonedx-python-lib' )
40
- self .assertEqual (component_this_library ['version' ], '0.0.1' )
51
+ self .assertEqual (component_this_library ['version' ], TestE2EEnvironment . _our_package_version )
41
52
42
53
def test_xml_defaults (self ):
43
54
outputter : Xml = get_instance (bom = Bom .from_parser (EnvironmentParser ()))
44
55
45
- # Check we have cyclonedx-python-lib version 0.0.1 with Author, Name and Version
56
+ # Check we have cyclonedx-python-lib with Author, Name and Version
46
57
bom_xml_e = ElementTree .fromstring (outputter .output_as_string ())
47
58
component_this_library = bom_xml_e .find ('./{{{}}}components/{{{}}}component[@bom-ref=\' pkg:pypi/{}\' ]' .format (
48
- outputter .
get_target_namespace (),
outputter .
get_target_namespace (),
'[email protected] '
59
+ outputter .get_target_namespace (), outputter .get_target_namespace (), 'cyclonedx-python-lib@{}' .format (
60
+ TestE2EEnvironment ._our_package_version
61
+ )
49
62
))
50
63
51
64
author = component_this_library .find ('./{{{}}}author' .format (outputter .get_target_namespace ()))
@@ -58,4 +71,4 @@ def test_xml_defaults(self):
58
71
59
72
version = component_this_library .find ('./{{{}}}version' .format (outputter .get_target_namespace ()))
60
73
self .assertIsNotNone (version , 'No version element but one was expected.' )
61
- self .assertEqual (version .text , '0.0.1' )
74
+ self .assertEqual (version .text , TestE2EEnvironment . _our_package_version )
0 commit comments