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
2 changes: 1 addition & 1 deletion .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
max-parallel: 5
matrix:
python-version: ['3.x']
python-version: ['3.13']
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand Down
Empty file added arch/tests/__init__.py
Empty file.
121 changes: 121 additions & 0 deletions arch/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# 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.contrib.auth.models import User
from django.test import TestCase, override_settings
from rest_framework import status
from rest_framework.test import APITestCase

from arch.models import MachineArchitecture, PackageArchitecture


@override_settings(
CELERY_TASK_ALWAYS_EAGER=True,
CACHES={'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}}
)
class ArchitectureAPITests(APITestCase):
"""Tests for the Architecture API endpoints."""

def setUp(self):
"""Set up test data."""
self.user = User.objects.create_user(
username='testuser', password='testpass'
)
self.client.force_authenticate(user=self.user)

self.machine_arch = MachineArchitecture.objects.create(name='x86_64')
self.pkg_arch = PackageArchitecture.objects.create(name='amd64')

def test_list_machine_architectures(self):
"""Test listing machine architectures."""
response = self.client.get('/api/machine-architecture/')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.data['results']), 1)

def test_retrieve_machine_architecture(self):
"""Test retrieving a machine architecture."""
response = self.client.get(f'/api/machine-architecture/{self.machine_arch.id}/')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data['name'], 'x86_64')

def test_list_package_architectures(self):
"""Test listing package architectures."""
response = self.client.get('/api/package-architecture/')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.data['results']), 1)

def test_retrieve_package_architecture(self):
"""Test retrieving a package architecture."""
response = self.client.get(f'/api/package-architecture/{self.pkg_arch.id}/')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data['name'], 'amd64')


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

def test_machine_architecture_creation(self):
"""Test creating a machine architecture."""
arch = MachineArchitecture.objects.create(name='aarch64')
self.assertEqual(arch.name, 'aarch64')

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

def test_machine_architecture_unique_name(self):
"""Test that machine architecture names must be unique."""
MachineArchitecture.objects.create(name='unique-arch')
from django.db import IntegrityError
with self.assertRaises(IntegrityError):
MachineArchitecture.objects.create(name='unique-arch')


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

def test_package_architecture_creation(self):
"""Test creating a package architecture."""
arch = PackageArchitecture.objects.create(name='arm64')
self.assertEqual(arch.name, 'arm64')

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

def test_package_architecture_unique_name(self):
"""Test that package architecture names must be unique."""
PackageArchitecture.objects.create(name='all')
from django.db import IntegrityError
with self.assertRaises(IntegrityError):
PackageArchitecture.objects.create(name='all')

def test_common_architectures(self):
"""Test creating common architecture types."""
archs = ['x86_64', 'amd64', 'i386', 'i686', 'noarch', 'all', 'arm64', 'aarch64']
for arch_name in archs:
arch = PackageArchitecture.objects.create(name=arch_name)
self.assertEqual(str(arch), arch_name)
Empty file added domains/tests/__init__.py
Empty file.
83 changes: 83 additions & 0 deletions domains/tests/test_api.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.contrib.auth.models import User
from django.test import TestCase, override_settings
from rest_framework import status
from rest_framework.test import APITestCase

from domains.models import Domain


@override_settings(
CELERY_TASK_ALWAYS_EAGER=True,
CACHES={'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}}
)
class DomainAPITests(APITestCase):
"""Tests for the Domain API endpoints."""

def setUp(self):
"""Set up test data."""
self.user = User.objects.create_user(
username='testuser', password='testpass'
)
self.client.force_authenticate(user=self.user)
self.domain = Domain.objects.create(name='example.com')

def test_list_domains(self):
"""Test listing all domains."""
response = self.client.get('/api/domain/')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.data['results']), 1)

def test_retrieve_domain(self):
"""Test retrieving a single domain."""
response = self.client.get(f'/api/domain/{self.domain.id}/')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data['name'], 'example.com')


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

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

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

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

def test_extract_domain_from_fqdn(self):
"""Test extracting domain from fully qualified domain name."""
# Domain extraction is done elsewhere, but test the model can store it
fqdn = 'server1.prod.example.com'
domain_name = '.'.join(fqdn.split('.')[1:]) # prod.example.com
domain = Domain.objects.create(name=domain_name)
self.assertEqual(domain.name, 'prod.example.com')
2 changes: 1 addition & 1 deletion errata/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
class ErratumSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Erratum
fields = ('id', 'name', 'e_type', 'issue_date', 'synopsis', 'cves', 'releases', 'references')
fields = ('id', 'name', 'e_type', 'issue_date', 'synopsis', 'cves', 'osreleases', 'references')
15 changes: 15 additions & 0 deletions errata/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 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/>
Loading
Loading