Skip to content

Commit 92fffaa

Browse files
committed
update tests
1 parent f8478c6 commit 92fffaa

24 files changed

Lines changed: 5103 additions & 0 deletions

arch/tests/test_models.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Copyright 2025 Marcus Furlong <furlongm@gmail.com>
2+
#
3+
# This file is part of Patchman.
4+
#
5+
# Patchman is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, version 3 only.
8+
#
9+
# Patchman is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with Patchman. If not, see <http://www.gnu.org/licenses/>
16+
17+
from django.test import TestCase, override_settings
18+
19+
from arch.models import MachineArchitecture, PackageArchitecture
20+
21+
22+
@override_settings(
23+
CELERY_TASK_ALWAYS_EAGER=True,
24+
CACHES={'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}}
25+
)
26+
class MachineArchitectureMethodTests(TestCase):
27+
"""Tests for MachineArchitecture model methods."""
28+
29+
def test_machine_arch_creation(self):
30+
"""Test creating a MachineArchitecture."""
31+
arch = MachineArchitecture.objects.create(name='x86_64')
32+
self.assertEqual(arch.name, 'x86_64')
33+
34+
def test_machine_arch_str(self):
35+
"""Test MachineArchitecture __str__ method."""
36+
arch = MachineArchitecture.objects.create(name='x86_64')
37+
self.assertEqual(str(arch), 'x86_64')
38+
39+
def test_machine_arch_unique_name(self):
40+
"""Test MachineArchitecture name is unique."""
41+
MachineArchitecture.objects.create(name='x86_64')
42+
from django.db import IntegrityError
43+
with self.assertRaises(IntegrityError):
44+
MachineArchitecture.objects.create(name='x86_64')
45+
46+
def test_common_machine_architectures(self):
47+
"""Test common machine architecture values."""
48+
archs = ['x86_64', 'aarch64', 'i686', 'armv7l', 'ppc64le']
49+
for name in archs:
50+
arch = MachineArchitecture.objects.create(name=name)
51+
self.assertEqual(str(arch), name)
52+
53+
54+
@override_settings(
55+
CELERY_TASK_ALWAYS_EAGER=True,
56+
CACHES={'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}}
57+
)
58+
class PackageArchitectureMethodTests(TestCase):
59+
"""Tests for PackageArchitecture model methods."""
60+
61+
def test_package_arch_creation(self):
62+
"""Test creating a PackageArchitecture."""
63+
arch = PackageArchitecture.objects.create(name='amd64')
64+
self.assertEqual(arch.name, 'amd64')
65+
66+
def test_package_arch_str(self):
67+
"""Test PackageArchitecture __str__ method."""
68+
arch = PackageArchitecture.objects.create(name='amd64')
69+
self.assertEqual(str(arch), 'amd64')
70+
71+
def test_package_arch_unique_name(self):
72+
"""Test PackageArchitecture name is unique."""
73+
PackageArchitecture.objects.create(name='amd64')
74+
from django.db import IntegrityError
75+
with self.assertRaises(IntegrityError):
76+
PackageArchitecture.objects.create(name='amd64')
77+
78+
def test_common_package_architectures(self):
79+
"""Test common package architecture values."""
80+
archs = ['amd64', 'i386', 'all', 'noarch', 'x86_64', 'arm64']
81+
for name in archs:
82+
arch = PackageArchitecture.objects.create(name=name)
83+
self.assertEqual(str(arch), name)

domains/tests/test_models.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright 2025 Marcus Furlong <furlongm@gmail.com>
2+
#
3+
# This file is part of Patchman.
4+
#
5+
# Patchman is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, version 3 only.
8+
#
9+
# Patchman is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with Patchman. If not, see <http://www.gnu.org/licenses/>
16+
17+
from django.test import TestCase, override_settings
18+
19+
from domains.models import Domain
20+
21+
22+
@override_settings(
23+
CELERY_TASK_ALWAYS_EAGER=True,
24+
CACHES={'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}}
25+
)
26+
class DomainMethodTests(TestCase):
27+
"""Tests for Domain model methods."""
28+
29+
def test_domain_creation(self):
30+
"""Test creating a Domain."""
31+
domain = Domain.objects.create(name='example.com')
32+
self.assertEqual(domain.name, 'example.com')
33+
34+
def test_domain_str(self):
35+
"""Test Domain __str__ method."""
36+
domain = Domain.objects.create(name='example.com')
37+
self.assertEqual(str(domain), 'example.com')
38+
39+
def test_domain_unique_name(self):
40+
"""Test Domain name is unique."""
41+
Domain.objects.create(name='example.com')
42+
from django.db import IntegrityError
43+
with self.assertRaises(IntegrityError):
44+
Domain.objects.create(name='example.com')
45+
46+
def test_domain_extract_from_fqdn(self):
47+
"""Test extracting domain from FQDN via Host creation."""
48+
# Domains are typically extracted when hosts are created
49+
# Test the domain itself can be created with subdomain parts
50+
Domain.objects.create(name='subdomain.example.com')
51+
domain = Domain.objects.get(name='subdomain.example.com')
52+
self.assertEqual(domain.name, 'subdomain.example.com')

errata/tests/test_integration.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Copyright 2025 Marcus Furlong <furlongm@gmail.com>
2+
#
3+
# This file is part of Patchman.
4+
#
5+
# Patchman is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, version 3 only.
8+
#
9+
# Patchman is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with Patchman. If not, see <http://www.gnu.org/licenses/>
16+
17+
from django.test import TestCase, override_settings
18+
19+
from errata.models import Erratum
20+
from operatingsystems.models import OSRelease
21+
from security.models import CVE
22+
23+
24+
@override_settings(
25+
CELERY_TASK_ALWAYS_EAGER=True,
26+
CACHES={'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}}
27+
)
28+
class ErrataIntegrationTests(TestCase):
29+
"""Integration tests for errata functionality."""
30+
31+
def test_erratum_with_cves(self):
32+
"""Test erratum can be associated with CVEs."""
33+
cve1 = CVE.objects.create(cve_id='CVE-2024-1001')
34+
cve2 = CVE.objects.create(cve_id='CVE-2024-1002')
35+
36+
erratum = Erratum.objects.create(
37+
name='RHSA-2024:1234',
38+
e_type='Security Advisory',
39+
synopsis='Important: curl security update',
40+
issue_date='2024-03-15',
41+
)
42+
erratum.cves.add(cve1, cve2)
43+
44+
self.assertEqual(erratum.cves.count(), 2)
45+
self.assertIn(cve1, erratum.cves.all())
46+
self.assertIn(cve2, erratum.cves.all())
47+
48+
def test_erratum_with_osreleases(self):
49+
"""Test erratum can be associated with OS releases."""
50+
osrelease1 = OSRelease.objects.create(name='Rocky Linux 9')
51+
osrelease2 = OSRelease.objects.create(name='Rocky Linux 8')
52+
53+
erratum = Erratum.objects.create(
54+
name='RHSA-2024:1235',
55+
e_type='Security Advisory',
56+
synopsis='Important: openssl security update',
57+
issue_date='2024-03-16',
58+
)
59+
erratum.osreleases.add(osrelease1, osrelease2)
60+
61+
self.assertEqual(erratum.osreleases.count(), 2)
62+
63+
def test_erratum_with_packages(self):
64+
"""Test erratum can reference package names."""
65+
erratum = Erratum.objects.create(
66+
name='RHSA-2024:1236',
67+
e_type='Bug Fix',
68+
synopsis='Bug fix: httpd update',
69+
issue_date='2024-03-17',
70+
)
71+
72+
# Verify erratum can store package references
73+
self.assertIsNotNone(erratum)
74+
self.assertEqual(erratum.e_type, 'Bug Fix')

errata/tests/test_models.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Copyright 2025 Marcus Furlong <furlongm@gmail.com>
2+
#
3+
# This file is part of Patchman.
4+
#
5+
# Patchman is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, version 3 only.
8+
#
9+
# Patchman is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with Patchman. If not, see <http://www.gnu.org/licenses/>
16+
17+
from django.test import TestCase, override_settings
18+
from django.utils import timezone
19+
20+
from errata.models import Erratum
21+
from operatingsystems.models import OSRelease
22+
from security.models import CVE
23+
24+
25+
@override_settings(
26+
CELERY_TASK_ALWAYS_EAGER=True,
27+
CACHES={'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}}
28+
)
29+
class ErratumMethodTests(TestCase):
30+
"""Tests for Erratum model methods."""
31+
32+
def test_erratum_creation(self):
33+
"""Test creating an Erratum."""
34+
erratum = Erratum.objects.create(
35+
name='USN-1234-1',
36+
e_type='security',
37+
synopsis='Security update',
38+
issue_date=timezone.now(),
39+
)
40+
self.assertEqual(erratum.name, 'USN-1234-1')
41+
42+
def test_erratum_str(self):
43+
"""Test Erratum __str__ method."""
44+
erratum = Erratum.objects.create(
45+
name='USN-1234-1',
46+
e_type='security',
47+
synopsis='Security update',
48+
issue_date=timezone.now(),
49+
)
50+
self.assertIn('USN-1234-1', str(erratum))
51+
52+
def test_erratum_get_absolute_url(self):
53+
"""Test Erratum.get_absolute_url()."""
54+
erratum = Erratum.objects.create(
55+
name='USN-1234-1',
56+
e_type='security',
57+
synopsis='Security update',
58+
issue_date=timezone.now(),
59+
)
60+
url = erratum.get_absolute_url()
61+
self.assertIn(erratum.name, url)
62+
63+
def test_erratum_unique_name(self):
64+
"""Test Erratum name is unique."""
65+
Erratum.objects.create(
66+
name='USN-1234-1',
67+
e_type='security',
68+
synopsis='Security update',
69+
issue_date=timezone.now(),
70+
)
71+
from django.db import IntegrityError
72+
with self.assertRaises(IntegrityError):
73+
Erratum.objects.create(
74+
name='USN-1234-1',
75+
e_type='bugfix',
76+
synopsis='Bugfix update',
77+
issue_date=timezone.now(),
78+
)
79+
80+
def test_erratum_with_cves(self):
81+
"""Test Erratum with associated CVEs."""
82+
erratum = Erratum.objects.create(
83+
name='USN-1234-1',
84+
e_type='security',
85+
synopsis='Security update',
86+
issue_date=timezone.now(),
87+
)
88+
cve = CVE.objects.create(cve_id='CVE-2024-12345')
89+
erratum.cves.add(cve)
90+
self.assertIn(cve, erratum.cves.all())
91+
92+
def test_erratum_with_osreleases(self):
93+
"""Test Erratum with associated OS releases."""
94+
erratum = Erratum.objects.create(
95+
name='USN-1234-1',
96+
e_type='security',
97+
synopsis='Security update',
98+
issue_date=timezone.now(),
99+
)
100+
release = OSRelease.objects.create(name='Ubuntu 22.04')
101+
erratum.osreleases.add(release)
102+
self.assertIn(release, erratum.osreleases.all())
103+
104+
def test_security_erratum(self):
105+
"""Test creating a security erratum."""
106+
erratum = Erratum.objects.create(
107+
name='RHSA-2024:1234',
108+
e_type='security',
109+
synopsis='Important security update',
110+
issue_date=timezone.now(),
111+
)
112+
self.assertEqual(erratum.e_type, 'security')
113+
114+
def test_bugfix_erratum(self):
115+
"""Test creating a bugfix erratum."""
116+
erratum = Erratum.objects.create(
117+
name='RHBA-2024:1234',
118+
e_type='bugfix',
119+
synopsis='Bug fix update',
120+
issue_date=timezone.now(),
121+
)
122+
self.assertEqual(erratum.e_type, 'bugfix')

0 commit comments

Comments
 (0)