{ "info": { "author": "Infrae", "author_email": "info@infrae.com", "bugtrack_url": null, "classifiers": [ "Framework :: Zope2", "License :: OSI Approved :: BSD License", "Programming Language :: Python", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "==============\ninfrae.testing\n==============\n\n``infrae.testing`` defines sanes tests layers for testing in Zope 2, to\nuse in conjunction with `zope.testing`_.\n\n.. contents::\n\nAPI\n===\n\nIt defines:\n\n- A ``ZMLLayer`` which load a ZCML file before your test, and clean\n up after,\n\n- A ``Zope2Layer`` which setup a Zope 2 test instance in a layer.\n\n You can customize the layer setup to add your tested application\n (like to create a Portal instance).\n\n If you define the shell environment variable ``SETUP_CACHE`` while\n running the tests, this last setup step will be cached in a\n FileSystem Storage. This makes it reusable between different testing\n sessions, and let you save a considerable amount of time while\n running your tests. Of course don't use the cache if you changed how\n you installed your application.\n\n By default it provides a environment which is exactly equivalent to\n the one provided by a real running Zope 2 instance (with all VHM,\n session support, temp_folder ...).\n\n If you compare it to the code of the ``Testing`` module in Zope 2,\n it does the same thing, but it is simpler (and so readable), provides\n an environment which match more a running one and is faster (as you can\n cache the setup operation).\n\n Every test is run in a separate DemoStorage (installed on top of the\n storage providing the installed application).\n\n- A TestCase base class that provides a bit more of assert methods:\n\n ``assertTriggersEvents(*events)``\n Context manager that will assert that the events with the given\n names have been triggered.\n\n ``assertNotTriggersEvents(*events)``\n Context manager that will assert that the events with the given\n names have not been triggered.\n\n ``assertEventsAre(events, interface=None)``\n Will assert that the event tiggered up until now are the one\n with the names in the given list. You can if you want restrict\n those events to the one implementing the given interface.\n\n ``assertContentEqual(c1, c2)``\n Will assert that both Zope object are the same.\n\n ``assertContentItemsEqual(l1, l2)``\n Will assert that both list contains the same Zope objects. The\n order is not important.\n\n ``assertHashEqual(s1, s2)``\n Will assert that both md5 hash of the given string are\n equal. This is useful when comparing two large string, and that\n you wish to have readable output error message.\n\n ``assertStringEqual(s1, s2)``\n Will assert that stripped version of both given strings are the same.\n\n ``assertEventsAre(events, interface=None)``\n Will assert that the triggered events are the ones whose names\n are specified in the given list argument. You can restrict events\n to match to those who implements at least the given interface.\n\n ``assertXMLEqual(xml1, xml2)``\n Will assert that both given XML strings have the same structure\n and data. The XML strings will be indented and after compared\n between them. In case of differences, the error will only report\n a diff between the indented XML strings.\n Of course don't use this method if you wish to compare two XML\n strings where spaces matters.\n\n An ``xmlindent`` script can be installed out of this package\n that indent the XML code exactly like the ``assertXMLEqual``\n method does.\n\n- A ``TestMethods`` class that will provide you access to the assert\n methods without the need of a test case. This gives you access to\n all the default assert methods of the ``unittest.TestCase`` and the\n ones documented above.\n\n- The ``suite_from_package`` function will construct a\n ``unittest.TestSuite`` out of files found in a package. A ``*.txt``\n file will create ``DocFileSuite``, and a ``*.py`` will create a\n ``DocTestSuite``. Other type of test files can be plugged in.\n\nIf you use the ``ZCMLLayer`` or ``Zope2Layer``, you have two different\ncallbacks registry you can use:\n\n- ``testCleanUp`` that is called after each test,\n\n- ``layerCleanUp`` that is called after each layer.\n\nThose callbacks registry have an ``add`` method that can be used in\norder to register a new cleanup function::\n\n from infrae.testing import testCleanUp\n\n testCleanUp.add(my_cleanup_function)\n\n\nExamples\n========\n\nZCMLLayer\n---------\n\nA example to test a package called ``corp.testpackage``. The package\nas a ``ftesting.zcml`` file which should mainly load its own\n``configure.zcml``::\n\n import unittest\n\n from infrae.testing import ZCMLLayer\n import corp.testpackage\n\n layer = ZCMLLayer(corp.testpackage)\n\n\n class MyTestCase(unittest.TestCase):\n\n layer = layer\n\nThe layer provides you a ``grok()`` method that can be used to grok a\nmodule in your test later on.\n\n\nZope2Layer\n----------\n\nNow our ``corp.testpackage`` is a Zope 2 extension providing some\ncontent. We want to test it installed::\n\n import unittest\n\n from infrae.testing import ZCMLLayer\n import corp.testpackage\n\n\n class CorpLayer(Zope2Layer):\n \"\"\"Add some installation tasks to the Zope2Layer.\n \"\"\"\n default_products = Zope2Layer.default_products + ['CMFCore']\n default_packages = Zope2Layer.default_packages + ['corp.testpackage']\n default_users = Zope2Layer.default_users + {'corp_user': 'CorpRole'}\n\n def _install_application(self, app):\n factory = app.manage_addProduct['corp.testpackage']\n factory.manage_addCorpPortal('portal')\n\n layer = CorpLayer(corp.testpackage)\n\n\n class MyTestCase(unittest.TestCase):\n\n layer = layer\n\n def setUp(self):\n self.root = self.layer.get_application()\n self.layer.login('corp_user')\n\n\nOf course your ZCML *must* include the ZCML of your package\ndependencies. As well we don't recommend to add ``Five`` in the layer\nas a ``default_products``, it goes crazy (but include it in your ZCML\n!).\n\nThe layer provides you the following useful methods:\n\n``login(username)``\n Log as a the given username.\n\n``logout()``\n Logout.\n\n``get_root_folder()``\n Return the root of the database, *not* wrapped in a request.\n\n``get_application()``\n Return the root of the database, wrapped in a request.\n\nCode\n====\n\nThe code is available through a Mercurial repository at:\nhttps://hg.infrae.com/infrae.testing\n\n\n.. _zope.testing: http://pypi.python.org/pypi/zope.testing\n\nChanges\n=======\n\n1.3 (2012-09-03)\n----------------\n\n- ``suite_from_package`` is now more generic. Other test file types can\n be plugged in to this discovery function.\n\n- Add two different sets of callback for cleanup: one after each test,\n one after each layer. This add more possibilities than the default\n set of callbacks provided by zope.testing.\n\n- Refactor Zope events helpers, and test methods, to be more generic.\n\n- Add a class with all the test methods defined in a testcase. This\n makes possible to use the test methods without having a testcase.\n\n1.2 (2011-11-07)\n----------------\n\n- Update for Python 2.7 and Zope 2 2.13.\n\n1.1 (2010-10-07)\n----------------\n\n- Add two context managers: assertTriggersEvents and\n assertNotTriggersEvents for event testing.\n\n- In Zope2 request container, default hostname is `localhost`, not\n `foo`.\n\n- Fix the option ``SETUP_CACHE`` when reloading databases (didn't work\n because of the Zope2 Session container setup code).\n\n\n1.0 (2010-07-14)\n----------------\n\n- Initial release.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://infrae.com/products/silva", "keywords": "silva cms zope security", "license": "BSD", "maintainer": null, "maintainer_email": null, "name": "infrae.testing", "package_url": "https://pypi.org/project/infrae.testing/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/infrae.testing/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://infrae.com/products/silva" }, "release_url": "https://pypi.org/project/infrae.testing/1.3/", "requires_dist": null, "requires_python": null, "summary": "Define some sane tests layers in Zope 2", "version": "1.3" }, "last_serial": 945370, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "40e03969cba9852bcf12858da135749e", "sha256": "2bc4c782a6599a28c8b7f41b98a6cb979c69de050729192ca9823d49f33f2493" }, "downloads": -1, "filename": "infrae.testing-1.0.tar.gz", "has_sig": false, "md5_digest": "40e03969cba9852bcf12858da135749e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9429, "upload_time": "2010-07-15T17:43:05", "url": "https://files.pythonhosted.org/packages/98/d2/dc74e51c1a60b608ced019c9163d9582287495014188614448588c76f060/infrae.testing-1.0.tar.gz" } ], "1.1": [ { "comment_text": "", "digests": { "md5": "b6a17286381c1f2b02e9c2b498cfb5cb", "sha256": "54ce33741a7e485ac5d78c8baf4922f3d18a2f5b0e4258f5399bd4f400bbdcff" }, "downloads": -1, "filename": "infrae.testing-1.1.tar.gz", "has_sig": false, "md5_digest": "b6a17286381c1f2b02e9c2b498cfb5cb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10317, "upload_time": "2010-10-07T11:09:03", "url": "https://files.pythonhosted.org/packages/9b/b2/b9aaa829eddee9909b3583ed0dfcd2c98afb4731aa6f1b1224e5f6174765/infrae.testing-1.1.tar.gz" } ], "1.2": [ { "comment_text": "", "digests": { "md5": "e74ac63a6953d286580d39e7586066eb", "sha256": "729210098b4de18b7a52908a8af2650bb9b6ac7894a2ceaeac36fdf9997505dd" }, "downloads": -1, "filename": "infrae.testing-1.2.tar.gz", "has_sig": false, "md5_digest": "e74ac63a6953d286580d39e7586066eb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10133, "upload_time": "2011-11-07T14:16:25", "url": "https://files.pythonhosted.org/packages/25/b9/77d0bbd2aef10db39063fece10b1685aa593307e0bcb092eedf0065a0d6b/infrae.testing-1.2.tar.gz" } ], "1.3": [ { "comment_text": "", "digests": { "md5": "e494906b92f0d71c443f91cde5bd0f3e", "sha256": "a020f7ee3541070e91adcd7d06fe2243c9a7f94e8a75fa2c5902a2ce7c8073fb" }, "downloads": -1, "filename": "infrae.testing-1.3.tar.gz", "has_sig": false, "md5_digest": "e494906b92f0d71c443f91cde5bd0f3e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18958, "upload_time": "2012-09-03T14:36:10", "url": "https://files.pythonhosted.org/packages/66/ab/6c968504fcc1ebff26e16d489b4bf402d18122d3828c79082b4555150606/infrae.testing-1.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "e494906b92f0d71c443f91cde5bd0f3e", "sha256": "a020f7ee3541070e91adcd7d06fe2243c9a7f94e8a75fa2c5902a2ce7c8073fb" }, "downloads": -1, "filename": "infrae.testing-1.3.tar.gz", "has_sig": false, "md5_digest": "e494906b92f0d71c443f91cde5bd0f3e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18958, "upload_time": "2012-09-03T14:36:10", "url": "https://files.pythonhosted.org/packages/66/ab/6c968504fcc1ebff26e16d489b4bf402d18122d3828c79082b4555150606/infrae.testing-1.3.tar.gz" } ] }