{ "info": { "author": "Simon Charette.", "author_email": "charette.s+testdata@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Web Environment", "Framework :: Django", "Framework :: Django :: 1.11", "Framework :: Django :: 2.0", "Framework :: Django :: 2.1", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Libraries :: Application Frameworks", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "django-testdata\n===============\n\n.. image:: https://img.shields.io/pypi/l/django-testdata.svg?style=flat\n :target: https://pypi.python.org/pypi/django-testdata/\n :alt: License\n\n.. image:: https://img.shields.io/pypi/v/django-testdata.svg?style=flat\n :target: https://pypi.python.org/pypi/django-testdata/\n :alt: Latest Version\n\n.. image:: https://travis-ci.org/charettes/django-testdata.svg?branch=master\n :target: https://travis-ci.org/charettes/django-testdata\n :alt: Build Status\n\n.. image:: https://coveralls.io/repos/charettes/django-testdata/badge.svg?branch=master\n :target: https://coveralls.io/r/charettes/django-testdata?branch=master\n :alt: Coverage Status\n\n.. image:: https://img.shields.io/pypi/pyversions/django-testdata.svg?style=flat\n :target: https://pypi.python.org/pypi/django-testdata/\n :alt: Supported Python Versions\n\n.. image:: https://img.shields.io/pypi/wheel/django-testdata.svg?style=flat\n :target: https://pypi.python.org/pypi/django-testdata/\n :alt: Wheel Status\n\nDjango application providing isolation for model instances created during\n`setUpTestData`.\n\nInstallation\n------------\n\n.. code:: sh\n\n pip install django-testdata\n\nMotivation\n----------\n\nDjango 1.8 introduced ``TestCase.setUpTestData`` to allow costly generation of\nmodel fixtures to be executed only once per test class in order to speed up\ntestcase instances execution.\n\nOne gotcha of ``setUpTestData`` though is that test instances all share the same\nmodel instances and have to be careful not to alter them to prevent breaking\ntest isolation. Per Django's `documentation`_::\n\n Be careful not to modify any objects created in setUpTestData() in your\n test methods. Modifications to in-memory objects from setup work done at\n the class level will persist between test methods. If you do need to modify\n them, you could reload them in the setUp() method with refresh_from_db(),\n for example.\n\nReloading objects in ``setUp()`` certainly works but it kind of defeats the\npurpose of avoiding database hits to speed up tests execution in the first\nplace. It makes little sense to fetch model instances from the database\ngiven all \n\nThis package offers a different alternative to work around this quirk of\n``setUpTestData``. Instead of reloading objects from the database the model\ninstances assigned as class attributes during ``setUpTestData`` are lazily deep\ncopied on testcase instance accesses from their original definition. All of\ndeep copying is done by sharing a `memo`_ which makes sure in-memory relationships\nbetween objects is preserved.\n\n.. _documentation: https://docs.djangoproject.com/en/2.1/topics/testing/tools/#django.test.TestCase.setUpTestData\n.. _memo: https://docs.python.org/3/library/copy.html?highlight=memo#copy.deepcopy\n\nUsage\n-----\n\nThe test data can be either wrapped manually by using ``testdata``.\n\n.. code:: python\n\n from django.test import TestCase\n from testdata import testdata\n\n from .models import Author, Book\n\n class BookTests(TestCase):\n @classmethod\n def setUpTestData(cls):\n cls.author = testdata(Author.objects.create(\n name='Milan Kundera',\n ))\n cls.book = testdata(cls.author.books.create(\n title='Nesnesiteln\u00e1 lehkost byt\u00ed',\n ))\n\nOr automatically by using the ``wrap_testdata`` decorator.\n\n.. code:: python\n\n from django.test import TestCase\n from testdata import testdata\n\n from .models import Author, Book\n\n class BookTests(TestCase):\n @classmethod\n @wrap_testdata\n def setUpTestData(cls):\n cls.author = Author.objects.create(\n name='Milan Kundera',\n )\n cls.book = cls.author.books.create(\n title='Nesnesiteln\u00e1 lehkost byt\u00ed',\n )\n\nUnder the hood ``wrap_testdata`` simply wraps all attributes added to `cls`\nduring the execution of ``setUpTestData()`` into ``testdata(attr, name=name)``\nwhich has also the nice side effect of speeding subsequent accesses.\n\nOnce test data is wrapped the testcase instances methods can alter objects\nretrieved from ``self`` without worrying about cross-tests isolation.\n\n.. code:: python\n\n from django.test import TestCase\n from testdata import testdata\n\n from .models import Author, Book\n\n class BookTests(TestCase):\n @classmethod\n @wrap_testdata\n def setUpTestData(cls):\n cls.author = Author.objects.create(\n name='Milan Kundera',\n )\n cls.book = cls.author.books.create(\n title='Nesnesiteln\u00e1 lehkost byt\u00ed',\n )\n\n def test_book_name_english(self):\n self.assertEqual(self.book.title, 'Nesnesiteln\u00e1 lehkost byt\u00ed')\n self.book.title = 'The Unbearable Lightness of Being'\n self.book.save()\n\n def test_book_name_french(self):\n self.assertEqual(self.book.title, 'Nesnesiteln\u00e1 lehkost byt\u00ed')\n self.book.title = \"L'Insoutenable L\u00e9g\u00e8ret\u00e9 de l'\u00eatre\"\n self.book.save()\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/charettes/django-testdata", "keywords": "django test testdata", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "django-testdata", "package_url": "https://pypi.org/project/django-testdata/", "platform": "", "project_url": "https://pypi.org/project/django-testdata/", "project_urls": { "Homepage": "https://github.com/charettes/django-testdata" }, "release_url": "https://pypi.org/project/django-testdata/1.0.1/", "requires_dist": [ "Django (>=1.11)", "tox; extra == 'tests'" ], "requires_python": "", "summary": "Django application providing isolation for model instances created during `setUpTestData`.", "version": "1.0.1" }, "last_serial": 4517996, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "d1af6e6589de27b5e4d72bf81c9f10bd", "sha256": "39b12ee58f783366f7de651488c7d5785ccb83004bb5de85bb9a72dccb3e86b3" }, "downloads": -1, "filename": "django_testdata-1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "d1af6e6589de27b5e4d72bf81c9f10bd", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 5251, "upload_time": "2018-11-22T10:23:15", "url": "https://files.pythonhosted.org/packages/ed/12/4244af89849eeff81df82ed864342593c9ebbae13cbbd649b8a0b66d1bc4/django_testdata-1.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "cfa53ace79165f91f0dd825c732573be", "sha256": "112cb2a27ac03f3a3ca5664f3cd5baba4d9fdc6920ba5cc99430f6c4f02aab86" }, "downloads": -1, "filename": "django-testdata-1.0.tar.gz", "has_sig": false, "md5_digest": "cfa53ace79165f91f0dd825c732573be", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4957, "upload_time": "2018-11-22T10:23:18", "url": "https://files.pythonhosted.org/packages/70/52/7eb60e441a8a0d356baa0abd02c3b680fe34c4ea3f142209842cce8537ca/django-testdata-1.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "68d48ef70a0bbf34fd67dfb2fba295d3", "sha256": "7b72b7d7d9b7dcdd27e48fedf80de748b0b0fe1b4e37ad7a6da57bc4746685d6" }, "downloads": -1, "filename": "django_testdata-1.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "68d48ef70a0bbf34fd67dfb2fba295d3", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 5370, "upload_time": "2018-11-22T18:15:03", "url": "https://files.pythonhosted.org/packages/9e/4e/9fc91762a5c2a5eac060705d4b8f84db69bafb6afcc778200cc4977c79f0/django_testdata-1.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "1cfab4a4df947917f27a10eddadad5ac", "sha256": "db134f2b0ecdbbc667a9a781fbf8bbcc3538c16d4fd7722362ae976c272579a6" }, "downloads": -1, "filename": "django-testdata-1.0.1.tar.gz", "has_sig": false, "md5_digest": "1cfab4a4df947917f27a10eddadad5ac", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5054, "upload_time": "2018-11-22T18:17:16", "url": "https://files.pythonhosted.org/packages/eb/e8/04289f751c0930d47a576dae4aa707d398112290ed3e8354b3da0dc78b0f/django-testdata-1.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "68d48ef70a0bbf34fd67dfb2fba295d3", "sha256": "7b72b7d7d9b7dcdd27e48fedf80de748b0b0fe1b4e37ad7a6da57bc4746685d6" }, "downloads": -1, "filename": "django_testdata-1.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "68d48ef70a0bbf34fd67dfb2fba295d3", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 5370, "upload_time": "2018-11-22T18:15:03", "url": "https://files.pythonhosted.org/packages/9e/4e/9fc91762a5c2a5eac060705d4b8f84db69bafb6afcc778200cc4977c79f0/django_testdata-1.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "1cfab4a4df947917f27a10eddadad5ac", "sha256": "db134f2b0ecdbbc667a9a781fbf8bbcc3538c16d4fd7722362ae976c272579a6" }, "downloads": -1, "filename": "django-testdata-1.0.1.tar.gz", "has_sig": false, "md5_digest": "1cfab4a4df947917f27a10eddadad5ac", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5054, "upload_time": "2018-11-22T18:17:16", "url": "https://files.pythonhosted.org/packages/eb/e8/04289f751c0930d47a576dae4aa707d398112290ed3e8354b3da0dc78b0f/django-testdata-1.0.1.tar.gz" } ] }