Django-admin-smoke
==================
Django-Admin-Smoke is a Django app providing smoke tests for django-admin.
![build](https://github.com/just-work/django-admin-smoke/workflows/build/badge.svg?branch=master)
[![codecov](https://codecov.io/gh/just-work/django-admin-smoke/branch/master/graph/badge.svg)](https://codecov.io/gh/just-work/django-admin-smoke)
[![PyPI version](https://badge.fury.io/py/django-admin-smoke.svg)](https://badge.fury.io/py/django-admin-smoke)
Installation
------------
```shell script
pip install django-admin-smoke
```
Usage
-----
Full example located at `testproject.testapp.tests`
```python
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 :)
Raw data
{
"_id": null,
"home_page": null,
"name": "django-admin-smoke",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "django, admin, smoke, tests",
"author": null,
"author_email": "Sergey Tikhonov <zimbler@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/e4/61/34ca7360cec62311de611ad76c063e8a312bfc68031ff32cfb1b8b12beac/django_admin_smoke-0.5.1.tar.gz",
"platform": null,
"description": "Django-admin-smoke\n==================\n\nDjango-Admin-Smoke is a Django app providing smoke tests for django-admin.\n\n![build](https://github.com/just-work/django-admin-smoke/workflows/build/badge.svg?branch=master)\n[![codecov](https://codecov.io/gh/just-work/django-admin-smoke/branch/master/graph/badge.svg)](https://codecov.io/gh/just-work/django-admin-smoke)\n[![PyPI version](https://badge.fury.io/py/django-admin-smoke.svg)](https://badge.fury.io/py/django-admin-smoke)\n\nInstallation\n------------\n\n```shell script\npip install django-admin-smoke\n```\n\nUsage\n-----\n\nFull example located at `testproject.testapp.tests`\n\n```python\n\nfrom admin_smoke.tests import AdminTests, AdminBaseTestCase\nfrom testproject.testapp import admin, models\n\n\nclass ProjectAdminTestCase(AdminTests, AdminBaseTestCase):\n model_admin = admin.ProjectAdmin # ModelAdmin to test\n model = models.Project # Django model to test against\n object_name = 'project' # self.project is an edited object in this testcase\n excluded_fields = ['client'] # fields excluded from presence check\n\n def setUp(self):\n super().setUp()\n # We need existing object to test editing and deleting\n self.project = models.Project.objects.create(name='first')\n # All inlines for tested model admin should be non-empty, so we fill\n # all related models.\n self.task = models.Task.objects.create(name='first',\n project=self.project)\n\n def transform_to_new(self, data: dict) -> dict:\n # Creating a new object is tested with following algorithm:\n # 1. Open \"edit\" page for existing object\n # 2. Clear PK value in form data\n # 3. Clear PK values for all related objects in admin inlines\n # 4. Clear FK values pointing to existing object in admin inlines\n # 5. POST resulting data to \"add\" page\n # This algorithm need some help with unique fields and other constraints\n # and restrictions, so there is a hook for making newly created object\n # valid.\n\n data = data.copy()\n # Project.name is unique, making new value\n data['name'] += 'new'\n # Manually reset PK/FK values in admin inlines\n self.reset_inline_data(\n data, # form data\n 'task_set', # name of inline prefix - it's FK's related_name \n 'project' # name of edited object FK field (FK.name)\n )\n # Task.name is also unique, it should be changed properly\n data['task_set-0-name'] += '_new'\n return data\n\n def prepare_deletion(self):\n # To delete an object with FK's with models.PROTECT behavior we need\n # a hook to delete it manually before POST delete confirmation.\n self.task.delete()\n```\n\nHappy testing and non-smoky admins :)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Smoke tests library for Django Admin",
"version": "0.5.1",
"project_urls": {
"homepage": "https://github.com/just-work/django-admin-smoke"
},
"split_keywords": [
"django",
" admin",
" smoke",
" tests"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e2a893dc4e2eefdcb8585e20009499abb345e6978f4e264750be11bdd52fded1",
"md5": "1e69be87ce01c997580c0272a87c77a8",
"sha256": "2e54079a217c579f1c0dc0f6a95f84e24ec0f2e7e410a97b33c073bc3ac8f009"
},
"downloads": -1,
"filename": "django_admin_smoke-0.5.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1e69be87ce01c997580c0272a87c77a8",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 7447,
"upload_time": "2024-09-20T16:02:56",
"upload_time_iso_8601": "2024-09-20T16:02:56.858098Z",
"url": "https://files.pythonhosted.org/packages/e2/a8/93dc4e2eefdcb8585e20009499abb345e6978f4e264750be11bdd52fded1/django_admin_smoke-0.5.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e46134ca7360cec62311de611ad76c063e8a312bfc68031ff32cfb1b8b12beac",
"md5": "c171b4413c05ead414388fec4621ef07",
"sha256": "b10476507e572d1ead6edd3f7a7c46e32eb16489233dd6c9588ef68f242912a8"
},
"downloads": -1,
"filename": "django_admin_smoke-0.5.1.tar.gz",
"has_sig": false,
"md5_digest": "c171b4413c05ead414388fec4621ef07",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 8211,
"upload_time": "2024-09-20T16:02:58",
"upload_time_iso_8601": "2024-09-20T16:02:58.169532Z",
"url": "https://files.pythonhosted.org/packages/e4/61/34ca7360cec62311de611ad76c063e8a312bfc68031ff32cfb1b8b12beac/django_admin_smoke-0.5.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-20 16:02:58",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "just-work",
"github_project": "django-admin-smoke",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "dj-inmemorystorage",
"specs": [
[
"==",
"2.1.0"
]
]
},
{
"name": "Django",
"specs": [
[
"==",
"5.0.3"
]
]
},
{
"name": "django-testing-utils",
"specs": [
[
"==",
"0.7.0"
]
]
}
],
"tox": true,
"lcname": "django-admin-smoke"
}