django-admin-smoke


Namedjango-admin-smoke JSON
Version 0.5.0 PyPI version JSON
download
home_pageNone
SummarySmoke tests library for Django Admin
upload_time2024-03-26 11:22:46
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseMIT
keywords django admin smoke tests
VCS
bugtrack_url
requirements dj-inmemorystorage Django django-testing-utils
Travis-CI No Travis.
coveralls test coverage No coveralls.
            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/3c/ef/ba1e21d647988b90991986206950799f7441115c3a19c6442589a7537c97/django-admin-smoke-0.5.0.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.0",
    "project_urls": {
        "homepage": "https://github.com/just-work/django-admin-smoke"
    },
    "split_keywords": [
        "django",
        " admin",
        " smoke",
        " tests"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bf9ece880c9e0b75f9bed5b1dacb2e5ba984868cf83c216fe0c919e32e39c7af",
                "md5": "9c47c780ec1a77b3edbaf82c46ca1dae",
                "sha256": "53b59591b93c7587f1fb86f31aadf37e4011820e9a54c31354579192f60554bb"
            },
            "downloads": -1,
            "filename": "django_admin_smoke-0.5.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9c47c780ec1a77b3edbaf82c46ca1dae",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 7412,
            "upload_time": "2024-03-26T11:22:45",
            "upload_time_iso_8601": "2024-03-26T11:22:45.504045Z",
            "url": "https://files.pythonhosted.org/packages/bf/9e/ce880c9e0b75f9bed5b1dacb2e5ba984868cf83c216fe0c919e32e39c7af/django_admin_smoke-0.5.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3cefba1e21d647988b90991986206950799f7441115c3a19c6442589a7537c97",
                "md5": "92515539d4c8055114d6c3dfe0f81011",
                "sha256": "a3638fd0a06a8e31e4df0a1a48a086bf6a72ba410d7c63ccebc7590c78e910ef"
            },
            "downloads": -1,
            "filename": "django-admin-smoke-0.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "92515539d4c8055114d6c3dfe0f81011",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8166,
            "upload_time": "2024-03-26T11:22:46",
            "upload_time_iso_8601": "2024-03-26T11:22:46.534269Z",
            "url": "https://files.pythonhosted.org/packages/3c/ef/ba1e21d647988b90991986206950799f7441115c3a19c6442589a7537c97/django-admin-smoke-0.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-26 11:22:46",
    "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"
}
        
Elapsed time: 0.21327s