{"id":13502413,"url":"https://github.com/paulocheque/django-dynamic-fixture","last_synced_at":"2025-04-07T06:13:28.794Z","repository":{"id":2923393,"uuid":"3934109","full_name":"paulocheque/django-dynamic-fixture","owner":"paulocheque","description":"A complete library to create dynamic model instances for testing purposes.","archived":false,"fork":false,"pushed_at":"2024-10-10T11:01:49.000Z","size":608,"stargazers_count":388,"open_issues_count":9,"forks_count":67,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-03-31T05:04:26.862Z","etag":null,"topics":["database-testing","django","python","testing-tools"],"latest_commit_sha":null,"homepage":"http://django-dynamic-fixture.readthedocs.io/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/paulocheque.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["paulocheque"]}},"created_at":"2012-04-04T22:54:41.000Z","updated_at":"2025-03-17T16:08:18.000Z","dependencies_parsed_at":"2024-12-24T13:10:20.615Z","dependency_job_id":"9119723e-b332-4722-8edd-465c7496abea","html_url":"https://github.com/paulocheque/django-dynamic-fixture","commit_stats":{"total_commits":351,"total_committers":39,"mean_commits":9.0,"dds":0.3504273504273504,"last_synced_commit":"7160dd935859690d7a3083623bf2f101878496b6"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulocheque%2Fdjango-dynamic-fixture","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulocheque%2Fdjango-dynamic-fixture/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulocheque%2Fdjango-dynamic-fixture/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulocheque%2Fdjango-dynamic-fixture/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paulocheque","download_url":"https://codeload.github.com/paulocheque/django-dynamic-fixture/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247601449,"owners_count":20964864,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database-testing","django","python","testing-tools"],"created_at":"2024-07-31T22:02:13.092Z","updated_at":"2025-04-07T06:13:28.771Z","avatar_url":"https://github.com/paulocheque.png","language":"Python","funding_links":["https://github.com/sponsors/paulocheque"],"categories":["Testing","Python","测试"],"sub_categories":[],"readme":"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* [Sponsors](#sponsors)\n* \u003ca href=\"http://django-dynamic-fixture.readthedocs.org/en/latest/index.html\" target=\"_blank\"\u003eFull Documentation\u003c/a\u003e\n\n\nBasic Examples\n--------------\n\n\u003e 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\u003e 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\u003e 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\nSponsors\n--------------\n- https://github.com/thnxdev\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulocheque%2Fdjango-dynamic-fixture","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaulocheque%2Fdjango-dynamic-fixture","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulocheque%2Fdjango-dynamic-fixture/lists"}