{ "info": { "author": "Christopher Roach", "author_email": "vthakr@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Internet :: WWW/HTTP :: Dynamic Content", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Software Development :: Testing" ], "description": "Flask-Fixtures\n==============\n\nA simple library that allows you to add database fixtures for your unit\ntests using nothing but JSON or YAML.\n\nInstallation\n------------\n\nInstalling Flask-Fixtures is simple, just do a typical pip install like\nso:\n\n::\n\n pip install flask-fixtures\n\n If you are going to use JSON as your data serialization format, you\n should also consider installing the dateutil package since it will\n add much more powerful and flexible parsing of dates and times.\n\nTo install the library from source simply download the source code, or\ncheck it out if you have git installed on your system, then just run the\ninstall command.\n\n::\n\n git clone https://github.com/croach/Flask-Fixtures.git\n cd /path/to/flask-fixtures\n python setup.py install\n\nSetup\n-----\n\nTo setup the library, you simply need to tell Flask-Fixtures where it\ncan find the fixtures files for your tests. Fixtures can reside anywhere\non the file system, but by default, Flask-Fixtures looks for these files\nin a directory called ``fixtures`` in your app's root directory. To add\nmore directories to the list to be searched, just add an attribute\ncalled ``FIXTURES_DIRS`` to your app's config object. This attribute\nshould be a list of strings, where each string is a path to a fixtures\ndirectory. Absolute paths are added as is, but reltative paths will be\nrelative to your app's root directory.\n\nOnce you have configured the extension, you can begin adding fixtures\nfor your tests.\n\nAdding Fixtures\n---------------\n\nTo add a set of fixtures, you simply add any number of JSON or YAML\nfiles describing the individual fixtures to be added to your test\ndatabase into one of the directories you specified in the\n``FIXTURES_DIRS`` attribute, or into the default fixtures directory. As\nan example, I'm going to assume we have a Flask application with the\nfollowing directory structure.\n\n::\n\n /myapp\n __init__.py\n config.py\n models.py\n /fixtures\n authors.json\n\nThe ``__init__.py`` file will be responsible for creating our Flask\napplication object.\n\n.. code:: python\n\n # myapp/__init__.py\n\n from flask import Flask\n\n app = Flask(__name__)\n\nThe ``config.py`` object holds our test configuration file.\n\n.. code:: python\n\n # myapp/config.py\n\n class TestConfig(object):\n SQLALCHEMY_DATABASE_URI = 'sqlite://'\n testing = True\n debug = True\n\nAnd, finally, inside of the ``models.py`` files we have the following\ndatabase models.\n\n.. code:: python\n\n # myapp/models.py\n\n from flask_sqlalchemy import SQLAlchemy\n\n from myapp import app\n\n db = SQLAlchemy(app)\n\n class Author(db.Model):\n id = db.Column(db.Integer, primary_key=True)\n first_name = db.Column(db.String(30))\n last_name = db.Column(db.String(30))\n\n class Book(db.Model):\n id = db.Column(db.Integer, primary_key=True)\n title = db.Column(db.String(200))\n author_id = db.Column(db.Integer, db.ForeignKey('author.id'))\n author = db.relationship('Author', backref='books')\n\nGiven the model classes above, if we wanted to mock up some data for our\ndatabase, we could do so in single file, or we could even split our\nfixtures into multiple files each corresponding to a single model class.\nFor this simple example, we'll go with one file that we'll call\n``authors.json``.\n\nA fixtures file contains a list of objects. Each object contains a key\ncalled ``records`` that holds another list of objects each representing\neither a row in a table, or an instance of a model. If you wish to work\nwith tables, you'll need to specify the name of the table with the\n``table`` key. If you'd prefer to work with models, specify the\nfully-qualified class name of the model using the ``model`` key. Once\nyou've specified the table or model you want to work with, you'll need\nto specify the data associated with each table row, or model instance.\nEach object in the ``records`` list will hold the data for a single row\nor model. The example below is the JSON for a single author record and a\nfew books associated with that author. Create a file called\n``myapp/fixtures/authors.json`` and copy and paste the fixtures JSON\nbelow into that file.\n\n.. code:: json\n\n [\n {\n \"table\": \"author\",\n \"records\": [{\n \"id\": 1,\n \"first_name\": \"William\",\n \"last_name\": \"Gibson\",\n }]\n },\n {\n \"model\": \"myapp.models.Book\",\n \"records\": [{\n \"title\": \"Neuromancer\",\n \"author_id\": 1\n },\n {\n \"title\": \"Count Zero\",\n \"author_id\": 1\n },\n {\n \"title\": \"Mona Lisa Overdrive\",\n \"author_id\": 1\n }]\n }\n ]\n\nAnother option, if you have `PyYAML `__ installed,\nis to write your fixtures using the YAML syntax instead of JSON.\nPersonally, I prefer to use YAML; I find its syntax is easier to read,\nand I find the ability to add comments to my fixtures to be invaluable.\n\nIf you'd prefer to use YAML, I've added a version of the authors.json\nfile written in YAML below. Just copy and paste it into a file called\n``myapp/fixtures/authors.yaml`` in place of creating the JSON file\nabove.\n\n.. code:: yaml\n\n - table: author\n records:\n - id: 1\n first_name: William\n last_name: Gibson\n\n - model: myapp.models.Book\n records:\n - title: Neuromancer\n author_id: 1\n published_date: 1984-07-01\n - title: Count Zero\n author_id: 1\n published_date: 1986-03-01\n - title: Neuromancer\n author_id: 1\n published_date: 1988-10-01\n\nAfter reading over the previous section, you might be asking yourself\nwhy the library supports two methods for adding records to the database.\nThere are a few good reasons for supporting both tables and models when\ncreating fixtures. Using tables is faster, since we can take advantage\nof SQLAlchemy's bulk insert to add several records at once. However, to\ndo so, you must first make sure that the records list is homegenous.\n**In other words, every object in the ``records`` list must have the\nsame set of key/value pairs, otherwise the bulk insert will not work.**\nUsing models, however, allows you to have a heterogenous list of record\nobjects.\n\nThe other reason you may want to use models instead of tables is that\nyou'll be able to take advantage of any python-level defaults, checks,\netc. that you have setup on the model. Using a table, bypasses the model\ncompletely and inserts the data directly into the database, which means\nyou'll need to think on a lower level when creating table-based\nfixtures.\n\nUsage\n-----\n\nTo use Flask-Fixtures in your unit tests, you'll need to make sure your\ntest class inherits from ``FixturesMixin`` and that you've specified a\nlist of fixtures files to load. The sample code below shows how to do\neach these steps.\n\nFirst, make sure the app that you're testing is initialized with the proper\nconfiguration. Then import and initialize the ``FixturesMixin`` class, create\na new test class, and inherit from ``FixturesMixin``. Now you just need to\ntell Flask-Fixtures which fixtures files to use for your tests. You can do so\nby setting the ``fixtures`` class variable. Doing so will setup and tear down\nfixtures between each test. To persist fixtures across tests, i.e., to setup\nfixtures only when the class is first created and tear them down after all\ntests have finished executing, you'll need to set the ``persist_fixtures``\nvariable to True. The ``fixtures`` variable should be set to a list of\nstrings, each of which is the name of a fixtures file to load. Flask-Fixtures\nwill then search the default fixtures directory followed by each directory in\nthe ``FIXTURES_DIRS`` config variable, in order, for a file matching each name\nin the list and load each into the test database.\n\n.. code:: python\n\n # myapp/fixtures/test_fixtures.py\n\n import unittest\n\n from myapp import app\n from myapp.models import db, Book, Author\n\n from flask_fixtures import FixturesMixin\n\n # Configure the app with the testing configuration\n app.config.from_object('myapp.config.TestConfig')\n\n\n # Make sure to inherit from the FixturesMixin class\n class TestFoo(unittest.TestCase, FixturesMixin):\n\n # Specify the fixtures file(s) you want to load.\n # Change the list below to ['authors.yaml'] if you created your fixtures\n # file using YAML instead of JSON.\n fixtures = ['authors.json']\n\n # Specify the Flask app and db we want to use for this set of tests\n app = app\n db = db\n\n # Your tests go here\n\n def test_authors(self):\n authors = Author.query.all()\n assert len(authors) == Author.query.count() == 1\n assert len(authors[0].books) == 3\n\n def test_books(self):\n books = Book.query.all()\n assert len(books) == Book.query.count() == 3\n gibson = Author.query.filter(Author.last_name=='Gibson').one()\n for book in books:\n assert book.author == gibson\n\nExamples\n--------\n\nTo see the library in action, you can find a simple Flask application\nand set of unit tests matching the ones in the example above in the\n``tests/myapp`` directory. To run these examples yourself, just follow\nthe directions below for \"Contributing to Flask-Fixtures\".\n\nContributing to Flask-Fixtures\n------------------------------\n\nCurrently, Flask-Fixtures supports python versions 2.6 and 2.7 and the\npy.test, nose, and unittest (included in the python standard library)\nlibraries. To contribute bug fixes and features to Flask-Fixtures,\nyou'll need to make sure that any code you contribute does not break any\nof the existing unit tests in any of these environments.\n\nTo run unit tests in all six of the supported environments, I suggest\nyou install `tox `__ and simply run the\n``tox`` command. If, however, you insist on running things by hand,\nyou'll need to create a virtualenv for both python 2.6 and python 2.7.\nThen, install nose and py.test in each virtualenv. Finally, you can run\nthe tests with the commands in the table below.\n\n+------------+-------------------------------------------------------+\n| Library | Command |\n+============+=======================================================+\n| py.test | py.test |\n+------------+-------------------------------------------------------+\n| nose | nosetests |\n+------------+-------------------------------------------------------+\n| unittest | python -m unittest discover --start-directory tests |\n+------------+-------------------------------------------------------+\n\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/croach/Flask-Fixtures", "keywords": "", "license": "MIT License", "maintainer": "Christopher Roach", "maintainer_email": "vthakr@gmail.com", "name": "Flask-Fixtures", "package_url": "https://pypi.org/project/Flask-Fixtures/", "platform": "any", "project_url": "https://pypi.org/project/Flask-Fixtures/", "project_urls": { "Homepage": "https://github.com/croach/Flask-Fixtures" }, "release_url": "https://pypi.org/project/Flask-Fixtures/0.3.8/", "requires_dist": [ "Flask", "Flask-SQLAlchemy", "six" ], "requires_python": "", "summary": "A simple library for adding database fixtures for unit tests using nothing but JSON or YAML.", "version": "0.3.8" }, "last_serial": 4841080, "releases": { "0.3.1": [ { "comment_text": "", "digests": { "md5": "763f842850038f86db012b4d32236f43", "sha256": "fb1cf4df913fbf2c53681c58c5085729e56122a61038a11be3c4738a8f31c1ef" }, "downloads": -1, "filename": "Flask_Fixtures-0.3.1-py2-none-any.whl", "has_sig": false, "md5_digest": "763f842850038f86db012b4d32236f43", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 12432, "upload_time": "2014-09-03T15:38:06", "url": "https://files.pythonhosted.org/packages/11/05/72c3a5da5ccaa83d620d1fcc48a0ecf6875b11a976fb6361bb08b49c72f7/Flask_Fixtures-0.3.1-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "31a818a5e66f79dce738a2a03a26b4b2", "sha256": "6e694beec133363265071ac168fb205c8dd86702a9ea787f9c35155d7a78a8cc" }, "downloads": -1, "filename": "Flask-Fixtures-0.3.1.tar.gz", "has_sig": false, "md5_digest": "31a818a5e66f79dce738a2a03a26b4b2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7910, "upload_time": "2014-09-03T15:38:04", "url": "https://files.pythonhosted.org/packages/c8/e1/39fda5f882d12ded1977ccd2bf6a8bbbd06a7d3958b67236b14df689f3db/Flask-Fixtures-0.3.1.tar.gz" } ], "0.3.2": [ { "comment_text": "", "digests": { "md5": "ca8add73de5d7f87893103bcf0720df9", "sha256": "7ee2bb2367eccc1f4fe5c27d4f3a5c7b88ca3f586a15fb6d0189a8752610b7ce" }, "downloads": -1, "filename": "Flask_Fixtures-0.3.2-py2.7.egg", "has_sig": false, "md5_digest": "ca8add73de5d7f87893103bcf0720df9", "packagetype": "bdist_egg", "python_version": "2.7", "requires_python": null, "size": 10557, "upload_time": "2015-06-22T02:02:53", "url": "https://files.pythonhosted.org/packages/2f/00/a99f4d13925ed47fbf0b3b0f46f1ba56e7102b0db1be1a5e6ca289711976/Flask_Fixtures-0.3.2-py2.7.egg" }, { "comment_text": "", "digests": { "md5": "5832892a569e7086ca0ff0f2039753f4", "sha256": "af08cc3da7605bb9d95dd460043e3693f925a083b2f320ffa0fd9e72044797b8" }, "downloads": -1, "filename": "Flask_Fixtures-0.3.2-py2-none-any.whl", "has_sig": false, "md5_digest": "5832892a569e7086ca0ff0f2039753f4", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 15836, "upload_time": "2015-06-22T02:02:49", "url": "https://files.pythonhosted.org/packages/65/8a/ba2bd5973378b449424baad76b40dabe5363d6001462768c838412551e8d/Flask_Fixtures-0.3.2-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5b1987ecb9e5e67b7ff276e67d0314f6", "sha256": "54a6518cd38280bbc881f33e66c1e9923bac56e4b01d1f56f4d8e2972bb355bf" }, "downloads": -1, "filename": "Flask-Fixtures-0.3.2.tar.gz", "has_sig": false, "md5_digest": "5b1987ecb9e5e67b7ff276e67d0314f6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9824, "upload_time": "2015-06-22T02:02:46", "url": "https://files.pythonhosted.org/packages/fb/22/6dae433df32145cab9c50073a6c3a5fd43465d0d294d9429474120308995/Flask-Fixtures-0.3.2.tar.gz" } ], "0.3.3": [ { "comment_text": "", "digests": { "md5": "8be62851bef0c74722efc29246d951df", "sha256": "2cf738bf7851512b16791b932ddf59f9be1ff7e95871c6fee18793e0cea7e36f" }, "downloads": -1, "filename": "Flask_Fixtures-0.3.3-py2.7.egg", "has_sig": false, "md5_digest": "8be62851bef0c74722efc29246d951df", "packagetype": "bdist_egg", "python_version": "2.7", "requires_python": null, "size": 10205, "upload_time": "2015-06-22T02:27:23", "url": "https://files.pythonhosted.org/packages/a5/c1/3efe6f6725176b7b7344df1bbd05ee3252bfe6d76a57ead9fd34281f6f2d/Flask_Fixtures-0.3.3-py2.7.egg" }, { "comment_text": "", "digests": { "md5": "abc892fd23cf872bd5c3658cad71ee71", "sha256": "48bd57359bc49f5f18ae6ba6dba539058f3e6f1a86ea05e3b97e6c9101016599" }, "downloads": -1, "filename": "Flask_Fixtures-0.3.3-py2-none-any.whl", "has_sig": false, "md5_digest": "abc892fd23cf872bd5c3658cad71ee71", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 15153, "upload_time": "2015-06-22T02:27:20", "url": "https://files.pythonhosted.org/packages/44/d2/e6a3260666eabeeb9e26325413fd155dc87f8398791ea1953091402b4ad8/Flask_Fixtures-0.3.3-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "75628d508a1d2deaa9e0f828b4045ae4", "sha256": "dc683b9e43602dd09017b8bd49bd055f56c39c238d018b5d3722f62f5530ca1a" }, "downloads": -1, "filename": "Flask-Fixtures-0.3.3.tar.gz", "has_sig": false, "md5_digest": "75628d508a1d2deaa9e0f828b4045ae4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10230, "upload_time": "2015-06-22T02:27:17", "url": "https://files.pythonhosted.org/packages/9c/2e/0e7346ff8485ec43bb8a49e8663becb27251b6ae74b554dc2f9515b12ba9/Flask-Fixtures-0.3.3.tar.gz" } ], "0.3.6": [ { "comment_text": "", "digests": { "md5": "0294463eff6581e732be27ede6d04ea9", "sha256": "7a03d25e3401e29ad81619994ef854a5a82a2b7d9e63533e524196b240fbc5bf" }, "downloads": -1, "filename": "Flask_Fixtures-0.3.6-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "0294463eff6581e732be27ede6d04ea9", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 15912, "upload_time": "2016-06-05T15:21:43", "url": "https://files.pythonhosted.org/packages/4b/e0/5829a94f2de1331c83232df32eeb2d01884941254d4026bb9dba8f346d89/Flask_Fixtures-0.3.6-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "11d58a7c5df1526ce19328b5185c0da4", "sha256": "0b6902af380fb741e20395259f7aabc4ab4db4c07d9ba45e74924fef76533ac4" }, "downloads": -1, "filename": "Flask-Fixtures-0.3.6.tar.gz", "has_sig": false, "md5_digest": "11d58a7c5df1526ce19328b5185c0da4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10928, "upload_time": "2016-06-05T15:21:47", "url": "https://files.pythonhosted.org/packages/df/26/41927e9d0a983d84ff6023d479aca0b475b2daa7c638e858943dab72226f/Flask-Fixtures-0.3.6.tar.gz" } ], "0.3.7": [ { "comment_text": "", "digests": { "md5": "78e4d6492c84fad50bd41e80bb166261", "sha256": "d2d05127a1af32d3da3a8d4b2847f5ab5552cb649ece8f56b8894f1870ce3b33" }, "downloads": -1, "filename": "Flask_Fixtures-0.3.7-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "78e4d6492c84fad50bd41e80bb166261", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 16136, "upload_time": "2016-06-06T01:27:09", "url": "https://files.pythonhosted.org/packages/27/53/53fd0dfc7196ee5aec7d7c7fabeaf93d7e56df7a62546d16b9bf9ce22968/Flask_Fixtures-0.3.7-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "4b414496e726adfdfc8ff8fa3fe2ef1b", "sha256": "c043e307877e28757c0fb5611c4baaed33713d4c8fa0c449d84fa767e0522f3d" }, "downloads": -1, "filename": "Flask-Fixtures-0.3.7.tar.gz", "has_sig": false, "md5_digest": "4b414496e726adfdfc8ff8fa3fe2ef1b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11082, "upload_time": "2016-06-06T01:27:13", "url": "https://files.pythonhosted.org/packages/be/6d/122d39b2851482a182b7cb05eeadeaada3c154a25cfc042a145ca339382f/Flask-Fixtures-0.3.7.tar.gz" } ], "0.3.8": [ { "comment_text": "", "digests": { "md5": "fd546f3ba7ac19f134aa74ff2ac9ef50", "sha256": "d4c5896cf0e463d8a21a56cb2cab86feea016e171a2706f38701fdb15edf6935" }, "downloads": -1, "filename": "Flask_Fixtures-0.3.8-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "fd546f3ba7ac19f134aa74ff2ac9ef50", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 12083, "upload_time": "2019-02-19T18:06:30", "url": "https://files.pythonhosted.org/packages/d8/12/6fa1ccf10d8d0680576a9196c9b5f9bdf5f932e8803416cd355b846e1111/Flask_Fixtures-0.3.8-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e8f85c0ae050509842b2ff14639208c9", "sha256": "2b8191f995896c0dee384b18b0ee236ab636b921856636c9ff1429c1ad10cb8b" }, "downloads": -1, "filename": "Flask-Fixtures-0.3.8.tar.gz", "has_sig": false, "md5_digest": "e8f85c0ae050509842b2ff14639208c9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13750, "upload_time": "2019-02-19T18:06:31", "url": "https://files.pythonhosted.org/packages/0c/51/f6a30e04b094c0657d66852183550c9ca708c1d2416d53a528dfad818efc/Flask-Fixtures-0.3.8.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "fd546f3ba7ac19f134aa74ff2ac9ef50", "sha256": "d4c5896cf0e463d8a21a56cb2cab86feea016e171a2706f38701fdb15edf6935" }, "downloads": -1, "filename": "Flask_Fixtures-0.3.8-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "fd546f3ba7ac19f134aa74ff2ac9ef50", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 12083, "upload_time": "2019-02-19T18:06:30", "url": "https://files.pythonhosted.org/packages/d8/12/6fa1ccf10d8d0680576a9196c9b5f9bdf5f932e8803416cd355b846e1111/Flask_Fixtures-0.3.8-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e8f85c0ae050509842b2ff14639208c9", "sha256": "2b8191f995896c0dee384b18b0ee236ab636b921856636c9ff1429c1ad10cb8b" }, "downloads": -1, "filename": "Flask-Fixtures-0.3.8.tar.gz", "has_sig": false, "md5_digest": "e8f85c0ae050509842b2ff14639208c9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13750, "upload_time": "2019-02-19T18:06:31", "url": "https://files.pythonhosted.org/packages/0c/51/f6a30e04b094c0657d66852183550c9ca708c1d2416d53a528dfad818efc/Flask-Fixtures-0.3.8.tar.gz" } ] }