|
10 | 10 | import urllib.parse |
11 | 11 | from datetime import datetime |
12 | 12 | from unittest import TestCase |
| 13 | +from unittest.mock import patch |
13 | 14 |
|
14 | 15 | import pytest |
15 | 16 | from django.core.exceptions import ValidationError |
| 17 | +from django.db.utils import IntegrityError |
16 | 18 | from django.test import TestCase as DjangoTestCase |
17 | 19 | from packageurl import PackageURL |
18 | 20 | from univers import versions |
|
25 | 27 | from vulnerabilities.importer import Reference |
26 | 28 | from vulnerabilities.models import Alias |
27 | 29 | from vulnerabilities.models import Package |
| 30 | +from vulnerabilities.models import Patch |
28 | 31 | from vulnerabilities.models import Vulnerability |
29 | 32 | from vulnerabilities.utils import compute_content_id |
30 | 33 |
|
@@ -647,9 +650,6 @@ def test_advisory_insert_no_duplicate_content_id(self): |
647 | 650 | ) |
648 | 651 |
|
649 | 652 |
|
650 | | -from unittest.mock import patch |
651 | | - |
652 | | - |
653 | 653 | class TestPipelineRunModel(DjangoTestCase): |
654 | 654 | def setUp(self): |
655 | 655 | self.schedule1 = models.PipelineSchedule.objects.create(pipeline_id="test_pipeline") |
@@ -694,3 +694,29 @@ def test_pipelineschedule_latest_run_date(self): |
694 | 694 |
|
695 | 695 | def test_pipelineschedule_all_runs(self): |
696 | 696 | self.assertEqual(self.schedule1.all_runs.count(), 2) |
| 697 | + |
| 698 | + |
| 699 | +class PatchConstraintTests(TestCase): |
| 700 | + @pytest.mark.django_db |
| 701 | + def test_constraint_none(self): |
| 702 | + with self.assertRaises(IntegrityError) as raised: |
| 703 | + Patch.objects.create(patch_url=None, patch_text=None) |
| 704 | + self.assertIn("patch_url_or_patch_text", str(raised.exception)) |
| 705 | + |
| 706 | + @pytest.mark.django_db |
| 707 | + def test_constraint_empty(self): |
| 708 | + with self.assertRaises(IntegrityError) as raised: |
| 709 | + Patch.objects.create(patch_url="", patch_text="") |
| 710 | + self.assertIn("patch_url_or_patch_text", str(raised.exception)) |
| 711 | + |
| 712 | + @pytest.mark.django_db |
| 713 | + def test_constraint_empty_none(self): |
| 714 | + with self.assertRaises(IntegrityError) as raised: |
| 715 | + Patch.objects.create(patch_url="", patch_text=None) |
| 716 | + self.assertIn("patch_url_or_patch_text", str(raised.exception)) |
| 717 | + |
| 718 | + @pytest.mark.django_db |
| 719 | + def test_constraint_none_empty(self): |
| 720 | + with self.assertRaises(IntegrityError) as raised: |
| 721 | + Patch.objects.create(patch_url=None, patch_text="") |
| 722 | + self.assertIn("patch_url_or_patch_text", str(raised.exception)) |
0 commit comments