17
17
# SPDX-License-Identifier: Apache-2.0
18
18
# Copyright (c) OWASP Foundation. All Rights Reserved.
19
19
from os .path import dirname , join
20
- from typing import List
21
20
from unittest .mock import Mock , patch
22
21
23
22
from cyclonedx .model .bom import Bom
29
28
get_bom_with_nested_services , get_bom_with_services_simple , get_bom_with_services_complex
30
29
from tests .base import BaseXmlTestCase
31
30
31
+ TEST_UUIDS = [
32
+ MOCK_UUID_1 , MOCK_UUID_2 , MOCK_UUID_3 , MOCK_UUID_4 , MOCK_UUID_5 , MOCK_UUID_6
33
+ ]
32
34
33
- class TestOutputXml (BaseXmlTestCase ):
34
-
35
- UUID_INDEX : int = 0
36
- UUIDS : List [str ] = [
37
- MOCK_UUID_1 , MOCK_UUID_2 , MOCK_UUID_3 , MOCK_UUID_4 , MOCK_UUID_5 , MOCK_UUID_6
38
- ]
39
35
40
- def setUp (self ) -> None :
41
- TestOutputXml .UUID_INDEX = 0
42
-
43
- @staticmethod
44
- def iter_uuid () -> str :
45
- uuid = TestOutputXml .UUIDS [TestOutputXml .UUID_INDEX ]
46
- TestOutputXml .UUID_INDEX += 1
47
- return uuid
36
+ class TestOutputXml (BaseXmlTestCase ):
48
37
49
38
def test_simple_bom_v1_4 (self ) -> None :
50
39
self ._validate_xml_bom (
@@ -249,7 +238,7 @@ def test_bom_v1_0_with_metadata_component(self, mock_uuid: Mock) -> None:
249
238
mock_uuid .assert_called ()
250
239
251
240
@patch ('cyclonedx.model.component.uuid4' , return_value = MOCK_UUID_6 )
252
- @patch ('cyclonedx.model.service.uuid4' , side_effect = iter_uuid )
241
+ @patch ('cyclonedx.model.service.uuid4' , side_effect = TEST_UUIDS )
253
242
def test_bom_v1_4_services_simple (self , mock_uuid_c : Mock , mock_uuid_s : Mock ) -> None :
254
243
self ._validate_xml_bom (
255
244
bom = get_bom_with_services_simple (), schema_version = SchemaVersion .V1_4 ,
@@ -259,7 +248,7 @@ def test_bom_v1_4_services_simple(self, mock_uuid_c: Mock, mock_uuid_s: Mock) ->
259
248
mock_uuid_s .assert_called ()
260
249
261
250
@patch ('cyclonedx.model.component.uuid4' , return_value = MOCK_UUID_5 )
262
- @patch ('cyclonedx.model.service.uuid4' , side_effect = iter_uuid )
251
+ @patch ('cyclonedx.model.service.uuid4' , side_effect = TEST_UUIDS )
263
252
def test_bom_v1_3_services_simple (self , mock_uuid_c : Mock , mock_uuid_s : Mock ) -> None :
264
253
self ._validate_xml_bom (
265
254
bom = get_bom_with_services_simple (), schema_version = SchemaVersion .V1_3 ,
@@ -269,7 +258,7 @@ def test_bom_v1_3_services_simple(self, mock_uuid_c: Mock, mock_uuid_s: Mock) ->
269
258
mock_uuid_s .assert_called ()
270
259
271
260
@patch ('cyclonedx.model.component.uuid4' , return_value = MOCK_UUID_4 )
272
- @patch ('cyclonedx.model.service.uuid4' , side_effect = iter_uuid )
261
+ @patch ('cyclonedx.model.service.uuid4' , side_effect = TEST_UUIDS )
273
262
def test_bom_v1_2_services_simple (self , mock_uuid_c : Mock , mock_uuid_s : Mock ) -> None :
274
263
self ._validate_xml_bom (
275
264
bom = get_bom_with_services_simple (), schema_version = SchemaVersion .V1_2 ,
@@ -279,7 +268,7 @@ def test_bom_v1_2_services_simple(self, mock_uuid_c: Mock, mock_uuid_s: Mock) ->
279
268
mock_uuid_s .assert_called ()
280
269
281
270
@patch ('cyclonedx.model.component.uuid4' , return_value = MOCK_UUID_1 )
282
- @patch ('cyclonedx.model.service.uuid4' , side_effect = iter_uuid )
271
+ @patch ('cyclonedx.model.service.uuid4' , side_effect = TEST_UUIDS )
283
272
def test_bom_v1_1_services_simple (self , mock_uuid_c : Mock , mock_uuid_s : Mock ) -> None :
284
273
self ._validate_xml_bom (
285
274
bom = get_bom_with_services_simple (), schema_version = SchemaVersion .V1_1 ,
@@ -289,7 +278,7 @@ def test_bom_v1_1_services_simple(self, mock_uuid_c: Mock, mock_uuid_s: Mock) ->
289
278
mock_uuid_s .assert_called ()
290
279
291
280
@patch ('cyclonedx.model.component.uuid4' , return_value = MOCK_UUID_1 )
292
- @patch ('cyclonedx.model.service.uuid4' , side_effect = iter_uuid )
281
+ @patch ('cyclonedx.model.service.uuid4' , side_effect = TEST_UUIDS )
293
282
def test_bom_v1_0_services_simple (self , mock_uuid_c : Mock , mock_uuid_s : Mock ) -> None :
294
283
self ._validate_xml_bom (
295
284
bom = get_bom_with_services_simple (), schema_version = SchemaVersion .V1_0 ,
@@ -299,7 +288,7 @@ def test_bom_v1_0_services_simple(self, mock_uuid_c: Mock, mock_uuid_s: Mock) ->
299
288
mock_uuid_s .assert_called ()
300
289
301
290
@patch ('cyclonedx.model.component.uuid4' , return_value = MOCK_UUID_6 )
302
- @patch ('cyclonedx.model.service.uuid4' , side_effect = iter_uuid )
291
+ @patch ('cyclonedx.model.service.uuid4' , side_effect = TEST_UUIDS )
303
292
def test_bom_v1_4_services_complex (self , mock_uuid_c : Mock , mock_uuid_s : Mock ) -> None :
304
293
self ._validate_xml_bom (
305
294
bom = get_bom_with_services_complex (), schema_version = SchemaVersion .V1_4 ,
@@ -309,7 +298,7 @@ def test_bom_v1_4_services_complex(self, mock_uuid_c: Mock, mock_uuid_s: Mock) -
309
298
mock_uuid_s .assert_called ()
310
299
311
300
@patch ('cyclonedx.model.component.uuid4' , return_value = MOCK_UUID_5 )
312
- @patch ('cyclonedx.model.service.uuid4' , side_effect = iter_uuid )
301
+ @patch ('cyclonedx.model.service.uuid4' , side_effect = TEST_UUIDS )
313
302
def test_bom_v1_3_services_complex (self , mock_uuid_c : Mock , mock_uuid_s : Mock ) -> None :
314
303
self ._validate_xml_bom (
315
304
bom = get_bom_with_services_complex (), schema_version = SchemaVersion .V1_3 ,
@@ -319,7 +308,7 @@ def test_bom_v1_3_services_complex(self, mock_uuid_c: Mock, mock_uuid_s: Mock) -
319
308
mock_uuid_s .assert_called ()
320
309
321
310
@patch ('cyclonedx.model.component.uuid4' , return_value = MOCK_UUID_4 )
322
- @patch ('cyclonedx.model.service.uuid4' , side_effect = iter_uuid )
311
+ @patch ('cyclonedx.model.service.uuid4' , side_effect = TEST_UUIDS )
323
312
def test_bom_v1_2_services_complex (self , mock_uuid_c : Mock , mock_uuid_s : Mock ) -> None :
324
313
self ._validate_xml_bom (
325
314
bom = get_bom_with_services_complex (), schema_version = SchemaVersion .V1_2 ,
@@ -329,7 +318,7 @@ def test_bom_v1_2_services_complex(self, mock_uuid_c: Mock, mock_uuid_s: Mock) -
329
318
mock_uuid_s .assert_called ()
330
319
331
320
@patch ('cyclonedx.model.component.uuid4' , return_value = MOCK_UUID_3 )
332
- @patch ('cyclonedx.model.service.uuid4' , side_effect = iter_uuid )
321
+ @patch ('cyclonedx.model.service.uuid4' , side_effect = TEST_UUIDS )
333
322
def test_bom_v1_1_services_complex (self , mock_uuid_c : Mock , mock_uuid_s : Mock ) -> None :
334
323
self ._validate_xml_bom (
335
324
bom = get_bom_with_services_complex (), schema_version = SchemaVersion .V1_1 ,
@@ -339,7 +328,7 @@ def test_bom_v1_1_services_complex(self, mock_uuid_c: Mock, mock_uuid_s: Mock) -
339
328
mock_uuid_s .assert_called ()
340
329
341
330
@patch ('cyclonedx.model.component.uuid4' , return_value = MOCK_UUID_6 )
342
- @patch ('cyclonedx.model.service.uuid4' , side_effect = iter_uuid )
331
+ @patch ('cyclonedx.model.service.uuid4' , side_effect = TEST_UUIDS )
343
332
def test_bom_v1_4_services_nested (self , mock_uuid_c : Mock , mock_uuid_s : Mock ) -> None :
344
333
self ._validate_xml_bom (
345
334
bom = get_bom_with_nested_services (), schema_version = SchemaVersion .V1_4 ,
@@ -349,7 +338,7 @@ def test_bom_v1_4_services_nested(self, mock_uuid_c: Mock, mock_uuid_s: Mock) ->
349
338
mock_uuid_s .assert_called ()
350
339
351
340
@patch ('cyclonedx.model.component.uuid4' , return_value = MOCK_UUID_5 )
352
- @patch ('cyclonedx.model.service.uuid4' , side_effect = iter_uuid )
341
+ @patch ('cyclonedx.model.service.uuid4' , side_effect = TEST_UUIDS )
353
342
def test_bom_v1_3_services_nested (self , mock_uuid_c : Mock , mock_uuid_s : Mock ) -> None :
354
343
self ._validate_xml_bom (
355
344
bom = get_bom_with_nested_services (), schema_version = SchemaVersion .V1_3 ,
@@ -359,7 +348,7 @@ def test_bom_v1_3_services_nested(self, mock_uuid_c: Mock, mock_uuid_s: Mock) ->
359
348
mock_uuid_s .assert_called ()
360
349
361
350
@patch ('cyclonedx.model.component.uuid4' , return_value = MOCK_UUID_4 )
362
- @patch ('cyclonedx.model.service.uuid4' , side_effect = iter_uuid )
351
+ @patch ('cyclonedx.model.service.uuid4' , side_effect = TEST_UUIDS )
363
352
def test_bom_v1_2_services_nested (self , mock_uuid_c : Mock , mock_uuid_s : Mock ) -> None :
364
353
self ._validate_xml_bom (
365
354
bom = get_bom_with_nested_services (), schema_version = SchemaVersion .V1_2 ,
0 commit comments