@@ -72,28 +72,46 @@ def test_make_with_name(self) -> None:
72
72
73
73
class TestFactoryLicenseChoice (unittest .TestCase ):
74
74
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
+
75
88
def test_make_from_string_with_compound_expression (self ) -> None :
76
89
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 )
78
93
79
94
with unittest .mock .patch ('cyclonedx.factory.license.is_spdx_compound_expression' , return_value = True ):
80
95
actual = factory .make_from_string ('foo' )
81
96
82
97
self .assertEqual (expected , actual )
98
+ license_factory .make_with_id .assert_called_once_with ('foo' )
83
99
84
- def test_make_from_string_with_license (self ) -> None :
100
+ def test_make_from_string_with_license_name (self ) -> None :
85
101
license_ = unittest .mock .NonCallableMock (spec = License )
86
102
expected = LicenseChoice (license = license_ )
87
103
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_
89
106
factory = LicenseChoiceFactory (license_factory = license_factory )
90
107
91
108
with unittest .mock .patch ('cyclonedx.factory.license.is_spdx_compound_expression' , return_value = False ):
92
109
actual = factory .make_from_string ('foo' )
93
110
94
111
self .assertEqual (expected , actual )
95
112
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' )
97
115
98
116
def test_make_with_compound_expression (self ) -> None :
99
117
expected = LicenseChoice (expression = 'foo' )
@@ -119,8 +137,7 @@ def test_make_with_license(self) -> None:
119
137
license_factory .make_from_string .return_value = license_
120
138
factory = LicenseChoiceFactory (license_factory = license_factory )
121
139
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 )
124
141
125
142
self .assertEqual (expected , actual )
126
143
self .assertIs (license_ , actual .license )
0 commit comments