{ "info": { "author": "Lou Marvin Caraig", "author_email": "loumarvincaraig@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Topic :: Database", "Topic :: Software Development :: Testing" ], "description": "mongo-dynamic-fixture: easy testing by dynamically creating mongo fixtures\n==========================================================================\n\n.. image:: https://travis-ci.org/se7entyse7en/mongo-dynamic-fixture.svg?branch=master\n :target: https://travis-ci.org/se7entyse7en/mongo-dynamic-fixture\n\n.. image:: https://coveralls.io/repos/se7entyse7en/mongo-dynamic-fixture/badge.svg?branch=master&service=github\n :target: https://coveralls.io/github/se7entyse7en/mongo-dynamic-fixture?branch=master\n\n\nMotivation\n----------\n\n* Using static json fixtures can be a pain as they are hard to maintain if the data evolves\n* Adding new tests usually require the addition of new static json fixtures\n* If a static json fixture is used in more than one test case even a little change can break all test cases\n\n\nInspiration\n-----------\n\nThis library is inspired from `django-dynamic-fixture `_.\n\n\nBasic usage\n-----------\n\nThe basic functions are ``N`` and ``G`` that stand for *New* and *Get* respectively.\nFirst you have to define the schema of the data that you want to generate:\n::\n\n from mongo_dynamic_fixture.schema import BaseSchema\n from mongo_dynamic_fixture.fields import IntegerField\n from mongo_dynamic_fixture.fields import DoubleField\n from mongo_dynamic_fixture.fields import BooleanField\n from mongo_dynamic_fixture.fields import StringField\n from mongo_dynamic_fixture.fields import ArrayField\n\n class SiteSchema(BaseSchema):\n\n schema = {\n 'name': StringField(),\n 'aliases': ArrayField(StringField()),\n 'active': BooleanField(),\n 'stats': {\n 'last_day_visits': IntegerField(),\n 'average_daily_visits': DoubleField()\n }\n }\n\nAfter that you can already generate your fixtures!\n::\n\n In [1]: from mongo_dynamic_fixture import N\n\n In [2]: N(SiteSchema)\n Out[2]:\n {'active': True,\n 'aliases': ['kisxcp', 'lG', 'vH5', 'Q7oT1xi', 'RyooxkzB', 'FSFnP'],\n 'name': 'oCmy0ZsGS',\n 'stats': {'average_daily_visits': 0.02137056342099064, 'last_day_visits': 21}}\n\nThe function ``N`` takes an instance of ``BaseSchema`` as first argument and generates a fixture which is compliant with the schema provided.\nObviously sometimes we would like to have more control over the fixture that we want generate, for this reason the ``N`` function also takes ``**kwargs`` optional arguments to fix some specific fields:\n::\n\n In [3]: N(SiteSchema, active=False, stats__last_day_visits=30)\n Out[3]:\n {'active': False,\n 'aliases': ['Euheq6sRgF',\n '9ajFi',\n 'xhCiZfxSsZ',\n 'wf',\n 'k9pkIXS',\n 'kX10H5j4',\n 'ZH',\n '142uYHlJvD'],\n 'name': 'KEKasgW',\n 'stats': {'average_daily_visits': 0.44985850259520865, 'last_day_visits': 30}}\n\nAs you can see both ``active`` and ``last_day_visits`` has been set to the values provided. If the key you want to fix is at the top level of the object then just use the variable name, otherwise list all its ancestors by separating them with ``_`` as for ``stats__last_day_visits``. If the resulting ``**kwargs`` key is not a valid python variable name, then pass it inside the ``extra`` argument:\n::\n\n In [3]: N(MySchema, field1=False, extra={'field2__some-invalid-name!': 30})\n\n\nThe ``G`` function does the same thing of the ``N`` function but additionaly takes a ``pymongo`` connection to a mongo collection as first argument:\n::\n\n In [4]: G(conn['test-db']['test-coll'], SiteSchema, active=False, stats__last_day_visits=30)\n Out[4]:\n {'active': False,\n 'aliases': ['K8ae2uwdW',\n '8P1lkRBC6',\n 'NUoyht',\n 'YG',\n 'BS9iV6Yy',\n 'gHgRVCq'],\n 'name': 'ihccMMs',\n 'stats': {'average_daily_visits': 0.5553574439909581, 'last_day_visits': 30}}\n\nwe have just created a fixture and inserted it inside the collection 'test-coll' of the database 'test-db'.\n\nThe available fields that are all importable from ``mongo_dynamic_fixture.fields`` are the following:\n\n- ``IntegerField``\n- ``DoubleField``\n- ``BooleanField``\n- ``StringField``\n- ``ArrayField``\n- ``ObjectField``\n\n\nA little more than basic usage\n------------------------------\n\nEach fields takes the following optional arguments:\n\n- ``required`` (default: ``True``)\n- ``null`` (default: ``False``)\n- ``blank`` (default: ``False``)\n- ``not_present_prob`` (default: ``0``)\n- ``null_prob`` (default: ``0``)\n- ``blank_prob`` (default: ``0``)\n\nIf ``required`` is ``False``, then with a probability given by ``not_present_prob`` the field will not be present in the document.\n\nIf ``null`` is ``True``, then with a probability given by ``null_prob`` the field will have a value of ``None``.\n\nIf ``blank`` is ``True``, then with a probability given by ``blank_prob`` the field will have a blank value which depends on the field.\n\nThe blank fields for each fields are the following:\n\n- ``IntegerField`` -> ``0``\n- ``DoubleField`` -> ``0.0``\n- ``BooleanField`` -> ``False``\n- ``StringField`` -> ``''``\n- ``ArrayField`` -> ``[]``\n- ``ObjectField`` -> ``{}``\n\n``IntegerField`` and ``DoubleField`` also take ``min_value`` and ``max_value`` as optional arguments, and ``StringField`` and ``ArrayField`` also take ``min_length`` and ``max_length``.\n``IntegerField``, ``DoubleField`` and ``StringField`` also take ``choices`` as optional argument which must be an iterable. In case that this argument is provided the generated value will one those present in the iterable.\nWith ``StringField`` it's also possible to specify the charset of the string to generate by passing it to the ``charset`` optional argument (default: ``string.ascii_letters + string.digits``).\n\nNow you might ask \"And what is the purpose of ``ObjectField``\"? Suppose that you have a schema like the following:\n::\n\n class SiteSchema(BaseSchema):\n\n schema = {\n 'name': StringField(),\n 'aliases': ArrayField(StringField()),\n 'active': BooleanField(),\n 'stats-hourly': {\n 'last_visits': IntegerField(),\n 'average_visits': DoubleField()\n },\n 'stats-daily': {\n 'last_visits': IntegerField(),\n 'average_visits': DoubleField()\n },\n 'stats-monthly': {\n 'last_visits': IntegerField(),\n 'average_visits': DoubleField()\n }\n }\n\nyou can use ``ObjectField`` to write it in a more concise way:\n::\n\n from mongo_dynamic_fixture.fields import ObjectField\n\n obj_field = ObjectField({'last_visits': IntegerField(),\n 'average_visits': DoubleField()})\n\n class SiteSchema(BaseSchema):\n\n schema = {\n 'name': StringField(),\n 'aliases': ArrayField(StringField()),\n 'active': BooleanField(),\n 'stats-hourly': obj_field,\n 'stats-daily': obj_field,\n 'stats-monthly': obj_field\n }\n\n\n\nInstallation\n------------\n\n pip install mongo-dynamic-fixture\n\n\nCompatiblity\n------------\n\nTested with:\n\n- ``python2.7`` and ``pymongo>=2.0``\n- ``python3.3``, ``python3.4`` and ``pymongo>=2.2``\n\n\nContributing\n------------\n\nFor any suggestion, improvements, issues and bugs please open an Issue.\n\n\nRelease History\n---------------\n\n\nv0.2.1\n^^^^^^\n\n- Fixed ``min_length`` of ``StringField`` and ``ArrayField`` from ``0`` to ``1``\n- Simplified interface of functions ``N`` and ``G``\n\nv0.2.0\n^^^^^^\n\n- Added ``python3.3`` and ``python3.4`` compatibility\n- Configured testing with ``tox``\n- Integrated Travis CI\n- Integrated Coveralls\n\n\nv0.1.0\n^^^^^^\n\n- Added modules ``mongo_dynamic_fixture.fields``, ``mongo_dynamic_fixture.fixture`` and ``mongo_dynamic_fixture.schema`` to generate datas\n- Added module ``mongo_dynamic_fixture.facades`` containing facades functions ``N`` and ``G``\n- Added module ``mongo_dynamic_fixture.test`` containing ``MongoTestCase`` to run tests with a sandboxed mongo instance", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/se7entyse7en/mongo-dynamic-fixture", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "mongo-dynamic-fixture", "package_url": "https://pypi.org/project/mongo-dynamic-fixture/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/mongo-dynamic-fixture/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/se7entyse7en/mongo-dynamic-fixture" }, "release_url": "https://pypi.org/project/mongo-dynamic-fixture/0.2.1/", "requires_dist": null, "requires_python": null, "summary": "Mongo Dynamic Fixture", "version": "0.2.1" }, "last_serial": 1792217, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "1a725ea71d5a21925af97ef682f295dd", "sha256": "4c8439ae74a7dd0fa1de7c19e23ee05f87f34d7d3881e8a1fdd215910403534e" }, "downloads": -1, "filename": "mongo-dynamic-fixture-0.1.0.tar.gz", "has_sig": false, "md5_digest": "1a725ea71d5a21925af97ef682f295dd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7815, "upload_time": "2015-10-24T11:14:09", "url": "https://files.pythonhosted.org/packages/e2/01/ebb917db7b41badbf6acb2afbadd2bf20aec64996f3849436dbe02159a06/mongo-dynamic-fixture-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "3a9336d523a516d02e9582d0125c3cca", "sha256": "1a00e7931770f9ed3ffd4b032b72ef2e6cc0ea1fe24060753459406bbc82be56" }, "downloads": -1, "filename": "mongo-dynamic-fixture-0.2.0.tar.gz", "has_sig": false, "md5_digest": "3a9336d523a516d02e9582d0125c3cca", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10705, "upload_time": "2015-10-28T18:21:54", "url": "https://files.pythonhosted.org/packages/d3/70/1f8fa9c576b93caeada109b567e15f15c038c32616e99bff05be38847d01/mongo-dynamic-fixture-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "847353d77ceb45c2057a411678248328", "sha256": "630ffdade5afb56eb80e51f14dee86d909d797a3aee94da9504a4d1c0d42bbe7" }, "downloads": -1, "filename": "mongo-dynamic-fixture-0.2.1.tar.gz", "has_sig": false, "md5_digest": "847353d77ceb45c2057a411678248328", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10957, "upload_time": "2015-10-29T17:18:52", "url": "https://files.pythonhosted.org/packages/b2/42/c653c071bfc2fb5358c666bb2f01b862d8d73abdc76707f4a9fdea7944e5/mongo-dynamic-fixture-0.2.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "847353d77ceb45c2057a411678248328", "sha256": "630ffdade5afb56eb80e51f14dee86d909d797a3aee94da9504a4d1c0d42bbe7" }, "downloads": -1, "filename": "mongo-dynamic-fixture-0.2.1.tar.gz", "has_sig": false, "md5_digest": "847353d77ceb45c2057a411678248328", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10957, "upload_time": "2015-10-29T17:18:52", "url": "https://files.pythonhosted.org/packages/b2/42/c653c071bfc2fb5358c666bb2f01b862d8d73abdc76707f4a9fdea7944e5/mongo-dynamic-fixture-0.2.1.tar.gz" } ] }