@@ -72,28 +72,46 @@ def test_make_with_name(self) -> None:
7272
7373class TestFactoryLicenseChoice (unittest .TestCase ):
7474
75+ def test_make_from_string_with_license_id (self ) -> None :
76+ license_ = unittest .mock .NonCallableMock (spec = License )
77+ expected = LicenseChoice (license = license_ )
78+ license_factory = unittest .mock .MagicMock (spec = LicenseFactory )
79+ license_factory .make_with_id .return_value = license_
80+ factory = LicenseChoiceFactory (license_factory = license_factory )
81+
82+ actual = factory .make_from_string ('foo' )
83+
84+ self .assertEqual (expected , actual )
85+ self .assertIs (license_ , actual .license )
86+ license_factory .make_with_id .assert_called_once_with ('foo' )
87+
7588 def test_make_from_string_with_compound_expression (self ) -> None :
7689 expected = LicenseChoice (expression = 'foo' )
77- factory = LicenseChoiceFactory (license_factory = unittest .mock .MagicMock (spec = LicenseFactory ))
90+ license_factory = unittest .mock .MagicMock (spec = LicenseFactory )
91+ license_factory .make_with_id .side_effect = InvalidSpdxLicenseException ('foo' )
92+ factory = LicenseChoiceFactory (license_factory = license_factory )
7893
7994 with unittest .mock .patch ('cyclonedx.factory.license.is_spdx_compound_expression' , return_value = True ):
8095 actual = factory .make_from_string ('foo' )
8196
8297 self .assertEqual (expected , actual )
98+ license_factory .make_with_id .assert_called_once_with ('foo' )
8399
84- def test_make_from_string_with_license (self ) -> None :
100+ def test_make_from_string_with_license_name (self ) -> None :
85101 license_ = unittest .mock .NonCallableMock (spec = License )
86102 expected = LicenseChoice (license = license_ )
87103 license_factory = unittest .mock .MagicMock (spec = LicenseFactory )
88- license_factory .make_from_string .return_value = license_
104+ license_factory .make_with_id .side_effect = InvalidSpdxLicenseException ('foo' )
105+ license_factory .make_with_name .return_value = license_
89106 factory = LicenseChoiceFactory (license_factory = license_factory )
90107
91108 with unittest .mock .patch ('cyclonedx.factory.license.is_spdx_compound_expression' , return_value = False ):
92109 actual = factory .make_from_string ('foo' )
93110
94111 self .assertEqual (expected , actual )
95112 self .assertIs (license_ , actual .license )
96- license_factory .make_from_string .assert_called_once_with ('foo' , license_text = None , license_url = None )
113+ license_factory .make_with_id .assert_called_once_with ('foo' )
114+ license_factory .make_with_name .assert_called_once_with ('foo' )
97115
98116 def test_make_with_compound_expression (self ) -> None :
99117 expected = LicenseChoice (expression = 'foo' )
@@ -119,8 +137,7 @@ def test_make_with_license(self) -> None:
119137 license_factory .make_from_string .return_value = license_
120138 factory = LicenseChoiceFactory (license_factory = license_factory )
121139
122- with unittest .mock .patch ('cyclonedx.factory.license.is_spdx_compound_expression' , return_value = False ):
123- actual = factory .make_with_license ('foo' , license_text = text , license_url = url )
140+ actual = factory .make_with_license ('foo' , license_text = text , license_url = url )
124141
125142 self .assertEqual (expected , actual )
126143 self .assertIs (license_ , actual .license )
0 commit comments