{ "info": { "author": "Mitchell Hashimoto", "author_email": "mitchell@kiip.me", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Software Development :: Testing" ], "description": "PyFactory\n=========\n\nPyFactory is a library for writing generic model factories useful\nfor unit testing.\n\nExample\n-------\n\nBasic Example\n~~~~~~~~~~~~~\n\nThe example below shows a very simple example. Say somewhere in our\ntests we need various instances of ``User`` objects. In our tests we\nwould simply write the following to create a user::\n\n user = UserFactory().create(\"basic\")\n\nThe PyFactory code necessary to make this happen is shown below. Note\nthat the ``ModelBuilder`` created would only have to be done once.\n\n::\n\n from pyfactory import Factory, schema\n\n import models\n\n class ModelBuilder(object):\n \"\"\"\n The model builder is responsible for knowing how to build\n and create models based on their attributes. This is what\n allows PyFactory to be completely model-agnostic.\n \"\"\"\n\n @classmethod\n def build(cls, model_cls, attrs):\n return model_cls(attributes)\n\n @classmethod\n def create(cls, model_cls, attrs):\n result = cls.build(model_cls, attrs)\n result.save()\n return result\n\n class UserFactory(Factory):\n \"\"\"\n This shows a simple factory which creates a type of User.\n \"\"\"\n\n _model = models.user.User\n _model_builder = ModelBuilder\n\n @schema()\n def basic(self):\n return {\n \"first_name\": \"Test\",\n \"last_name\": \"User\",\n }\n\nAssociations\n~~~~~~~~~~~~\n\nIn any application, models typically have associations. Let's look at\nthe case where we have a ``Post`` model which is written by a ``User``.\nIf we want a valid ``Post`` object in our tests, once again we only need\nto do the following::\n\n post = PostFactory().create(\"basic\")\n\nAnd the PyFactory factories to make this possible are equally simple::\n\n class PostFactory(Factory):\n @schema()\n def basic(self):\n return {\n \"title\": \"Fake Title\",\n \"body\": \"Lorem ipsum...\",\n \"author_id\": association(UserFactory(), \"basic\", \"id\")\n }\n\nAttribute Overrides\n~~~~~~~~~~~~~~~~~~~\n\nGiven the above examples, what if you already had a ``User`` that you\nwanted as a post author? Well, its simple to override attributes by\njust passing the override attributes as additional keyword arguments\nto the factory method::\n\n author = # Pretend we got an author somewhere\n post = PostFactory().create(\"basic\", author_id=author.id)", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://kiip.github.com/pyfactory/", "keywords": "factory,pyfactory,model", "license": "MIT License", "maintainer": null, "maintainer_email": null, "name": "pyfactory", "package_url": "https://pypi.org/project/pyfactory/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/pyfactory/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://kiip.github.com/pyfactory/" }, "release_url": "https://pypi.org/project/pyfactory/0.4.0/", "requires_dist": null, "requires_python": null, "summary": "Generic model factory framework", "version": "0.4.0" }, "last_serial": 797196, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "13f153c1155c0bbb971556951f25694c", "sha256": "44e3ff0bd9fa42562aa687752dae7b91c64fadd2bf8c768e6dc2e6ba87021059" }, "downloads": -1, "filename": "pyfactory-0.1.0.tar.gz", "has_sig": false, "md5_digest": "13f153c1155c0bbb971556951f25694c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4325, "upload_time": "2011-08-30T20:48:21", "url": "https://files.pythonhosted.org/packages/dd/5a/53e27d76d5bf709ea04ab83fec9cdfa5ac0eefdb5a96cf6c3a17fac0127f/pyfactory-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "e73b1a24d61c2993d2c76f0be5f219d2", "sha256": "f02f2193ca3eab26797d77e332160d640a3dd901dbd7acf3715d0322e797a082" }, "downloads": -1, "filename": "pyfactory-0.2.0.tar.gz", "has_sig": false, "md5_digest": "e73b1a24d61c2993d2c76f0be5f219d2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4976, "upload_time": "2011-08-31T00:53:29", "url": "https://files.pythonhosted.org/packages/d8/84/d1a7e6d9f69f56762add23c6230b1e7d424d357b6bfdf9c0ed31d0bef10f/pyfactory-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "d3ddd05c3fc2dc6afdf76c0925baf1bc", "sha256": "db2640b87bcb8d2b05ea2179a3a0841a6bbb891d2ff377ad72b45a8b3f44de7e" }, "downloads": -1, "filename": "pyfactory-0.3.0.tar.gz", "has_sig": false, "md5_digest": "d3ddd05c3fc2dc6afdf76c0925baf1bc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6025, "upload_time": "2011-08-31T20:07:57", "url": "https://files.pythonhosted.org/packages/4b/b3/84959df0edccd70cff197b401468cdcfae0eefedd1dce213351458a1308b/pyfactory-0.3.0.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "c73f46dc83d5dda1592f3d322b65e202", "sha256": "3138d19ef47ad0b198b167fde132b9fdcd4816539e598bfae1a7ba5961389736" }, "downloads": -1, "filename": "pyfactory-0.4.0.tar.gz", "has_sig": false, "md5_digest": "c73f46dc83d5dda1592f3d322b65e202", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6078, "upload_time": "2011-08-31T23:33:07", "url": "https://files.pythonhosted.org/packages/22/b6/2c745779a0625b8e2626fff0b1c9493dd793cab030ecc01e7ce27a256020/pyfactory-0.4.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "c73f46dc83d5dda1592f3d322b65e202", "sha256": "3138d19ef47ad0b198b167fde132b9fdcd4816539e598bfae1a7ba5961389736" }, "downloads": -1, "filename": "pyfactory-0.4.0.tar.gz", "has_sig": false, "md5_digest": "c73f46dc83d5dda1592f3d322b65e202", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6078, "upload_time": "2011-08-31T23:33:07", "url": "https://files.pythonhosted.org/packages/22/b6/2c745779a0625b8e2626fff0b1c9493dd793cab030ecc01e7ce27a256020/pyfactory-0.4.0.tar.gz" } ] }