-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed unit tests pinned to a VERISON.
- Loading branch information
Showing
1 changed file
with
18 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import json | ||
import os | ||
from unittest import TestCase | ||
from xml.etree import ElementTree | ||
|
||
|
@@ -26,26 +27,38 @@ | |
|
||
|
||
class TestE2EEnvironment(TestCase): | ||
_our_package_version: str | ||
|
||
@classmethod | ||
def setUpClass(cls) -> None: | ||
with open(os.path.join(os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../')), | ||
'VERSION')) as _our_version: | ||
cls._our_package_version = _our_version.read() | ||
|
||
_our_version.close() | ||
|
||
def test_json_defaults(self): | ||
outputter: Json = get_instance(bom=Bom.from_parser(EnvironmentParser()), output_format=OutputFormat.JSON) | ||
bom_json = json.loads(outputter.output_as_string()) | ||
component_this_library = next( | ||
(x for x in bom_json['components'] if x['purl'] == 'pkg:pypi/[email protected]'), None | ||
(x for x in bom_json['components'] if | ||
x['purl'] == 'pkg:pypi/cyclonedx-python-lib@{}'.format(TestE2EEnvironment._our_package_version)), None | ||
) | ||
|
||
self.assertTrue('author' in component_this_library.keys(), 'author is missing from JSON BOM') | ||
self.assertEqual(component_this_library['author'], 'Sonatype Community') | ||
self.assertEqual(component_this_library['name'], 'cyclonedx-python-lib') | ||
self.assertEqual(component_this_library['version'], '0.0.1') | ||
self.assertEqual(component_this_library['version'], TestE2EEnvironment._our_package_version) | ||
|
||
def test_xml_defaults(self): | ||
outputter: Xml = get_instance(bom=Bom.from_parser(EnvironmentParser())) | ||
|
||
# Check we have cyclonedx-python-lib version 0.0.1 with Author, Name and Version | ||
# Check we have cyclonedx-python-lib with Author, Name and Version | ||
bom_xml_e = ElementTree.fromstring(outputter.output_as_string()) | ||
component_this_library = bom_xml_e.find('./{{{}}}components/{{{}}}component[@bom-ref=\'pkg:pypi/{}\']'.format( | ||
outputter.get_target_namespace(), outputter.get_target_namespace(), '[email protected]' | ||
outputter.get_target_namespace(), outputter.get_target_namespace(), 'cyclonedx-python-lib@{}'.format( | ||
TestE2EEnvironment._our_package_version | ||
) | ||
)) | ||
|
||
author = component_this_library.find('./{{{}}}author'.format(outputter.get_target_namespace())) | ||
|
@@ -58,4 +71,4 @@ def test_xml_defaults(self): | |
|
||
version = component_this_library.find('./{{{}}}version'.format(outputter.get_target_namespace())) | ||
self.assertIsNotNone(version, 'No version element but one was expected.') | ||
self.assertEqual(version.text, '0.0.1') | ||
self.assertEqual(version.text, TestE2EEnvironment._our_package_version) |