|
37 | 37 | from cyclonedx.model import (
|
38 | 38 | AttachedText,
|
39 | 39 | Copyright,
|
| 40 | + Encoding, |
40 | 41 | ExternalReference,
|
41 | 42 | ExternalReferenceType,
|
42 | 43 | IdentifiableAction,
|
@@ -364,21 +365,41 @@ def test_not_same(self) -> None:
|
364 | 365 | self.assertFalse(diff_1 == diff_2)
|
365 | 366 |
|
366 | 367 | def test_sort(self) -> None:
|
| 368 | + text_a = AttachedText(content='a') |
| 369 | + text_b = AttachedText(content='b') |
| 370 | + |
367 | 371 | # expected sort order: ([url], [text])
|
368 | 372 | expected_order = [1, 0, 5, 2, 3, 4]
|
369 | 373 | diffs = [
|
370 |
| - Diff(url=XsUri('a'), text='b'), |
371 |
| - Diff(url=XsUri('a'), text='a'), |
372 |
| - Diff(url=XsUri('b'), text='a'), |
373 |
| - Diff(text='a'), |
374 |
| - Diff(text='b'), |
| 374 | + Diff(url=XsUri('a'), text=text_b), |
| 375 | + Diff(url=XsUri('a'), text=text_a), |
| 376 | + Diff(url=XsUri('b'), text=text_a), |
| 377 | + Diff(text=text_a), |
| 378 | + Diff(text=text_b), |
375 | 379 | Diff(url=XsUri('a')),
|
376 | 380 | ]
|
377 | 381 | sorted_diffs = sorted(diffs)
|
378 | 382 | expected_diffs = reorder(diffs, expected_order)
|
379 | 383 | self.assertListEqual(sorted_diffs, expected_diffs)
|
380 | 384 |
|
381 | 385 |
|
| 386 | +class TestModelAttachedText(TestCase): |
| 387 | + |
| 388 | + def test_sort(self) -> None: |
| 389 | + # expected sort order: (content_type, content, encoding) |
| 390 | + expected_order = [0, 4, 2, 1, 3] |
| 391 | + text = [ |
| 392 | + AttachedText(content='a', content_type='a', encoding=Encoding.BASE_64), |
| 393 | + AttachedText(content='a', content_type='b', encoding=Encoding.BASE_64), |
| 394 | + AttachedText(content='b', content_type='a', encoding=Encoding.BASE_64), |
| 395 | + AttachedText(content='b', content_type='b', encoding=Encoding.BASE_64), |
| 396 | + AttachedText(content='a', content_type='a'), |
| 397 | + ] |
| 398 | + sorted_text = sorted(text) |
| 399 | + expected_text = reorder(text, expected_order) |
| 400 | + self.assertListEqual(sorted_text, expected_text) |
| 401 | + |
| 402 | + |
382 | 403 | class TestModelPatch(TestCase):
|
383 | 404 |
|
384 | 405 | def test_same_1(self) -> None:
|
@@ -425,8 +446,8 @@ def test_not_same_1(self) -> None:
|
425 | 446 | self.assertFalse(p1 == p2)
|
426 | 447 |
|
427 | 448 | def test_sort(self) -> None:
|
428 |
| - diff_a = Diff(text='a') |
429 |
| - diff_b = Diff(text='b') |
| 449 | + diff_a = Diff(text=AttachedText(content='a')) |
| 450 | + diff_b = Diff(text=AttachedText(content='b')) |
430 | 451 |
|
431 | 452 | resolves_a = [
|
432 | 453 | IssueType(classification=IssueClassification.DEFECT),
|
|
0 commit comments