django-dynamic-fixture


Namedjango-dynamic-fixture JSON
Version 4.0.1 PyPI version JSON
download
home_pagehttps://github.com/paulocheque/django-dynamic-fixture
SummaryA full library to create dynamic model instances for testing purposes.
upload_time2023-09-15 22:37:50
maintainer
docs_urlNone
authorpaulocheque
requires_python
licenseMIT
keywords python django testing fixture
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            Django Dynamic Fixture
======================

[![Docs Status](https://readthedocs.org/projects/django-dynamic-fixture/badge/?version=latest)](http://django-dynamic-fixture.readthedocs.org/en/latest/index.html)
[![PyPI version](https://badge.fury.io/py/django-dynamic-fixture.svg)](https://badge.fury.io/py/django-dynamic-fixture)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/django-dynamic-fixture)
![PyPI - Downloads](https://img.shields.io/pypi/dm/django-dynamic-fixture)

**Latest version: 4.0.1 (Sep 2023)**

Django Dynamic Fixture (DDF) is a complete and simple library to create dynamic model instances for testing purposes.

It lets you focus on your tests, instead of focusing on generating some dummy data which is boring and polutes the test source code.

* [Basic Examples](#basic-examples)
* [Cheat Sheet](#cheat-sheet)
* <a href="http://django-dynamic-fixture.readthedocs.org/en/latest/index.html" target="_blank">Full Documentation</a>


Basic Examples
--------------

> Customize only the important details of the test:

```python
    from ddf import G
    from my_library import Author, Book

    def test_search_book_by_author():
        author1 = G(Author)
        author2 = G(Author)
        book1 = G(Book, authors=[author1])
        book2 = G(Book, authors=[author2])
        books = Book.objects.search_by_author(author1.name)
        assert book1 in books
        assert book2 not in books
```

> Using some goodies to keep the test code smaller:

```python
    from ddf import G

    def test_search_book_by_author():
        author1, author2 = G('my_library.Author', n=2)
        book1 = G('my_library.Book', authors=[author1])
        book2 = G('my_library.Book', authors=[author2])
        books = Book.objects.search_by_author(author1.name)
        assert book1 in books
        assert book2 not in books
```

> Configuring data from relationship fields:

```python
    from ddf import G

    def test_search_book_by_author():
        book1 = G(Book, main_author__name='Eistein')
        book2 = G(Book)
        books = Book.objects.search_by_author(book1.main_author.name)
        assert book1 in books
        assert book2 not in books
        assert book1.main_author.name == 'Eistein'
```

Cheat Sheet
--------------

```python
# Import the main DDF features
from ddf import N, G, F, M, C, P, teach # meaning: New, Get, ForeignKey, Mask, Copier, Print, teach
```

```python
# `N` creates an instance of model without saving it to DB
instance = N(Book)
```

```python
# `G` creates an instance of model and save it into the DB
instance = G(Book)
```

```python
# `F` customize relationship objects
instance = G(Book, author=F(name='Eistein'))
# Same as `F`
instance = G(Book, author__name='Eistein')
```

```python
# `M` receives a data mask and create a random string using it
# Known symbols: `_`, `#` or `-`
# To escape known symbols: `!`
instance = N(Book, address=M('Street ___, ### !- --'))
assert instance.address == 'Street TPA, 632 - BR'
```

```python
# `C` copies data from one field to another
instance = N(Book, address_formatted=C('address'), address=M('Street ___, ### \- --'))
assert instance.address_formatted == 'Street TPA, 632 - BR'
```

```python
# `teach` teaches DDF in how to build an instance
teach(Book, address=M('Street ___, ### !- --'))
instance = G(Book)
assert instance.address == 'Street TPA, 632 - BR'
```

```python
# `P` print instance values for debugging
P(instance)
```

```python
import ddf
ddf.__version__
```

```python
from ddf import ddf_check_models
succeeded, errors = ddf_check_models()
succeeded, errors = ddf_check_models(print_csv=True)
succeeded, errors = ddf_check_models(csv_filename='ddf_compatibility_report.csv')
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/paulocheque/django-dynamic-fixture",
    "name": "django-dynamic-fixture",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "python django testing fixture",
    "author": "paulocheque",
    "author_email": "paulocheque@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/47/62/d7ca06aece37b7c651b7ffe1aff15e89dfc18653e266af203c5ae9d5212b/django-dynamic-fixture-4.0.1.tar.gz",
    "platform": null,
    "description": "Django Dynamic Fixture\n======================\n\n[![Docs Status](https://readthedocs.org/projects/django-dynamic-fixture/badge/?version=latest)](http://django-dynamic-fixture.readthedocs.org/en/latest/index.html)\n[![PyPI version](https://badge.fury.io/py/django-dynamic-fixture.svg)](https://badge.fury.io/py/django-dynamic-fixture)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/django-dynamic-fixture)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/django-dynamic-fixture)\n\n**Latest version: 4.0.1 (Sep 2023)**\n\nDjango Dynamic Fixture (DDF) is a complete and simple library to create dynamic model instances for testing purposes.\n\nIt lets you focus on your tests, instead of focusing on generating some dummy data which is boring and polutes the test source code.\n\n* [Basic Examples](#basic-examples)\n* [Cheat Sheet](#cheat-sheet)\n* <a href=\"http://django-dynamic-fixture.readthedocs.org/en/latest/index.html\" target=\"_blank\">Full Documentation</a>\n\n\nBasic Examples\n--------------\n\n> Customize only the important details of the test:\n\n```python\n    from ddf import G\n    from my_library import Author, Book\n\n    def test_search_book_by_author():\n        author1 = G(Author)\n        author2 = G(Author)\n        book1 = G(Book, authors=[author1])\n        book2 = G(Book, authors=[author2])\n        books = Book.objects.search_by_author(author1.name)\n        assert book1 in books\n        assert book2 not in books\n```\n\n> Using some goodies to keep the test code smaller:\n\n```python\n    from ddf import G\n\n    def test_search_book_by_author():\n        author1, author2 = G('my_library.Author', n=2)\n        book1 = G('my_library.Book', authors=[author1])\n        book2 = G('my_library.Book', authors=[author2])\n        books = Book.objects.search_by_author(author1.name)\n        assert book1 in books\n        assert book2 not in books\n```\n\n> Configuring data from relationship fields:\n\n```python\n    from ddf import G\n\n    def test_search_book_by_author():\n        book1 = G(Book, main_author__name='Eistein')\n        book2 = G(Book)\n        books = Book.objects.search_by_author(book1.main_author.name)\n        assert book1 in books\n        assert book2 not in books\n        assert book1.main_author.name == 'Eistein'\n```\n\nCheat Sheet\n--------------\n\n```python\n# Import the main DDF features\nfrom ddf import N, G, F, M, C, P, teach # meaning: New, Get, ForeignKey, Mask, Copier, Print, teach\n```\n\n```python\n# `N` creates an instance of model without saving it to DB\ninstance = N(Book)\n```\n\n```python\n# `G` creates an instance of model and save it into the DB\ninstance = G(Book)\n```\n\n```python\n# `F` customize relationship objects\ninstance = G(Book, author=F(name='Eistein'))\n# Same as `F`\ninstance = G(Book, author__name='Eistein')\n```\n\n```python\n# `M` receives a data mask and create a random string using it\n# Known symbols: `_`, `#` or `-`\n# To escape known symbols: `!`\ninstance = N(Book, address=M('Street ___, ### !- --'))\nassert instance.address == 'Street TPA, 632 - BR'\n```\n\n```python\n# `C` copies data from one field to another\ninstance = N(Book, address_formatted=C('address'), address=M('Street ___, ### \\- --'))\nassert instance.address_formatted == 'Street TPA, 632 - BR'\n```\n\n```python\n# `teach` teaches DDF in how to build an instance\nteach(Book, address=M('Street ___, ### !- --'))\ninstance = G(Book)\nassert instance.address == 'Street TPA, 632 - BR'\n```\n\n```python\n# `P` print instance values for debugging\nP(instance)\n```\n\n```python\nimport ddf\nddf.__version__\n```\n\n```python\nfrom ddf import ddf_check_models\nsucceeded, errors = ddf_check_models()\nsucceeded, errors = ddf_check_models(print_csv=True)\nsucceeded, errors = ddf_check_models(csv_filename='ddf_compatibility_report.csv')\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A full library to create dynamic model instances for testing purposes.",
    "version": "4.0.1",
    "project_urls": {
        "Homepage": "https://github.com/paulocheque/django-dynamic-fixture"
    },
    "split_keywords": [
        "python",
        "django",
        "testing",
        "fixture"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5fcaf77782903f93a4ba42204dce89682c5de734d88002cefa6071f805697620",
                "md5": "b2b4fb16bb4a78827c1fab81ad7c38e9",
                "sha256": "d0611b6dc594fb1bccad1fd94dade89cc8deca12385bc2763baded3e48322547"
            },
            "downloads": -1,
            "filename": "django_dynamic_fixture-4.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b2b4fb16bb4a78827c1fab81ad7c38e9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 58712,
            "upload_time": "2023-09-15T22:37:47",
            "upload_time_iso_8601": "2023-09-15T22:37:47.956845Z",
            "url": "https://files.pythonhosted.org/packages/5f/ca/f77782903f93a4ba42204dce89682c5de734d88002cefa6071f805697620/django_dynamic_fixture-4.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4762d7ca06aece37b7c651b7ffe1aff15e89dfc18653e266af203c5ae9d5212b",
                "md5": "1de4946b647f4a98da8bed66cbbee33d",
                "sha256": "2a2197578b7702db8f5eed9ad704f6be33bac8bf0111c7c92f6063c2a4d02933"
            },
            "downloads": -1,
            "filename": "django-dynamic-fixture-4.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "1de4946b647f4a98da8bed66cbbee33d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 44278,
            "upload_time": "2023-09-15T22:37:50",
            "upload_time_iso_8601": "2023-09-15T22:37:50.084899Z",
            "url": "https://files.pythonhosted.org/packages/47/62/d7ca06aece37b7c651b7ffe1aff15e89dfc18653e266af203c5ae9d5212b/django-dynamic-fixture-4.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-15 22:37:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "paulocheque",
    "github_project": "django-dynamic-fixture",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [],
    "tox": true,
    "lcname": "django-dynamic-fixture"
}
        
Elapsed time: 0.12204s