{"id":21306382,"url":"https://github.com/davidemoro/play_requests","last_synced_at":"2025-07-11T21:31:31.482Z","repository":{"id":57453367,"uuid":"116274490","full_name":"davidemoro/play_requests","owner":"davidemoro","description":"pytest-play plugin driving the famous python requests library for making HTTP calls","archived":false,"fork":false,"pushed_at":"2019-04-08T06:48:28.000Z","size":75,"stargazers_count":7,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2025-04-06T09:23:37.601Z","etag":null,"topics":["api","http","pytest","python","requests","testing"],"latest_commit_sha":null,"homepage":"https://github.com/pytest-dev/pytest-play","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davidemoro.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.rst","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-04T15:12:59.000Z","updated_at":"2024-11-28T09:21:22.000Z","dependencies_parsed_at":"2022-08-29T06:51:26.328Z","dependency_job_id":null,"html_url":"https://github.com/davidemoro/play_requests","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/davidemoro/play_requests","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidemoro%2Fplay_requests","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidemoro%2Fplay_requests/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidemoro%2Fplay_requests/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidemoro%2Fplay_requests/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidemoro","download_url":"https://codeload.github.com/davidemoro/play_requests/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidemoro%2Fplay_requests/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264902388,"owners_count":23681057,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","http","pytest","python","requests","testing"],"created_at":"2024-11-21T16:23:33.629Z","updated_at":"2025-07-11T21:31:31.097Z","avatar_url":"https://github.com/davidemoro.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"=============\nplay requests\n=============\n\n\n.. image:: https://img.shields.io/pypi/v/play_requests.svg\n        :target: https://pypi.python.org/pypi/play_requests\n\n.. image:: https://travis-ci.org/davidemoro/play_requests.svg?branch=develop\n       :target: https://travis-ci.org/davidemoro/play_requests\n\n.. image:: https://readthedocs.org/projects/play-requests/badge/?version=latest\n        :target: https://play-requests.readthedocs.io/en/latest/?badge=latest\n        :alt: Documentation Status\n\n.. image:: https://codecov.io/gh/davidemoro/play_requests/branch/develop/graph/badge.svg\n     :target: https://codecov.io/gh/davidemoro/play_requests\n\n\npytest-play plugin driving the famous Python requests_ library for making ``HTTP`` calls.\n\nMore info and examples on:\n\n* pytest-play_, documentation\n* cookiecutter-qa_, see ``pytest-play`` in action with a working example if you want to start hacking\n\n\nFeatures\n--------\n\nThis pytest-play_ command provider let you drive a\nPython requests_ HTTP library using a YAML configuration file\ncontaining a set of pytest-play_ commands.\n\nyou can see a pytest-play_ script powered by a command provided\nby the play_requests_ plugin:\n\n::\n\n    - provider: play_requests\n      type: GET\n      assertion: \"'pytest-play' in response.json()\"\n      url: https://www.google.it/complete/search\n      parameters:\n        headers:\n          Host: www.google.it\n          User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101\n            Firefox/57.0\n          Accept: \"*/*\"\n          Accept-Language: en-US,en;q=0.5\n          Referer: https://www.google.it/\n          Connection: keep-alive\n        params:\n        - - client\n          - psy-ab\n        - - hl\n          - it\n        - - gs_rn\n          - '64'\n        - - gs_ri\n          - psy-ab\n        - - gs_mss\n          - pytest-\n        - - cp\n          - '11'\n        - - gs_id\n          - '172'\n        - - q\n          - pytest-play\n        - - xhr\n          - t\n        timeout: 2.5\n\n\nThe above example:\n\n* performs a GET call to https://www.google.it/complete/search?client=psy-ab\u0026hl=it\u0026... \n  with the provided headers, a timeout (if it takes more than 2.5 seconds a timeout\n  exception will be raised) and an assertion expression that verifies that the response\n  meets the expected value\n\nplay_requests_ supports all the HTTP verbs supported by the requests_ library:\n\n* OPTIONS\n* HEAD\n* GET\n* POST\n* PUT\n* PATCH\n* DELETE\n\nYou'll find other play_requests_ command examples in the following sections.\n\nAuthentication cookies\n======================\n\nManages cookies and prepare them for you so you don't have to create\ncookie headers by yourself using the ``auth=('username', 'password')``::\n\n    - provider: play_requests\n      type: GET\n      url: http://something/authenticated\n      parameters:\n        auth:\n          - username\n          - password\n\nUpload files\n============\n\nPost a csv file::\n\n    - provider: play_requests\n      type: POST\n      url: http://something/1\n      parameters:\n        files:\n          filecsv:\n          - report.csv\n          - some,data\n\nPost a csv file with custom headers::\n\n    - provider: play_requests\n      type: POST\n      url: http://something/1\n      parameters:\n        files:\n          filecsv:\n          - report.csv\n          - some,data\n          - application/csv\n          - Expires: '0'\n\nPost a file providing the path::\n\n    - provider: play_requests\n      type: POST\n      url: http://something/1\n      parameters:\n        files:\n          filecsv:\n          - file.csv\n          - path:$base_path/file.csv\n\nassuming that you have a ``$base_path`` variable.\n\nSave the response to a variable\n===============================\n\nYou can save a response elaboration to a pytest-play_ variable\nand reuse in the following commands::\n\n    - provider: play_requests\n      type: POST\n      url: http://something/1\n      variable: myvar\n      variable_expression: response.json()\n      assertion: variables['myvar']['status'] == 'ok'\n      parameters:\n        json:\n          foo: bar\n        timeout: 2.5\n\nIt the endpoint returns a non JSON response, use ``response.text`` instead.\n\nDefault payload\n===============\n\nIf all your requests have a common payload it might be annoying\nbut thanks to play_requests_ you can avoid repetitions.\n\nYou can set variables in many ways programatically using the pytest-play_\nexecute command or execute commands. You can also update variables using\nthe play_python_ ``exec`` command::\n\n    - provider: python\n      type: store_variable\n      name: bearer\n      expression: \"'BEARER'\"\n    - provider: python\n      type: store_variable\n      name: play_requests\n      expression: \"{'parameters': {'headers': {'Authorization': '$bearer'}}}\"\n    - provider: play_requests\n      type: GET\n      url: \"$base_url\"\n\nand all the following HTTP calls will be performed with the authorization bearer provided in the default\npayload.\n\nMerging rules:\n\n* if a play_requests_ command provides any other header value, the resulting HTTP call will be performed\n  with merged header values (eg: ``Authorization`` + ``Host``)\n* if a play_requests_ command provides a conflicting header value or any other default option,\n  the ``Authorization`` header provided by the command will win and it will override just for the current\n  call the default conflicting header value\n\nAssert response status code\n===========================\n\n::\n\n    - provider: play_requests\n      type: POST\n      url: http://something/1\n      variable: myvar\n      variable_expression: response.json()\n      assertion: response.status_code == 200\n      parameters:\n        json:\n          foo: bar\n\nof if you want you can use the expression ``response.raise_for_status()`` instead of\nchecking the exact match of status code.\n\nThe ``raise_for_status`` call will raise an ``HTTPError`` if the ``HTTP`` request\nreturned an unsuccessful status code.\n\n\nPost raw data\n=============\n\nIf you want to send some POST data or send a JSON payload without automatic JSON encoding::\n\n    - provider: play_requests\n      type: POST\n      url: http://something/1\n      parameters:\n        data: '{\"foo\"  : \"bar\"    }'\n\nRedirections\n============\n\nBy default requests_ will perform location redirection for all verbs\nexcept HEAD:\n\n* http://docs.python-requests.org/en/master/user/quickstart/#redirection-and-history\n\nYou can disable or enable redirects playing with the ``allow_redirects`` option::\n\n    - provider: play_requests\n      type: POST\n      url: http://something/1\n      variable: myvar\n      variable_expression: response.json()\n      assertion: response.status_code == 200\n      parameters:\n        allow_redirects: false\n        json:\n          foo: bar\n\nTwitter\n-------\n\n``pytest-play`` tweets happens here:\n\n* `@davidemoro`_\n\nCredits\n-------\n\nThis package was created with Cookiecutter_ and the cookiecutter-play-plugin_ (based on `audreyr/cookiecutter-pypackage`_ project template).\n\n.. _Cookiecutter: https://github.com/audreyr/cookiecutter\n.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage\n.. _`cookiecutter-play-plugin`: https://github.com/davidemoro/cookiecutter-play-plugin\n.. _pytest-play: https://github.com/davidemoro/pytest-play\n.. _cookiecutter-qa: https://github.com/davidemoro/cookiecutter-qa\n.. _requests: http://docs.python-requests.org/en/master/user/quickstart\n.. _play_requests: https://play_requests.readthedocs.io/en/latest\n.. _play_python: https://play_python.readthedocs.io/en/latest\n.. _`@davidemoro`: https://twitter.com/davidemoro\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidemoro%2Fplay_requests","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidemoro%2Fplay_requests","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidemoro%2Fplay_requests/lists"}