{"id":16525754,"url":"https://github.com/zx80/flask-tester","last_synced_at":"2026-05-15T19:31:28.626Z","repository":{"id":227076602,"uuid":"769867777","full_name":"zx80/flask-tester","owner":"zx80","description":"FlaskTester - Pytest fixtures for Flask internal and external authenticated tests","archived":false,"fork":false,"pushed_at":"2026-02-24T07:28:18.000Z","size":153,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-24T13:45:48.892Z","etag":null,"topics":["authentication","flask","pytest"],"latest_commit_sha":null,"homepage":"https://zx80.github.io/flask-tester/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zx80.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-03-10T09:44:19.000Z","updated_at":"2026-02-24T07:28:23.000Z","dependencies_parsed_at":"2024-03-27T11:26:02.574Z","dependency_job_id":"fe7ae7fc-4971-46f7-b7dc-04e6226f95f4","html_url":"https://github.com/zx80/flask-tester","commit_stats":null,"previous_names":["zx80/flask-tester"],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/zx80/flask-tester","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zx80%2Fflask-tester","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zx80%2Fflask-tester/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zx80%2Fflask-tester/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zx80%2Fflask-tester/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zx80","download_url":"https://codeload.github.com/zx80/flask-tester/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zx80%2Fflask-tester/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33076154,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-15T11:35:32.926Z","status":"ssl_error","status_checked_at":"2026-05-15T11:35:31.362Z","response_time":103,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["authentication","flask","pytest"],"created_at":"2024-10-11T17:06:31.621Z","updated_at":"2026-05-15T19:31:28.607Z","avatar_url":"https://github.com/zx80.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FlaskTester - Pytest fixtures for Flask internal and external authenticated tests\n\nThis package allows to run authenticated tests against a Flask application,\neither with internal Flask tests (aka `test_client`) or external tests (with\n`requests` which performs actual HTTP requests), including password and token\nauthentication and per-user cookies.\n\nOnly one set of tests is needed, switching from internal to external is\nachieved by setting an environment variable.\n\n![Status](https://github.com/zx80/flask-tester/actions/workflows/package.yml/badge.svg?branch=main\u0026style=flat)\n![Tests](https://img.shields.io/badge/tests-16%20✓-success)\n![Coverage](https://img.shields.io/badge/coverage-100%25-success)\n![Issues](https://img.shields.io/github/issues/zx80/flask-tester?style=flat)\n![Python](https://img.shields.io/badge/python-3-informational)\n![Version](https://img.shields.io/pypi/v/FlaskTester)\n![Badges](https://img.shields.io/badge/badges-8-informational)\n![License](https://img.shields.io/pypi/l/flasktester?style=flat)\n\n## Usage\n\nInstall package with `pip install FlaskTester` or equivalent.\n\nThe following test creates a local fixture with 2 users identified by a\npassword, and retrieves tokens for both users using a `/login` route\nprovided by the application.\nIt then proceeds to run authenticated requests against the `/admin` route.\n\n```python\nimport pytest\nfrom FlaskTester import ft_authenticator, ft_client\nimport secret\n\ndef authHook(api, user: str, pwd: str|None):\n    if pwd is not None:  # get a token when a login/password is provided\n        res = api.get(\"/login\", login=user, auth=\"basic\", status=200)\n        api.setToken(user, res.json[\"token\"])\n    else:  # remove token\n        api.setToken(user, None)\n\n@pytest.fixture\ndef app(ft_client):\n    # register authentication hook\n    ft_client.setHook(authHook)\n    # add test passwords for Calvin and Hobbes (must be consistent with app!)\n    ft_client.setPass(\"calvin\", secret.PASSES[\"calvin\"])\n    ft_client.setPass(\"hobbes\", secret.PASSES[\"hobbes\"])\n    # also set a cookie\n    ft_client.setCookie(\"hobbes\", \"lang\", \"fr\")\n    ft_client.setCookie(\"calvin\", \"lang\", \"en\")\n    # return working client\n    yield ft_client\n\ndef test_app_admin(app):\n    app.get(\"/admin\", login=None, status=401)\n    for auth in [\"bearer\", \"basic\", \"param\"]:\n        res = app.get(\"/admin\", login=\"calvin\", auth=auth, status=200)\n        assert res.json[\"user\"] == \"calvin\" and res.json[\"isadmin\"]\n        res = app.get(\"/admin\", login=\"hobbes\", auth=auth, status=403)\n        assert 'not in group \"ADMIN\"' in res.text\n```\n\nThis can be run against a local or remote server:\n\n```shell\nexport TEST_SEED=\"some-random-data\"              # shared test seed\nflask --app app:app run \u0026                        # start flask app\npid=$!                                           # keep pid\nexport FLASK_TESTER_APP=\"http://localhost:5000\"  # set app url, local or remote\npytest test.py                                   # run external tests\nkill $pid                                        # stop app with pid\n```\n\nOr locally with the Flask internal test infrastructure:\n\n```shell\nexport FLASK_TESTER_APP=\"app:app\"                # set app package\npytest test.py                                   # run internal tests\n```\n\nThe above test runs with [`tests/app.py`](tests/app.py)\n[Flask](https://flask.palletsprojects.com/)\nREST application back-end with password and token authentication based on\n[FlaskSimpleAuth](https://pypi.org/project/FlaskSimpleAuth/).\nThe code uses _23_ lines of Python for implementing\npassword (basic and parameters) and token authentications,\nadmin group authorization, and routes for\ntoken generation (2), identity tests (2) and an incredible open cookie-based\ntranslation service.\n\nSee the [documentation](https://zx80.github.io/flask-tester/).\n\n## License\n\nThis code is [Public Domain](https://creativecommons.org/publicdomain/zero/1.0/).\n\nAll software has bug, this is software, hence… Beware that you may lose your\nhairs or your friends because of it. If you like it, feel free to send a\npostcard to the author.\n\n## Versions\n\nPackages are distributed from [PyPI](https://pypi.org/project/FlaskTester/),\n[sources](https://github.com/zx80/flask-tester) are available on GitHub,\nplease report any [issues](https://github.com/zx80/flask-tester/issues).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzx80%2Fflask-tester","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzx80%2Fflask-tester","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzx80%2Fflask-tester/lists"}