{ "info": { "author": "Michael Pickelbauer", "author_email": "mmmichlPi@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Topic :: Database", "Topic :: Software Development :: Testing" ], "description": "SQLAlchemy-Fixture-Factory\n==========================\n\n|Build Status| |Version Status| |Documentation|\n\nA fixture factory for SQLAlchemy ORM mapper to easily build test scenarios for unit or integration testing.\nInspired by Ruby's `factory_girl `_\n\nInstallation\n------------\n\n pip install sqlalchemy-fixture-factory\n\n\nUsage\n-----\n\nAssume following plain SQLAlchemy ORM models:\n\n.. code-block:: python\n\n # association table\n account_role = Table('account_role', Base.metadata,\n Column('id_account', Integer, ForeignKey('account.id')),\n Column('id_role', Integer, ForeignKey('role.id')))\n \n class Role(Base):\n __tablename__ = 'role'\n \n id = Column(Integer, primary_key=True)\n name = Column(Unicode)\n \n class Account(Base):\n __tablename__ = 'account'\n \n id = Column(Integer, primary_key=True)\n name = Column('name', Unicode)\n \n roles = relationship(Role, secondary=account_role)\n \n class Person(Base):\n __tablename__ = 'person'\n \n id = Column(Integer, primary_key=True)\n first_name = Column('first_name', Unicode)\n account_id = Column(Integer, ForeignKey('account.id'))\n account = relationship(Account)\n\nInitialize SQLAlchemy-Fixture-Factory:\n\n.. code-block:: python\n\n # SQLAlechemy DB session generated from SessionPool\n fix_fact = SqlaFixFact(db_session)\n\nDefine a simple person fixture:\n\n.. code-block:: python\n \n class FranzPerson(BaseFix):\n MODEL = Person\n first_name = 'Franz'\n\nThe property ``MODEL`` needs to be set with the desired ORM class. Then simply set the fields as desired. \nIn this example the ``first_name`` with ``Franz``.\n \nUse this fixture:\n\n.. code-block:: python\n\n franz_fix = FranzPerson(fix_fact).create()\n \n print (\"Person count:\", db_session.query(Person).count())\n # output: 1\n \n # create more instances of the same fixture\n franz_fix_2 = FranzPerson(fix_fact).create()\n franz_fix_3 = FranzPerson(fix_fact).create()\n \n print (\"Person count:\", db_session.query(Person).count())\n # output: 3\n \n print (\"Instances and id's are different:\",\n franz_fix != franz_fix_2 != franz_fix_3,\n franz_fix.id != franz_fix_2.id != franz_fix_3.id)\n # output: True True\n \n # alter fields at instantiation time\n franz_fix_alt_name = FranzPerson(fix_fact, first_name='Sepp').create()\n \n print (\"Person count with first_name 'Sepp':\",\n db_session.query(Person).filter(Person.first_name == \"Sepp\").count())\n # output: 1\n \nAlternatively, retrieve the model without instantiating the fixture, but create the dependencies with ``.model()``\n\n.. code-block:: python\n\n # retrieve only the (altered) model\n franz_model_alt_name = FranzPerson(fix_fact, first_name='Hugo').model()\n \n print (\"Person count with first_name 'Hugo':\",\n db_session.query(Person).filter(Person.first_name == \"Hugo\").count())\n # output: 0\n \n db_session.add(franz_model_alt_name)\n \n print (\"Person count with first_name 'Hugo':\",\n db_session.query(Person).filter(Person.first_name == \"Hugo\").count())\n # output: 1\n\nIf you need the same instance in different fixtures, use ``.get()``\n\n.. code-block:: python\n\n # clean up the DB\n Base.metadata.drop_all(connection)\n Base.metadata.create_all(connection)\n \n # first call creates the fixture and caches the reference\n franz_get = FranzPerson(fix_fact).get()\n franz_get_2 = FranzPerson(fix_fact).get()\n franz_get_3 = FranzPerson(fix_fact).get()\n \n print (\"Person count:\", db_session.query(Person).count())\n # output: 1\n \n print (\"Instances and id's are the same:\",\n franz_get == franz_get_2 == franz_get_3, \n franz_get.id == franz_get_2.id == franz_get_3.id)\n # output: True True\n\nBuild a more complex scenario:\n\n.. code-block:: python\n\n class ViewRole(BaseFix):\n MODEL = Role\n name = \"View Role\"\n \n class EditRole(BaseFix):\n MODEL = Role\n name = \"Edit Role\"\n \n class ArnoldAccount(BaseFix):\n MODEL = Account\n name = \"arney\"\n # Use get to reference to the roles, as only one instance in the DB is desired\n roles = [sqla_fix_fact.subFactoryGet(ViewRole), sqla_fix_fact.subFactoryGet(EditRole)]\n \n class ArnoldPerson(BaseFix):\n MODEL = Person\n name = \"Arnold\"\n account = sqla_fix_fact.subFactoryModel(ArnoldAccount)\n\nTo instantiate the ``ArnoldPerson`` fixture, following line is sufficient to create the person with all dependencies:\n\n.. code-block:: python\n\n arnold_fix = ArnoldPerson(fix_fact).create()\n\nQuery the DB to see if everything is in place as expected:\n\n.. code-block:: python\n\n arnold_db = db_session.query(Person).get(arnold_fix.id)\n \n print (\"Account name of Arnold:\", arnold_db.account.name)\n # output: arney\n print (\"Roles of Arnold:\", [r.name for r in arnold_db.account.roles])\n # output: ['View Role', 'Edit Role']\n\nYou can find this examples ready to play around in ``readme_examples.py``\n\nResources\n---------\n\n- `Documentation `_\n- `Issue Tracker `_\n- `Code `_\n\n\n.. |Build Status| image:: https://travis-ci.org/mmmichl/sqlalchemy-fixture-factory.svg?branch=master\n :target: https://travis-ci.org/mmmichl/sqlalchemy-fixture-factory\n.. |Version Status| image:: https://pypip.in/version/SQLAlchemy-Fixture-Factory/badge.svg\n :target: https://pypi.python.org/pypi/SQLAlchemy-Fixture-Factory/\n :alt: Latest Version\n.. |Documentation| image:: https://readthedocs.org/projects/sqlalchemy-fixture-factory/badge/?version=latest\n :target: https://readthedocs.org/projects/sqlalchemy-fixture-factory/?badge=latest\n :alt: Documentation Status\n.. |Downloads| image:: https://pypip.in/download/SQLAlchemy-Fixture-Factory/badge.svg\n :target: https://pypi.python.org/pypi/SQLAlchemy-Fixture-Factory/\n :alt: Downloads", "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/mmmichl/sqlalchemy-fixture-factory", "keywords": "SQLAlchemy test fixtures database-testing scenario builder", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "SQLAlchemy-Fixture-Factory", "package_url": "https://pypi.org/project/SQLAlchemy-Fixture-Factory/", "platform": "any", "project_url": "https://pypi.org/project/SQLAlchemy-Fixture-Factory/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/mmmichl/sqlalchemy-fixture-factory" }, "release_url": "https://pypi.org/project/SQLAlchemy-Fixture-Factory/1.0.0/", "requires_dist": null, "requires_python": null, "summary": "Test Fixture Factory for SQLAlchemy. Inspired by Ruby's factory_girl", "version": "1.0.0" }, "last_serial": 2088077, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "176fa44776a9123575d1ba2afa90a505", "sha256": "b2d9a50e76d829300898e9d58934eaed894b9d5d75609517ce75d6c09d8ec6b8" }, "downloads": -1, "filename": "SQLAlchemy_Fixture_Factory-0.1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "176fa44776a9123575d1ba2afa90a505", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 9631, "upload_time": "2015-03-23T17:34:53", "url": "https://files.pythonhosted.org/packages/6f/e6/ebb209f49e9b5aac6481e67ca703ec41c37b4f650a7e257293f744d7ff71/SQLAlchemy_Fixture_Factory-0.1.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "75c76defc59c2f9424a7e17eea4a0818", "sha256": "d5ea7c0a4267bb7a5479c7d871af48bed3ad6405b27c8584a522d6aec1e08ddc" }, "downloads": -1, "filename": "SQLAlchemy-Fixture-Factory-0.1.0.tar.gz", "has_sig": false, "md5_digest": "75c76defc59c2f9424a7e17eea4a0818", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6949, "upload_time": "2015-03-23T17:34:49", "url": "https://files.pythonhosted.org/packages/5a/1b/49e2e0852bcc164f75dd56f8aa099d81408f0586738d9957a2873f149368/SQLAlchemy-Fixture-Factory-0.1.0.tar.gz" } ], "0.1.0dev": [ { "comment_text": "", "digests": { "md5": "3eafd2be6e22bfb338a88cbcc53ca617", "sha256": "4f22165f5a15d22335d0e0dae163d5522eaf1606998b2bcfac50ac0024ce3d11" }, "downloads": -1, "filename": "SQLAlchemy_Fixture_Factory-0.1.0dev-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "3eafd2be6e22bfb338a88cbcc53ca617", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 9053, "upload_time": "2015-03-18T22:57:41", "url": "https://files.pythonhosted.org/packages/ca/f6/cac61fa83b7cbfc629a2305cc7c752c0971b18bd84d1d7a95547278bf3dc/SQLAlchemy_Fixture_Factory-0.1.0dev-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e33076482af23a88e4707c68d9cb929b", "sha256": "be07c8af4530e7da1e0a193b178d5ce7e5b12631658f6ee36296edb38065ca0c" }, "downloads": -1, "filename": "SQLAlchemy-Fixture-Factory-0.1.0dev.tar.gz", "has_sig": false, "md5_digest": "e33076482af23a88e4707c68d9cb929b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6363, "upload_time": "2015-03-18T22:57:37", "url": "https://files.pythonhosted.org/packages/0f/43/59bd761dcb31880fa9552532eef5e613e4e43391004dcd7db8d54e1e62de/SQLAlchemy-Fixture-Factory-0.1.0dev.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "3b01bf52c846983dfcfc38eff4d1f38b", "sha256": "3df544165e616adf9ce6e1c1cbdf3820b0efc709f0bc6fc3e00ba4731038e0a6" }, "downloads": -1, "filename": "SQLAlchemy_Fixture_Factory-1.0.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "3b01bf52c846983dfcfc38eff4d1f38b", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 9689, "upload_time": "2016-04-28T06:41:22", "url": "https://files.pythonhosted.org/packages/a5/4d/efcc4c406c3ae4824f003893af65cba24832591e4f702be679d7e99c3476/SQLAlchemy_Fixture_Factory-1.0.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5fdd61bbe3a70354c54cd1ccb800b682", "sha256": "050d25fb1766769b15770e0a9b05d07eb610060e43fb4789b55fbed9bdcb03f5" }, "downloads": -1, "filename": "SQLAlchemy-Fixture-Factory-1.0.0.tar.gz", "has_sig": false, "md5_digest": "5fdd61bbe3a70354c54cd1ccb800b682", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6991, "upload_time": "2016-04-28T06:41:16", "url": "https://files.pythonhosted.org/packages/ee/72/346179e8ee97b32048423a57e6483b4b33a7640c363a61458ec41a222f0d/SQLAlchemy-Fixture-Factory-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "3b01bf52c846983dfcfc38eff4d1f38b", "sha256": "3df544165e616adf9ce6e1c1cbdf3820b0efc709f0bc6fc3e00ba4731038e0a6" }, "downloads": -1, "filename": "SQLAlchemy_Fixture_Factory-1.0.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "3b01bf52c846983dfcfc38eff4d1f38b", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 9689, "upload_time": "2016-04-28T06:41:22", "url": "https://files.pythonhosted.org/packages/a5/4d/efcc4c406c3ae4824f003893af65cba24832591e4f702be679d7e99c3476/SQLAlchemy_Fixture_Factory-1.0.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5fdd61bbe3a70354c54cd1ccb800b682", "sha256": "050d25fb1766769b15770e0a9b05d07eb610060e43fb4789b55fbed9bdcb03f5" }, "downloads": -1, "filename": "SQLAlchemy-Fixture-Factory-1.0.0.tar.gz", "has_sig": false, "md5_digest": "5fdd61bbe3a70354c54cd1ccb800b682", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6991, "upload_time": "2016-04-28T06:41:16", "url": "https://files.pythonhosted.org/packages/ee/72/346179e8ee97b32048423a57e6483b4b33a7640c363a61458ec41a222f0d/SQLAlchemy-Fixture-Factory-1.0.0.tar.gz" } ] }