Skip to main content

Django-admin-smoke

Django-Admin-Smoke is a Django app providing smoke tests for django-admin.

build codecov PyPI version

Installation

pip install django-admin-smoke

Usage

Full example located at testproject.testapp.tests

from admin_smoke.tests import AdminTests, AdminBaseTestCase
from testproject.testapp import admin, models


class ProjectAdminTestCase(AdminTests, AdminBaseTestCase):
    model_admin = admin.ProjectAdmin  # ModelAdmin to test
    model = models.Project  # Django model to test against
    object_name = 'project'  # self.project is an edited object in this testcase
    excluded_fields = ['client']  #  fields excluded from presence check

    def setUp(self):
        super().setUp()
        # We need existing object to test editing and deleting
        self.project = models.Project.objects.create(name='first')
        # All inlines for tested model admin should be non-empty, so we fill
        # all related models.
        self.task = models.Task.objects.create(name='first',
                                               project=self.project)

    def transform_to_new(self, data: dict) -> dict:
        # Creating a new object is tested with following algorithm:
        # 1. Open "edit" page for existing object
        # 2. Clear PK value in form data
        # 3. Clear PK values for all related objects in admin inlines
        # 4. Clear FK values pointing to existing object in admin inlines
        # 5. POST resulting data to "add" page
        # This algorithm need some help with unique fields and other constraints
        # and restrictions, so there is a hook for making newly created object
        # valid.

        data = data.copy()
        # Project.name is unique, making new value
        data['name'] += 'new'
        # Manually reset PK/FK values in admin inlines
        self.reset_inline_data(
            data,        # form data
            'task_set',  # name of inline prefix - it's FK's related_name 
            'project'    # name of edited object FK field (FK.name)
        )
        # Task.name is also unique, it should be changed properly
        data['task_set-0-name'] += '_new'
        return data

    def prepare_deletion(self):
        # To delete an object with FK's with models.PROTECT behavior we need
        # a hook to delete it manually before POST delete confirmation.
        self.task.delete()

Happy testing and non-smoky admins :)

Metadata

Release files for django-admin-smoke 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-admin-smoke 0.6.0
File Size Uploaded
django_admin_smoke-0.6.0.tar.gz 8.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-admin-smoke 0.6.0
File Interpreter ABI Platform
django_admin_smoke-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.8 kB

Release files / django_admin_smoke-0.6.0.tar.gz

Download URL django_admin_smoke-0.6.0.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
acc0e19bbfde0c0b0a4f70591a0f87afb15d02177523c1a15cdd321da057f107
BLAKE2b-256 checksum
How to use checksums
a1a1066c5d2b03a795be4a9c5806754d159298634fae416fc35626fae2964dba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / django_admin_smoke-0.6.0-py3-none-any.whl

Download URL django_admin_smoke-0.6.0-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3e1383f42a0855487e119b788cd4624b9f39fd2bca80c2f4d194aad389bc4b1a
BLAKE2b-256 checksum
How to use checksums
702f532795b50932ad144c08a655ca90973bc5966abc8074b1ad78ad98befddf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page