Smoke tests library for Django Admin
Project description
Django-admin-smoke
Django-Admin-Smoke is a Django app providing smoke tests for django-admin.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django_admin_smoke-0.5.1.tar.gz
.
File metadata
- Download URL: django_admin_smoke-0.5.1.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b10476507e572d1ead6edd3f7a7c46e32eb16489233dd6c9588ef68f242912a8 |
|
MD5 | c171b4413c05ead414388fec4621ef07 |
|
BLAKE2b-256 | e46134ca7360cec62311de611ad76c063e8a312bfc68031ff32cfb1b8b12beac |
File details
Details for the file django_admin_smoke-0.5.1-py3-none-any.whl
.
File metadata
- Download URL: django_admin_smoke-0.5.1-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e54079a217c579f1c0dc0f6a95f84e24ec0f2e7e410a97b33c073bc3ac8f009 |
|
MD5 | 1e69be87ce01c997580c0272a87c77a8 |
|
BLAKE2b-256 | e2a893dc4e2eefdcb8585e20009499abb345e6978f4e264750be11bdd52fded1 |