Skip to content

Commit 5d907d5

Browse files
committed
Fixed unit tests pinned to a VERISON.
1 parent 1050839 commit 5d907d5

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

tests/test_e2e_environment.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# SPDX-License-Identifier: Apache-2.0
1616

1717
import json
18+
import os
1819
from unittest import TestCase
1920
from xml.etree import ElementTree
2021

@@ -26,26 +27,38 @@
2627

2728

2829
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()
2939

3040
def test_json_defaults(self):
3141
outputter: Json = get_instance(bom=Bom.from_parser(EnvironmentParser()), output_format=OutputFormat.JSON)
3242
bom_json = json.loads(outputter.output_as_string())
3343
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
3546
)
3647

3748
self.assertTrue('author' in component_this_library.keys(), 'author is missing from JSON BOM')
3849
self.assertEqual(component_this_library['author'], 'Sonatype Community')
3950
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)
4152

4253
def test_xml_defaults(self):
4354
outputter: Xml = get_instance(bom=Bom.from_parser(EnvironmentParser()))
4455

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
4657
bom_xml_e = ElementTree.fromstring(outputter.output_as_string())
4758
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+
)
4962
))
5063

5164
author = component_this_library.find('./{{{}}}author'.format(outputter.get_target_namespace()))
@@ -58,4 +71,4 @@ def test_xml_defaults(self):
5871

5972
version = component_this_library.find('./{{{}}}version'.format(outputter.get_target_namespace()))
6073
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

Comments
 (0)