{ "info": { "author": "Alex Gaudio", "author_email": "adgaudio@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "About:\n===\n\nfixturefactory is a super simple, easy to use and customizable library for creating Django fixtures. \n\nWithin fixturefactory.py, you will find a BaseFactory and DjangoMixin.\n\n* The BaseFactory class was written to make developing with factories for other purposes or frameworks very simple.\n* The DjangoMixin class provides some methods to make fixture creation easy.\n\nPlease fork, give feedback, or add an issue to the tracker!\n\nUse Cases:\n===\n\nCreating instances of a model\n\n >>> ChildFactory()\n >>> ChildFactory(save_to_db=False)\n\nDynamically passing params to your factories\n\n >>> child1 = ChildFactory().last_obj_created\n \n >>> BrotherFactory(pk1=child1.pk, pk2=1) # These pks are usable as class vars\n\n\nDefining your Factories:\n===\n\nAll factories you create need to have these basic characteristics:\n\n* Must inherit from BaseFactory (should also inherit from DjangoMixin to simplify working with Django)\n* Must have a class variable, 'model', which works like this: inst = model(some='keyword args') ; inst.save() # to db\n* Must have a method, 'getparams', which returns a dict containing the params necessary to instantiate the model.\n\nThe basic template looks like this:\n\n class ChildFactory(BaseFactory, DjangoMixin):\n model = myapp.models.SomeModel\n\n def getparams(self): return {}\n\n\nExample Implementations:\n---\n\nThe following factory generates generic Django users. A more advanced implementation may make use of randomly generated text, etc. Note that getparams returns locals(), which is a dict of the local environment. If you have defined temporary variables in the getparams() method, this approach can cause django to raise an exception, but it also brings up the point that getparams() should not do anything complicated. The purpose of getparams() is to define parameters that will eventually get sent as a call to your factory's model\n\n class UserFactory(BaseFactory, DjangoMixin):\n model = django.contrib.auth.models.User\n\n def getparams(self):\n pk = self.getUnusedPk() # Utilize the methods in DjangoMixin\n username = 'markov_%s' % pk\n password = username\n return locals()\n\nThis next example shows how to implement Foreign Keys, where the UserProfile has a Foreign Key on the above example's User model. Note that the 'user' variable in getparams() is an instance of the UserFactory's model \n\n class UserProfileFactory(BaseFactory, DjangoMixin):\n model = myapp.models.UserProfile\n\n def getparams(self):\n \"\"\"An example of a foreign key\"\"\"\n user = UserFactory().last_obj_created\n pk = user.pk #this User and UserProfile share the same primary key\n return locals()\n\nImplementing Many to Many Relationships are also very easy. In this example, lets assume that RelatedUser is a many to many table linking Users to each other. Use this simple form if you don't care about which 2 UserProfiles the relationships are between:\n\n class RelatedUserFactory(BaseFactory, DjangoMixin):\n model = myapp.models.RelatedUser\n def getparams(self):\n user1_id = self.getRandInst(myapp.models.UserProfile).pk\n user2_id = self.getRandInst(myapp.models.UserProfile).pk\n return locals()\n\nIf you wanted to link 2 user profiles dynamically at runtime, your factory might look a little different. \n\n class RelatedUserFactory(BaseFactory, DjangoMixin):\n model = myapp.models.RelatedUser\n\n def getparams(self):\n user1 = self.pk1 #NOTE the use of self.pk1 and self.pk2\n user2 = self.pk2\n return locals()\n\n >>> RelatedUserFactory(pk1=3, pk2=5) #keyword param required in this case.\n\nYou can avoid typing in keyword arguments if you really want to by overriding the init method. If you do this, which probably means you're overthinking things a bit, make sure you call super() **at the end** of your init method like so:\n\n def __init__(self, pk1, pk2):\n self.pk1 = pk1\n self.pk2 = pk2\n super(self.__class__, self).__init__()\n\nAlso, you can have your factory fall back to randomly choosing values if no keyword argument is supplied by setting class variables to None before __init__ gets called.\n\n class RelatedUserFactory(BaseFactory, DjangoMixin):\n model = mysapp.models.RelatedUser\n\n pk1 = None # sets default value\n pk2 = None\n\n def getparams(self):\n user1 = self.pk1 or self.getRandInst(myapp.models.UserProfile).pk\n user2 = self.pk2 or self.getRandInst(myapp.models.UserProfile).pk\n\nDevelopment:\n===\n\nTo use BaseFactory for a purpose other than Django fixtures, you'd have to (probably) override the BaseFactory.create() method. You will also probably want to create a mixin to simplify development (see DjangoMixin for an example).\n\nI hope all this encourages you to use fixturefactory!", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "git@github.com:adgaudio/fixturefactory.git", "keywords": "django factory fixture", "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "fixturefactory", "package_url": "https://pypi.org/project/fixturefactory/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/fixturefactory/", "project_urls": { "Download": "UNKNOWN", "Homepage": "git@github.com:adgaudio/fixturefactory.git" }, "release_url": "https://pypi.org/project/fixturefactory/0.1/", "requires_dist": null, "requires_python": null, "summary": "Factory to generate Django model objects. Easier than factoryboy and factorygirl", "version": "0.1" }, "last_serial": 792015, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "f46ee25c5d78748db5e4354e3daf5306", "sha256": "008fb59920050b775b5be56c70130ff663f767225c860f8e8416c727f5d33dc2" }, "downloads": -1, "filename": "fixturefactory-0.1.tar.gz", "has_sig": false, "md5_digest": "f46ee25c5d78748db5e4354e3daf5306", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4532, "upload_time": "2011-10-25T06:13:34", "url": "https://files.pythonhosted.org/packages/fa/a0/d0b158dfed4f4c2a5f0a0eeb2328a4e7f36bd3c1b5582d988302f14cb7d6/fixturefactory-0.1.tar.gz" } ], "0.1b": [ { "comment_text": "", "digests": { "md5": "a9a932dd2147347338b6bd1c4ab1ab48", "sha256": "8aef8c2bbf52a8f2f76512450097bacf03cb1880480c69dd79dd12b764d1f469" }, "downloads": -1, "filename": "fixturefactory-0.1b.tar.gz", "has_sig": false, "md5_digest": "a9a932dd2147347338b6bd1c4ab1ab48", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4534, "upload_time": "2011-10-26T14:49:25", "url": "https://files.pythonhosted.org/packages/f2/a1/c968206c37742321ad01a57c334da20fe323934e0e82f155bfdc93e39864/fixturefactory-0.1b.tar.gz" } ], "0.2a": [ { "comment_text": "", "digests": { "md5": "759e0aa50269a6d68fe06ea0cda1f8e7", "sha256": "863b6bea11f34c0dc2a5860921b7eb3f4a094de4498a10a3acfac24a4f2a01ac" }, "downloads": -1, "filename": "fixturefactory-0.2a.tar.gz", "has_sig": false, "md5_digest": "759e0aa50269a6d68fe06ea0cda1f8e7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5066, "upload_time": "2011-10-28T03:11:26", "url": "https://files.pythonhosted.org/packages/73/2e/7ed01a055bbba119dca60ac2d40bbe622d175546841e72b01b9e54015574/fixturefactory-0.2a.tar.gz" } ], "0.2b": [ { "comment_text": "", "digests": { "md5": "f2a2dc000824ec77023aa72cbf765090", "sha256": "91ce345ebe7ec0ed7a7a8149a11ce8eeca8edc07cf1a37a692fa90b6e2312f2e" }, "downloads": -1, "filename": "fixturefactory-0.2b.tar.gz", "has_sig": false, "md5_digest": "f2a2dc000824ec77023aa72cbf765090", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5311, "upload_time": "2011-11-01T05:53:05", "url": "https://files.pythonhosted.org/packages/17/20/e7310b7457ec1ddc20c0b106cab6040d82f28b2c809bcdf33b0c1082686c/fixturefactory-0.2b.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f46ee25c5d78748db5e4354e3daf5306", "sha256": "008fb59920050b775b5be56c70130ff663f767225c860f8e8416c727f5d33dc2" }, "downloads": -1, "filename": "fixturefactory-0.1.tar.gz", "has_sig": false, "md5_digest": "f46ee25c5d78748db5e4354e3daf5306", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4532, "upload_time": "2011-10-25T06:13:34", "url": "https://files.pythonhosted.org/packages/fa/a0/d0b158dfed4f4c2a5f0a0eeb2328a4e7f36bd3c1b5582d988302f14cb7d6/fixturefactory-0.1.tar.gz" } ] }