{"id":10566596,"url":"https://github.com/Ori-Roza/drf-api-action","last_synced_at":"2025-09-11T19:32:10.538Z","repository":{"id":177621283,"uuid":"656999754","full_name":"Ori-Roza/drf-api-action","owner":"Ori-Roza","description":"drf-api-action elevates Django Rest Framework testing with the action_api fixture, simplifying REST endpoint testing to a seamless, function-like experience.","archived":false,"fork":false,"pushed_at":"2024-05-12T14:18:23.000Z","size":1336,"stargazers_count":99,"open_issues_count":3,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-02T00:51:49.434Z","etag":null,"topics":["api","backend","decorators","django","django-rest-framework","django-test","django-testing","pytest","pytest-fixtures","python","testing","unit-testing","webdevelopment"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Ori-Roza.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"docs/CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":"docs/CODE_OF_CONDUCT.md","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}},"created_at":"2023-06-22T05:17:03.000Z","updated_at":"2024-12-18T02:17:05.000Z","dependencies_parsed_at":"2023-12-24T08:31:57.499Z","dependency_job_id":"931843e0-d740-4049-bc5a-da0986b5574f","html_url":"https://github.com/Ori-Roza/drf-api-action","commit_stats":null,"previous_names":["ori-roza/drf-api-action"],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ori-Roza%2Fdrf-api-action","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ori-Roza%2Fdrf-api-action/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ori-Roza%2Fdrf-api-action/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ori-Roza%2Fdrf-api-action/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ori-Roza","download_url":"https://codeload.github.com/Ori-Roza/drf-api-action/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232663829,"owners_count":18557668,"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","backend","decorators","django","django-rest-framework","django-test","django-testing","pytest","pytest-fixtures","python","testing","unit-testing","webdevelopment"],"created_at":"2024-06-01T08:20:04.609Z","updated_at":"2025-01-06T02:30:19.878Z","avatar_url":"https://github.com/Ori-Roza.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"![Alt text](resources/drf-api-action-banner-current.png?raw=true \"\")\n\n[![codecov](https://codecov.io/gh/Ori-Roza/drf-api-action/graph/badge.svg?token=2PB7NG8A4W)](https://codecov.io/gh/Ori-Roza/drf-api-action)\n[![python - 3.8 | 3.9 | 3.10 | 3.11](https://img.shields.io/badge/python-3.8_|_3.9_|_3.10_|_3.11-blue)](https://)[![CI](https://github.com/Ori-Roza/drf-api-action/actions/workflows/tests.yaml/badge.svg?branch=master)](https://github.com/Ori-Roza/drf-api-action/actions/workflows/tests.yaml)\n[![license - MIT](https://img.shields.io/badge/license-MIT-yellow)](https://)\n\n\nThe drf-api-action Python package is designed to elevate your testing experience for Django Rest Framework (DRF) REST endpoints.\nWith the api_action fixture, this package empowers you to effortlessly test your REST endpoints as if they were conventional functions.\n\nFeatures:\n\n* **Simplified Testing:** Testing DRF REST endpoints using the api_action plugin, treating them like regular functions.\n\n* **Seamless Integration:** you don't need to do anything in existing server code.\n\n* **Easy Debugging:** Instead of getting a response with error code by using default drf testing `client` object , get the real traceback that led to the error.\n\n* **Pagination Support**: Paginating easily through pages by using `page` argument.\n\n\n## Installation\n\nYou can install `drf-api-action` using pip:\n\n```shell\npip install drf-api-action\n```\n\n## Usage\n\n### To use `drf-api-action` as a Pytest fixture, you need to follow these steps:\n\n#### Step 1: Import your Viewsets explicitly:\n\n```python\nimport pytest\nfrom tests.test_server.test_app.models import DummyModel\nfrom tests.test_server.test_app.views import DummyViewSetFixture\n```\n\n#### Step 2: use the following action_api mark decorator:\n\n`@pytest.mark.api_action(view_set_class={YOUR VIEW_SET})`\n\ne.g:\nour ViewSet is called `DummyViewSetFixture`\n\n```python\nimport pytest\nfrom tests.test_server.test_app.views import DummyViewSetFixture\n\n\n@pytest.mark.api_action(view_set_class=DummyViewSetFixture)\ndef test_call_as_api_fixture(db, api_action):\n  pass\n```\nNow you can use all `DummyViewSetFixture` functionality!\n\n#### Step 3: write your tests\n\ne.g:\nour ViewSet is called `DummyViewSetFixture`\n\n```python\nimport pytest\nfrom tests.test_server.test_app.models import DummyModel\nfrom tests.test_server.test_app.views import DummyViewSetFixture\n\n\n@pytest.mark.api_action(view_set_class=DummyViewSetFixture)\ndef test_call_as_api_fixture(db, api_action):\n  dummy_model = DummyModel()\n  dummy_model.dummy_int = 1\n  dummy_model.save()\n  res = api_action.api_dummy(pk=1)\n  assert res[\"dummy_int\"] == 1\n\n```\nHere as an example, the real exception and trace will be thrown, make it easy to understand what the issue is:\n\n```python\nimport pytest\nfrom tests.test_server.test_app.views import DummyViewSetFixture\n\n\n@pytest.mark.api_action(view_set_class=DummyViewSetFixture)\ndef test_dummy(db, api_action):\n  result = api_action.dummy(pk='bbb')\n  assert result['dummy_int'] == 1\n```\n\n```shell\ntests/functionality_tests/test_as_api.py:11 (test_call_as_api)\nself = \u003cdjango.db.models.fields.BigAutoField: id\u003e, value = 'bb'\n\n    def get_prep_value(self, value):\n        value = super().get_prep_value(value)\n        if value is None:\n            return None\n        try:\n\u003e           return int(value)\nE           ValueError: invalid literal for int() with base 10: 'bb'\n\n../venv/lib/python3.9/site-packages/django/db/models/fields/__init__.py:2053: ValueError\n\nThe above exception was the direct cause of the following exception:\n\nqueryset = \u003cQuerySet [\u003cDummyModel: DummyModel object (1)\u003e]\u003e, filter_args = ()\nfilter_kwargs = {'pk': 'bb'}\n\n    def get_object_or_404(queryset, *filter_args, **filter_kwargs):\n        \"\"\"\n        Same as Django's standard shortcut, but make sure to also raise 404\n        if the filter_kwargs don't match the required types.\n        \"\"\"\n        try:\n\u003e           return _get_object_or_404(queryset, *filter_args, **filter_kwargs)\n\n../venv/lib/python3.9/site-packages/rest_framework/generics.py:19: \n....\n....\n...\n```\n\nCall endpoints with pagination:\n```python\n@pytest.mark.api_action(view_set_class=DummyAPIViewSet)\ndef test_pagination_data(db, api_action):\n    for i in range(1, 3):\n        dummy_model = DummyModel()\n        dummy_model.dummy_int = 1\n        dummy_model.save()\n\n    response = api_action.by_dummy_int(dummy_int=1, page=1)\n\n    obj = response['results'][0]\n    assert obj['dummy_int'] == 1\n\n    assert extract_page_number(response['next']) == 2\n\n    response = api_action.by_dummy_int(dummy_int=1, page=2)\n    assert extract_page_number(response['previous']) == 1\n    assert extract_page_number(response['next']) is None\n\n```\n\n\n## Package Testing\n\nThe `drf-api-action` library includes tests to ensure the functionality works as expected. To run the tests run `pytest`:\n\n ```shell\n pytest\n ```\n\nThe tests will be executed, and the results will be displayed in the console.\n\n## Example\n\nExample of using drf-api-action in a [DRF project](https://github.com/Ori-Roza/drf-api-action-example)\n\n## Support \u0026 Contribution\n\nFor guidance on support \u0026 contribution, see the [contributing guidelines](https://github.com/Ori-Roza/drf-api-action/blob/master/docs/CONTRIBUTING.md).\n\n## Bug Report \n\nFor guidance on how to open a bug, see the [bug report template](https://github.com/Ori-Roza/drf-api-action/blob/master/docs/BUG_REPORT.md).\n\n## Open an Issue\n\nFor guidance on how to open an issue, see the [issue template](https://github.com/Ori-Roza/drf-api-action/blob/master/docs/ISSUE_TEMPLATE.md).\n\n## Code Of Conduct\n\n[code of conduct](https://github.com/Ori-Roza/drf-api-action/blob/master/docs/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOri-Roza%2Fdrf-api-action","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FOri-Roza%2Fdrf-api-action","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOri-Roza%2Fdrf-api-action/lists"}