Skip to main content

Smoke tests for Django admin

Project description

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 :)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-admin-smoke-0.1.1.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_admin_smoke-0.1.1-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file django-admin-smoke-0.1.1.tar.gz.

File metadata

  • Download URL: django-admin-smoke-0.1.1.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for django-admin-smoke-0.1.1.tar.gz
Algorithm Hash digest
SHA256 358b39daf1157ef6a7864e819ed442cf5a83c5df923b73b761fdabe7c6efe7a2
MD5 304522a1e0a5bf1b30b12e2f9a6238c4
BLAKE2b-256 0cee2d75889ee298d3ce093e5e05c88d4153852aef92855fd219d279517b3ead

See more details on using hashes here.

File details

Details for the file django_admin_smoke-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: django_admin_smoke-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for django_admin_smoke-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0b2b1d29005002aa7016f3dea3421d2038090e76c4f719ac7dbca035ab87bc22
MD5 464d0612d24fa02abac57037d77f1c7b
BLAKE2b-256 6d3f8b496583884538663448749b934267d7709eeb2fb15a17a661c49b7cbb94

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page