Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions arch/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Copyright 2025 Marcus Furlong <furlongm@gmail.com>
#
# This file is part of Patchman.
#
# Patchman is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 only.
#
# Patchman is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Patchman. If not, see <http://www.gnu.org/licenses/>

from django.test import TestCase, override_settings

from arch.models import MachineArchitecture, PackageArchitecture


@override_settings(
CELERY_TASK_ALWAYS_EAGER=True,
CACHES={'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}}
)
class MachineArchitectureMethodTests(TestCase):
"""Tests for MachineArchitecture model methods."""

def test_machine_arch_creation(self):
"""Test creating a MachineArchitecture."""
arch = MachineArchitecture.objects.create(name='x86_64')
self.assertEqual(arch.name, 'x86_64')

def test_machine_arch_str(self):
"""Test MachineArchitecture __str__ method."""
arch = MachineArchitecture.objects.create(name='x86_64')
self.assertEqual(str(arch), 'x86_64')

def test_machine_arch_unique_name(self):
"""Test MachineArchitecture name is unique."""
MachineArchitecture.objects.create(name='x86_64')
from django.db import IntegrityError
with self.assertRaises(IntegrityError):
MachineArchitecture.objects.create(name='x86_64')

def test_common_machine_architectures(self):
"""Test common machine architecture values."""
archs = ['x86_64', 'aarch64', 'i686', 'armv7l', 'ppc64le']
for name in archs:
arch = MachineArchitecture.objects.create(name=name)
self.assertEqual(str(arch), name)


@override_settings(
CELERY_TASK_ALWAYS_EAGER=True,
CACHES={'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}}
)
class PackageArchitectureMethodTests(TestCase):
"""Tests for PackageArchitecture model methods."""

def test_package_arch_creation(self):
"""Test creating a PackageArchitecture."""
arch = PackageArchitecture.objects.create(name='amd64')
self.assertEqual(arch.name, 'amd64')

def test_package_arch_str(self):
"""Test PackageArchitecture __str__ method."""
arch = PackageArchitecture.objects.create(name='amd64')
self.assertEqual(str(arch), 'amd64')

def test_package_arch_unique_name(self):
"""Test PackageArchitecture name is unique."""
PackageArchitecture.objects.create(name='amd64')
from django.db import IntegrityError
with self.assertRaises(IntegrityError):
PackageArchitecture.objects.create(name='amd64')

def test_common_package_architectures(self):
"""Test common package architecture values."""
archs = ['amd64', 'i386', 'all', 'noarch', 'x86_64', 'arm64']
for name in archs:
arch = PackageArchitecture.objects.create(name=name)
self.assertEqual(str(arch), name)
52 changes: 52 additions & 0 deletions domains/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2025 Marcus Furlong <furlongm@gmail.com>
#
# This file is part of Patchman.
#
# Patchman is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 only.
#
# Patchman is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Patchman. If not, see <http://www.gnu.org/licenses/>

from django.test import TestCase, override_settings

from domains.models import Domain


@override_settings(
CELERY_TASK_ALWAYS_EAGER=True,
CACHES={'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}}
)
class DomainMethodTests(TestCase):
"""Tests for Domain model methods."""

def test_domain_creation(self):
"""Test creating a Domain."""
domain = Domain.objects.create(name='example.com')
self.assertEqual(domain.name, 'example.com')

def test_domain_str(self):
"""Test Domain __str__ method."""
domain = Domain.objects.create(name='example.com')
self.assertEqual(str(domain), 'example.com')

def test_domain_unique_name(self):
"""Test Domain name is unique."""
Domain.objects.create(name='example.com')
from django.db import IntegrityError
with self.assertRaises(IntegrityError):
Domain.objects.create(name='example.com')

def test_domain_extract_from_fqdn(self):
"""Test extracting domain from FQDN via Host creation."""
# Domains are typically extracted when hosts are created
# Test the domain itself can be created with subdomain parts
Domain.objects.create(name='subdomain.example.com')
domain = Domain.objects.get(name='subdomain.example.com')
self.assertEqual(domain.name, 'subdomain.example.com')
74 changes: 74 additions & 0 deletions errata/tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Copyright 2025 Marcus Furlong <furlongm@gmail.com>
#
# This file is part of Patchman.
#
# Patchman is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 only.
#
# Patchman is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Patchman. If not, see <http://www.gnu.org/licenses/>

from django.test import TestCase, override_settings

from errata.models import Erratum
from operatingsystems.models import OSRelease
from security.models import CVE


@override_settings(
CELERY_TASK_ALWAYS_EAGER=True,
CACHES={'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}}
)
class ErrataIntegrationTests(TestCase):
"""Integration tests for errata functionality."""

def test_erratum_with_cves(self):
"""Test erratum can be associated with CVEs."""
cve1 = CVE.objects.create(cve_id='CVE-2024-1001')
cve2 = CVE.objects.create(cve_id='CVE-2024-1002')

erratum = Erratum.objects.create(
name='RHSA-2024:1234',
e_type='Security Advisory',
synopsis='Important: curl security update',
issue_date='2024-03-15',
)
erratum.cves.add(cve1, cve2)

self.assertEqual(erratum.cves.count(), 2)
self.assertIn(cve1, erratum.cves.all())
self.assertIn(cve2, erratum.cves.all())

def test_erratum_with_osreleases(self):
"""Test erratum can be associated with OS releases."""
osrelease1 = OSRelease.objects.create(name='Rocky Linux 9')
osrelease2 = OSRelease.objects.create(name='Rocky Linux 8')

erratum = Erratum.objects.create(
name='RHSA-2024:1235',
e_type='Security Advisory',
synopsis='Important: openssl security update',
issue_date='2024-03-16',
)
erratum.osreleases.add(osrelease1, osrelease2)

self.assertEqual(erratum.osreleases.count(), 2)

def test_erratum_with_packages(self):
"""Test erratum can reference package names."""
erratum = Erratum.objects.create(
name='RHSA-2024:1236',
e_type='Bug Fix',
synopsis='Bug fix: httpd update',
issue_date='2024-03-17',
)

# Verify erratum can store package references
self.assertIsNotNone(erratum)
self.assertEqual(erratum.e_type, 'Bug Fix')
122 changes: 122 additions & 0 deletions errata/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Copyright 2025 Marcus Furlong <furlongm@gmail.com>
#
# This file is part of Patchman.
#
# Patchman is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 only.
#
# Patchman is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Patchman. If not, see <http://www.gnu.org/licenses/>

from django.test import TestCase, override_settings
from django.utils import timezone

from errata.models import Erratum
from operatingsystems.models import OSRelease
from security.models import CVE


@override_settings(
CELERY_TASK_ALWAYS_EAGER=True,
CACHES={'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}}
)
class ErratumMethodTests(TestCase):
"""Tests for Erratum model methods."""

def test_erratum_creation(self):
"""Test creating an Erratum."""
erratum = Erratum.objects.create(
name='USN-1234-1',
e_type='security',
synopsis='Security update',
issue_date=timezone.now(),
)
self.assertEqual(erratum.name, 'USN-1234-1')

def test_erratum_str(self):
"""Test Erratum __str__ method."""
erratum = Erratum.objects.create(
name='USN-1234-1',
e_type='security',
synopsis='Security update',
issue_date=timezone.now(),
)
self.assertIn('USN-1234-1', str(erratum))

def test_erratum_get_absolute_url(self):
"""Test Erratum.get_absolute_url()."""
erratum = Erratum.objects.create(
name='USN-1234-1',
e_type='security',
synopsis='Security update',
issue_date=timezone.now(),
)
url = erratum.get_absolute_url()
self.assertIn(erratum.name, url)

def test_erratum_unique_name(self):
"""Test Erratum name is unique."""
Erratum.objects.create(
name='USN-1234-1',
e_type='security',
synopsis='Security update',
issue_date=timezone.now(),
)
from django.db import IntegrityError
with self.assertRaises(IntegrityError):
Erratum.objects.create(
name='USN-1234-1',
e_type='bugfix',
synopsis='Bugfix update',
issue_date=timezone.now(),
)

def test_erratum_with_cves(self):
"""Test Erratum with associated CVEs."""
erratum = Erratum.objects.create(
name='USN-1234-1',
e_type='security',
synopsis='Security update',
issue_date=timezone.now(),
)
cve = CVE.objects.create(cve_id='CVE-2024-12345')
erratum.cves.add(cve)
self.assertIn(cve, erratum.cves.all())

def test_erratum_with_osreleases(self):
"""Test Erratum with associated OS releases."""
erratum = Erratum.objects.create(
name='USN-1234-1',
e_type='security',
synopsis='Security update',
issue_date=timezone.now(),
)
release = OSRelease.objects.create(name='Ubuntu 22.04')
erratum.osreleases.add(release)
self.assertIn(release, erratum.osreleases.all())

def test_security_erratum(self):
"""Test creating a security erratum."""
erratum = Erratum.objects.create(
name='RHSA-2024:1234',
e_type='security',
synopsis='Important security update',
issue_date=timezone.now(),
)
self.assertEqual(erratum.e_type, 'security')

def test_bugfix_erratum(self):
"""Test creating a bugfix erratum."""
erratum = Erratum.objects.create(
name='RHBA-2024:1234',
e_type='bugfix',
synopsis='Bug fix update',
issue_date=timezone.now(),
)
self.assertEqual(erratum.e_type, 'bugfix')
Loading
Loading