|
13 | 13 |
|
14 | 14 | import responses |
15 | 15 |
|
16 | | -sys.path.insert(1, "..") |
| 16 | +from sw360 import SW360, SW360Error |
17 | 17 |
|
18 | | -from sw360 import SW360 # noqa: E402 |
| 18 | +sys.path.insert(1, "..") |
19 | 19 |
|
20 | 20 |
|
21 | 21 | class Sw360TestLicenses(unittest.TestCase): |
@@ -123,6 +123,93 @@ def test_get_license(self): |
123 | 123 | self.assertEqual("Apache-2.0", license["shortName"]) |
124 | 124 | self.assertEqual("Apache License 2.0", license["fullName"]) |
125 | 125 |
|
| 126 | + @responses.activate |
| 127 | + def test_create_new_license(self): |
| 128 | + lib = SW360(self.MYURL, self.MYTOKEN, False) |
| 129 | + self._add_login_response() |
| 130 | + actual = lib.login_api() |
| 131 | + self.assertTrue(actual) |
| 132 | + |
| 133 | + responses.add( |
| 134 | + responses.POST, |
| 135 | + url=f"{self.MYURL}resource/api/licenses", |
| 136 | + status=201, |
| 137 | + json={ |
| 138 | + # server returns full license, here we only mock a part of it |
| 139 | + 'shortName': 'LGPL-2.0-only', |
| 140 | + 'fullName': 'GNU Library General Public License v2 only', |
| 141 | + 'checked': True, |
| 142 | + '_links': { |
| 143 | + 'self': { |
| 144 | + 'href': f"{self.MYURL}resource/api/licenses/LGPL-2.0-only" |
| 145 | + } |
| 146 | + } |
| 147 | + }, |
| 148 | + match=[responses.json_params_matcher({ |
| 149 | + "shortName": "LGPL-2.0-only", |
| 150 | + "fullName": "GNU Library General Public License v2 only", |
| 151 | + "checked": True, |
| 152 | + "text": ""})] |
| 153 | + ) |
| 154 | + lib.create_new_license( |
| 155 | + shortName="LGPL-2.0-only", |
| 156 | + fullName="GNU Library General Public License v2 only", |
| 157 | + text="", |
| 158 | + checked=True, |
| 159 | + ) |
| 160 | + |
| 161 | + @responses.activate |
| 162 | + def test_create_new_license_fail(self): |
| 163 | + lib = SW360(self.MYURL, self.MYTOKEN, False) |
| 164 | + self._add_login_response() |
| 165 | + actual = lib.login_api() |
| 166 | + self.assertTrue(actual) |
| 167 | + |
| 168 | + responses.add( |
| 169 | + responses.POST, |
| 170 | + url=f"{self.MYURL}resource/api/licenses", |
| 171 | + status=403, |
| 172 | + json={ |
| 173 | + # server returns full license, here we only mock a part of it |
| 174 | + 'shortName': 'LGPL-2.0-only', |
| 175 | + 'fullName': 'GNU Library General Public License v2 only', |
| 176 | + 'checked': True, |
| 177 | + '_links': { |
| 178 | + 'self': { |
| 179 | + 'href': f"{self.MYURL}resource/api/licenses/LGPL-2.0-only" |
| 180 | + } |
| 181 | + } |
| 182 | + }, |
| 183 | + match=[responses.json_params_matcher({ |
| 184 | + "shortName": "LGPL-2.0-only", |
| 185 | + "fullName": "GNU Library General Public License v2 only", |
| 186 | + "checked": True, |
| 187 | + "text": ""})] |
| 188 | + ) |
| 189 | + |
| 190 | + with self.assertRaises(SW360Error) as context: |
| 191 | + lib.create_new_license( |
| 192 | + shortName="LGPL-2.0-only", |
| 193 | + fullName="GNU Library General Public License v2 only", |
| 194 | + text="", |
| 195 | + checked=True, |
| 196 | + ) |
| 197 | + self.assertEqual(403, context.exception.response.status_code) |
| 198 | + |
| 199 | + @responses.activate |
| 200 | + def test_delete_license(self): |
| 201 | + lib = SW360(self.MYURL, self.MYTOKEN, False) |
| 202 | + self._add_login_response() |
| 203 | + actual = lib.login_api() |
| 204 | + self.assertTrue(actual) |
| 205 | + |
| 206 | + responses.add( |
| 207 | + responses.DELETE, |
| 208 | + url=self.MYURL + "resource/api/licenses/LGPL-2.0-only", |
| 209 | + status=201) |
| 210 | + |
| 211 | + lib.delete_license("LGPL-2.0-only") |
| 212 | + |
126 | 213 |
|
127 | 214 | if __name__ == "__main__": |
128 | 215 | unittest.main() |
0 commit comments