{ "info": { "author": "Arie Bro", "author_email": "ariebro@gmail.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Topic :: Software Development :: Testing" ], "description": "python-testdata\n===============\n\nA simple package that generates data for tests.\n\ntestdata provides the basic Factory and DictFactory classes that generate content.\nit also provides many more specialized factories that provide extended functionality.\nevery Factory instance knows how many elements its going to generate, this enables us to generate statistical results.\n\nThe DictFactory is especially useful if you want to generate data that you will later input to your NoSQL, Document based\ndatabase\n\nIn addition, using the DictFactory and the DependentField factories allows us to create factorys that depend on the results\nof other factories. (see Examples for more information).\n\ntestdata isn't bound to a specifc database, but does include database specfic modules inside, like - extra.mongodb.py)\nbut it will always be clean of database related dependencies.\n\n## Installation\n\n pip install python-testdata\n\n## Examples\nWe integrate the awsome fake-factory package to generate data using FakeDataFactory,\nthis allows us to generate all sorts of content like:\n * Names (First, last, full names)\n * companies\n * addresses\n * emails\n * urls\n * and much much more\n\nlets create a very simple factory that generates Users:\n\n```python\nimport testdata\n\nclass Users(testdata.DictFactory):\n id = testdata.CountingFactory(10)\n firstname = testdata.FakeDataFactory('firstName')\n lastname = testdata.FakeDataFactory('lastName')\n address = testdata.FakeDataFactory('address')\n age = testdata.RandomInteger(10, 30) \n gender = testdata.RandomSelection(['female', 'male'])\n\nfor user in Users().generate(10): # let say we only want 10 users\n print user\n # {'firstname': 'Toni', 'lastname': 'Schaden', 'gender': 'female', 'age': 18, 'address': '0641 Homenick Hills\\nSouth Branson, RI 70388', 'id': 10}\n # {'firstname': 'Gene', 'lastname': 'Greenfelder', 'gender': 'male', 'age': 17, 'address': '292 Loy Lights Suite 328\\nFritzfort, IN 73914', 'id': 11}\n # or more likely you'd want to insert them into your favorite database (MongoDB, ElasticSearch, ..)\n```\n\nWhen creating our own subclasses for DictFactory, we can make some fields dependent on other fields.\nfor example:\n\n```python\nclass ExampleFactory(DictFactory):\n a = CountingFactory(10)\n b = ClonedField(\"a\") # b will have the same value as field 'a'\n\nfor e in ExampleFactory().generate(100):\n print e\n\n# {'a': 10, 'b': 10}\n# {'a': 11, 'b': 11}\n# ...\n```\n\nLets say we want to generate something like events data, we want events to have \na start time, and an end time that will be 20 minutes in the future.\nIn addition, we want the event's start_time will be 12 minutes apart.\n\n```python\nimport testdata\n\nEVENT_TYPES = [\"USER_DISCONNECT\", \"USER_CONNECTED\", \"USER_LOGIN\", \"USER_LOGOUT\"]\nclass EventsFactory(testdata.DictFactory):\n start_time = testdata.DateIntervalFactory(datetime.datetime.now(), datetime.timedelta(minutes=12))\n end_time = testdata.RelativeToDatetimeField(\"start_time\", datetime.timedelta(minutes=20))\n event_code = testdata.RandomSelection(EVENT_TYPES)\n\nfor event in EventFactory().generate(100):\n print event\n # {'start_time': datetime.datetime(2013, 12, 23, 13, 37, 1, 591878), 'end_time': datetime.datetime(2013, 12, 23, 13, 57, 1, 591878), 'event_code': 'USER_CONNECTED'}\n # {'start_time': datetime.datetime(2013, 12, 23, 13, 49, 1, 591878), 'end_time': datetime.datetime(2013, 12, 23, 14, 9, 1, 591878), 'event_code': 'USER_LOGIN'}\n # {'start_time': datetime.datetime(2013, 12, 23, 14, 1, 1, 591878), 'end_time': datetime.datetime(2013, 12, 23, 14, 21, 1, 591878), 'event_code': 'USER_DISCONNECT'}\n```\n\nWe also have factories that allow us to generate different data distributed by different percentage, for example,\nlets say we want to create a 'Job', that will have an assigned user field, a state field and a description field.\nWe want the state to be 'pending' in 90% of dictionaries and 'error' in the rest of them. In addition, we want that if the 'state' field is \n'error' the assigned user will be 'support', or else it should be 'admin'.\n\n```python\nclass Job(testdata.DictFactory):\n state = testdata.StatisticalValuesFactory([('pending', 90), ('error', 10)])\n assigned_user = testdata.ConditionalValueField('state', {'error': 'support'}, 'admin')\n description = testdata.RandomLengthStringFactory()\n\nfor i in Job().generate(10):\n print i\n # {'state': 'error', 'assigned_user': 'support', 'description': 'jUlyFByPxPdFlBPBfPaGaTPPuajFSHXKkyewzrQ'}\n # {'state': 'pending', 'assigned_user': 'admin', 'description': 'tOzkgmBBnxQZhSYEjVduyXGdLrtqeTZqRxmHNXbaJBfpdNxuLKWyTDxkCZgiZTLHeiKEswvIyDzAnuuOLtXmVWhjvazaOYuu'}\n # {'state': 'pending', 'assigned_user': 'admin', 'description': 'TIDVuvZRUBLLTtG'}\n # {'state': 'pending', 'assigned_user': 'admin', 'description': 'RgcSaFzmMrhwCAZjLofikmXJhtqkVOTsWHnqTXjgrxgzTKH'}\n # {'state': 'pending', 'assigned_user': 'admin', 'description': 'tLkSEkCbYDvlcDBDWUBGMmidEdOxeiLDBADDKnqGqWLnxUBqzOXFXnBxkiGTymuGNbUnmxyawzLGsiummCiwxNSw'}\n # {'state': 'pending', 'assigned_user': 'admin', 'description': 'tUyYLofuZpceaWYKkiRvksQLqFHGOiwACuPIvRxMIuftJPsObSqCBcrQnOkOhqAukfMwrY'}\n # {'state': 'pending', 'assigned_user': 'admin', 'description': 'JbFrUxrERMObfwhEtCQGcxEbimvoTFwJriSfRFLFkBpyemqEfqUCGKmVlgSlVoZrrnetEnLCgbfobFbTMQOZ'}\n # {'state': 'pending', 'assigned_user': 'admin', 'description': 'lqatAwdcQuMMOPiYdVMRyyQgEIzOlcoozijjdCfXsVoZnnTtQjPSGBFZQGSkPblJrTIYLAotiZoyYRFrlncevwuNcqfOmeXeCPD'}\n # {'state': 'pending', 'assigned_user': 'admin', 'description': 'VYxnhydWtIUFiOEPszVQHuxYBIUGDyAefZiPIgkWHCMmophiueXbixXtdwKQkuvWImuErMOOOcwevQHGApXkolhjAq'}\n # {'state': 'pending', 'assigned_user': 'admin', 'description': 'RcawgTkQggchdHppSyQxnbDdNxqkGqbQWnQMSlorqnAQLdAqyWnKtGpXaZuVdxcGQBImzVPQsYAbIFUIpqvDzwTDdRpleBrc'}\n```\n\nIn version 1.0.5 we extended the DictFactory to support passing additional factories, or overriding existing factories, for a specific instance.\nLets take for example our 'User' example from the begining.\n\n```python\nimport testdata\nclass Users(testdata.DictFactory):\n id = testdata.CountingFactory(10)\n firstname = testdata.FakeDataFactory('firstName')\n lastname = testdata.FakeDataFactory('lastName')\n address = testdata.FakeDataFactory('address')\n age = testdata.RandomInteger(10, 30) \n gender = testdata.RandomSelection(['female', 'male'])\n```\nBut lets override it so the 'firstname' always returns John, and make the age be a random integer between 40 and 60 and add an 'email' field.\n\n```python\nfor user in Users(firstname=testdata.Constant('John'), age=testdata.RandomInteger(40, 60), email=testdata.FakeDataFactory('email')).generate(10): # let say we only want 10 users\n print user\n #{'firstname': 'John', 'gender': 'male', 'age': 54, 'email': 'hazle.wehner@brekke.com', 'lastname': 'Willms', 'address': '245 Pfeffer Light Apt. 309\\nEast Audieside, IN 11931', 'id': 10}\n #{'firstname': 'John', 'gender': 'male', 'age': 47, 'email': 'mariam25@gmail.com', 'lastname': 'Ratke', 'address': '98710 Freddy Gateway\\nDelilahborough, GU 50849', 'id': 11}\n #{'firstname': 'John', 'gender': 'male', 'age': 55, 'email': 'tyler22@yahoo.com', 'lastname': 'Cormier', 'address': '432 Block Locks Apt. 547\\nNew Estel, NJ 54026', 'id': 12}\n # or more likely you'd want to insert them into your favorite database (MongoDB, ElasticSearch, ..)\n```\n\n## Factories\nSee the Factorie's Docstrings for more examples and doctests.\n\n#### Bases\n|Factory Class| Description|\n|:-------|:-----------|\n| Factory | The base class of all the factories.|\n| DictFactory | A very powerful base class. allows sub classing to create factories that generate dicts with a specific schema (see [Examples][#Examples]). |\n| ListFactory | A factory that returns on each iteration a list of `elements_per_list` items returned from calls to the given factory. |\n| Callable | Gets a callable object as an argument and returns the result of calling the object on every iteration |\n| DependentCallable | Gets a callable object as an argument and returns the result of calling the object passing the defined fields as arguments on every iteration |\n| ClonedField | A factory that copies the value of another factory. |\n#### Dates\n|Factory Class| Description|\n|:-------|:-----------|\n| RandomDateFactory | Generates random dates (python's datetime) between 2 dates|\n| DateIntervalFactory | Generates datetime objects starting from `base` while adding `delta` to it each iteration.\n| RelativeToDatetimeField | Generates datetime object relative to another datetime field, like if you have `start_time` which is a RandomDateFactory field, and want an `end_time` field that is always 15 minutes later.| \n\nAnd MUCH MUCH more.. \n\n## Todos\n* Add usage documentation for each factory (using doctest maybe?)\n* Add more tests\n* Add GeoLocationFactories to generates Location and distance related data (for example, random points near a central point).\n* Add MORE Statistical Factories\n* more ideas welcome!", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/arieb/python-testdata", "keywords": "factory testing test unittest mongo data testdata database json elasticsearch", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "python-testdata", "package_url": "https://pypi.org/project/python-testdata/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/python-testdata/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/arieb/python-testdata" }, "release_url": "https://pypi.org/project/python-testdata/1.0.5/", "requires_dist": null, "requires_python": null, "summary": "A small package that helps generate content to fill databases for tests.", "version": "1.0.5" }, "last_serial": 954592, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "987af32db4d02a415f1e0684bfa5d82b", "sha256": "c605dcac878370729e9698697ba648eae2638598c1204358d000caf8fb7438e8" }, "downloads": -1, "filename": "python-testdata-1.0.0.tar.gz", "has_sig": false, "md5_digest": "987af32db4d02a415f1e0684bfa5d82b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9070, "upload_time": "2013-12-22T12:00:38", "url": "https://files.pythonhosted.org/packages/ac/1b/ec7b65d3e3e7ce7501af6075e42b1818def760fa888c8838c1d731a124e8/python-testdata-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "eb7794a4d2ff22cda79afb180bc37b21", "sha256": "8c6cb238fb3d02186682e980dd114b188fcad6aa784cbdea03373d942c9ee008" }, "downloads": -1, "filename": "python-testdata-1.0.1.tar.gz", "has_sig": false, "md5_digest": "eb7794a4d2ff22cda79afb180bc37b21", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10029, "upload_time": "2013-12-23T11:49:53", "url": "https://files.pythonhosted.org/packages/b9/1a/42d75703d58bc15cd69f1876fe941177717fc254f482ede78a9114dbfbbd/python-testdata-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "0fe21db1e496f977e42eac3532e92999", "sha256": "b1ca3097773bc5a814fd6afa3e0985a2c6b44a2bf0046dd260a276a4d076db58" }, "downloads": -1, "filename": "python-testdata-1.0.2.tar.gz", "has_sig": false, "md5_digest": "0fe21db1e496f977e42eac3532e92999", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10270, "upload_time": "2013-12-23T14:46:08", "url": "https://files.pythonhosted.org/packages/19/b5/f2e939b008ac76536e9f32112bfe7c012ab09fdb97ad241055cca6006023/python-testdata-1.0.2.tar.gz" } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "d37c90f073f39edc238df3dae9b65513", "sha256": "df60996210272934562facd3fd1e9b28d9d61da70dfc1ece15812e031a5e894b" }, "downloads": -1, "filename": "python-testdata-1.0.3.tar.gz", "has_sig": false, "md5_digest": "d37c90f073f39edc238df3dae9b65513", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12147, "upload_time": "2013-12-24T15:56:15", "url": "https://files.pythonhosted.org/packages/97/17/9e6d609a7a25fb2cf2333311d42cef548cd6d86e5dbfe7fb0ebd24da0616/python-testdata-1.0.3.tar.gz" } ], "1.0.5": [ { "comment_text": "", "digests": { "md5": "665bfabb39c243930c965ab3055dc0c5", "sha256": "0fb0ef8a8feb7a6905c17c7e88c0fb0dc5593604fec755d0f3c089af035e7cb6" }, "downloads": -1, "filename": "python-testdata-1.0.5.tar.gz", "has_sig": false, "md5_digest": "665bfabb39c243930c965ab3055dc0c5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13087, "upload_time": "2013-12-25T16:27:10", "url": "https://files.pythonhosted.org/packages/87/f8/fa2cd76b1e6d153df1df139231f7906cca06ea811f8d6cf2c39e791a5d60/python-testdata-1.0.5.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "665bfabb39c243930c965ab3055dc0c5", "sha256": "0fb0ef8a8feb7a6905c17c7e88c0fb0dc5593604fec755d0f3c089af035e7cb6" }, "downloads": -1, "filename": "python-testdata-1.0.5.tar.gz", "has_sig": false, "md5_digest": "665bfabb39c243930c965ab3055dc0c5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13087, "upload_time": "2013-12-25T16:27:10", "url": "https://files.pythonhosted.org/packages/87/f8/fa2cd76b1e6d153df1df139231f7906cca06ea811f8d6cf2c39e791a5d60/python-testdata-1.0.5.tar.gz" } ] }