{ "info": { "author": "Christo Crampton", "author_email": "info@38.co.za", "bugtrack_url": null, "classifiers": [ "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "> A mechanism for running processes which might have side effects (e.g.: calling an external API etc.) in a way that is safe by default during testing and provides useful introspection functionality.\n\n[![PyPI version](https://badge.fury.io/py/dj-saferunner.svg)](https://badge.fury.io/py/dj-saferunner)\n\nIt will: Run a list of tasks. If possible, it will run them asyncronously\n\nIn `TEST_MODE`:\n\n* It will not run the code\n* It will store information about the calls made in\n\n\n## Usage\n\n### Install and configure\n\n```\npip install dj-saferunner\n```\n\n### Config options\n\n**Django settings**\n\n`SAFERUNNER_USE_SENTRY` - set to `True` to swallow errors and log to Sentry\n\n### In your code:\n\n**before**\n\n```python\nfrom myapp.tasks import ping_google\nping_google(url='http://foo.com')\n```\n\n**after**\n\n```python\nfrom myapp.tasks import ping_google\nfrom saferunner.process_runner import safely_run_processes\ntask_list = [\n # task, args, async\n (ping_google, {\"url\", \"http://foo.com\"}, False)\n]\nsafely_run_processes(\n run_id='identifier giving some context about where this is run',\n task_list=task_list\n)\n```\n\n### In your tests\n\nWhen in test mode, by default the saferunner will not execute your code. Instead it will log your calls using django's cache\n\n**example test**\n\n```python\ndef test_run_some_tasks(self):\n clear_run_cache()\n run_id = 'this_is_a_test'\n task_list = [\n (hello, {\"msg\": \"hi\"} , False),\n (do_something_slowly, {\"sleep\": 10}, True),\n ]\n safely_run_processes(\n run_id = run_id,\n task_list = task_list\n )\n res = get_process_run(run_id)\n```\n\nThe results of `get_process_run` would look something like this:\n\n```\n[{\n\t'task_name': 'hello',\n\t'task_args': \"OrderedDict([('msg', 'hi')])\",\n\t'is_async': False\n}, {\n\t'task_name': 'do_something_slowly',\n\t'task_args': \"OrderedDict([('sleep', 10)])\",\n\t'is_async': True\n}]\n```\n\n#### Explicitly running side effect code\n\n> In your tests, You can force `saferunner` to execute safely run code.\n\nYou might want to do this, for example, if you want to test code inside your function from a higher level.\nIdeally you should not really need to do this too often. We would recommend that it is preferred to test your\nfunctions by calling them directly (as opposed to checking for side effects in a higher level function)\n\n**Run all side effect code:**\n\nWill essentially turn `saferunner` off for this test\n\n```\n@override_settings(FORCE_RUN_SIDE_EFFECTS='__all__')\n```\n\n**You can also specify a specific task to pass through:**\n\nThis will force `saferunner` to explicitly run this exact function/method\n\n```\n@override_settings(FORCE_RUN_SIDE_EFFECTS=task.name)\n@override_settings(FORCE_RUN_SIDE_EFFECTS=task.__name__)\n```\n\n## FAQ:\n\nQ: Why not just use mocks?\nA:\nThe use-case for this is for code that might get executed often\n(for example code in signals), and which might have unwanted\nside-effects if accidentally run durung tests (e.g.: send SMSes or making API calls).\nWe want to err on the side of caution here and mock by default during testing\nand be explicit about when we want to run this code\n\nPS: DHH would probably call this test induced damage!\n\n## TODO\n\n* Make it work Class methods", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://gitlab.com/schoolorchestration/libs/dj-saferunner", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "dj-saferunner", "package_url": "https://pypi.org/project/dj-saferunner/", "platform": "", "project_url": "https://pypi.org/project/dj-saferunner/", "project_urls": { "Homepage": "https://gitlab.com/schoolorchestration/libs/dj-saferunner" }, "release_url": "https://pypi.org/project/dj-saferunner/0.0.2/", "requires_dist": null, "requires_python": "", "summary": "", "version": "0.0.2" }, "last_serial": 5497613, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "c50599e8c3ea1e7e57d3ef1a1877cf48", "sha256": "fc41092b60054f911c6330835733244b2db3f94f30d78db87de3dd289ab5f020" }, "downloads": -1, "filename": "dj-saferunner-0.0.1.tar.gz", "has_sig": false, "md5_digest": "c50599e8c3ea1e7e57d3ef1a1877cf48", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4397, "upload_time": "2019-07-07T16:54:32", "url": "https://files.pythonhosted.org/packages/0b/65/05f43f2504dbbecb7bbb7c9cdb34c854598075fe054d05052cfa947ead35/dj-saferunner-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "a895b30adffa42d18f29629e3a901564", "sha256": "f2fddae12798efc26333dce8615a7e834fd368e52494e6a9d8af4e7019e91fe9" }, "downloads": -1, "filename": "dj-saferunner-0.0.2.tar.gz", "has_sig": false, "md5_digest": "a895b30adffa42d18f29629e3a901564", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4727, "upload_time": "2019-07-07T17:28:56", "url": "https://files.pythonhosted.org/packages/90/4a/2fa25c4b15c308ad4dbf141ba2d5e32d807c1934b924705613ff98ea1d1b/dj-saferunner-0.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a895b30adffa42d18f29629e3a901564", "sha256": "f2fddae12798efc26333dce8615a7e834fd368e52494e6a9d8af4e7019e91fe9" }, "downloads": -1, "filename": "dj-saferunner-0.0.2.tar.gz", "has_sig": false, "md5_digest": "a895b30adffa42d18f29629e3a901564", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4727, "upload_time": "2019-07-07T17:28:56", "url": "https://files.pythonhosted.org/packages/90/4a/2fa25c4b15c308ad4dbf141ba2d5e32d807c1934b924705613ff98ea1d1b/dj-saferunner-0.0.2.tar.gz" } ] }