Skip to content

Commit

Permalink
Fixed unit tests pinned to a VERISON.
Browse files Browse the repository at this point in the history
  • Loading branch information
madpah committed Sep 6, 2021
1 parent 1050839 commit 5d907d5
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions tests/test_e2e_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# SPDX-License-Identifier: Apache-2.0

import json
import os
from unittest import TestCase
from xml.etree import ElementTree

Expand All @@ -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()))
Expand All @@ -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)

0 comments on commit 5d907d5

Please sign in to comment.