Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
oriroza committed Nov 30, 2023
1 parent a58c05f commit b56884b
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
python3 -m coverage run -m pytest
python3 create_coverage.py
python3 resources/create_coverage.py
env:
GIT_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
![Alt text](drf-api-action-banner.png?raw=true "")
![Alt text](resources/drf-api-action-banner.png?raw=true "")


[![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)
![Alt text](coverage_badge.svg)
![Alt text](resources/coverage_badge.svg)
[![license - MIT](https://img.shields.io/badge/license-MIT-yellow)](https://)


Expand All @@ -15,6 +15,7 @@ The benefits of using DRF inside your API functions:
* Pagination
* Clear separation between function signature and business logic
* Makes Django DB models accessible in other libraries/web services
* transform the app to a web server in a click

And many more!

Expand Down Expand Up @@ -71,14 +72,18 @@ Create an instance of your view class and call the API actions as regular functi
api = DummyView()
results = api.dummy_func(**args)
```
example:
![Alt text](resources/running_shell.png?raw=true "")


In the example above, we create an instance of `DummyView` and call the `dummy_func` action with the specified arguments (`args`) and an additional `page` argument.


### Step 5: Run as a server
```bash
python3 drf-api-action/tests/manage.py
```
![Alt text](run_server.png?raw=true "")
![Alt text](resources/run_server.png?raw=true "")


## Pagination Support
Expand Down
1 change: 0 additions & 1 deletion coverage.json

This file was deleted.

14 changes: 4 additions & 10 deletions drf_api_action/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,18 @@ def run_as_api(self, **kw):
request = CustomRequest(kw, kw)
self.kwargs = kw
self.request = request
results = None
current_error = None

try:
ret = func(self, request, **kw)
if isinstance(ret.data, list):
if isinstance(ret.data, list): # multiple results
results = [dict(res) for res in ret.data]
else:
results = {k.lower(): v for k, v in ret.data.items()}
except Exception as error: # pylint: disable=broad-except
current_error = error

if current_error:
error_type = type(current_error)

raised_exception = ActionsAPIExceptionMiddleware(current_error,
error_type = type(error)
raised_exception = ActionsAPIExceptionMiddleware(error,
error_type=error_type,
traceback=current_error.__traceback__)
traceback=error.__traceback__) # fixing stack frames
raise raised_exception # pylint: disable=raising-non-exception

return results
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "drf_api_action"
description = "use the power of restframework also as a library functions"
version = "1.0.3"
version = "1.0.4"
readme = "README.md"
dependencies = ["Django>=4.2.3", "djangorestframework>=3.14.0", "pytest-django>=4.5.2"]
authors = [
Expand Down
1 change: 1 addition & 0 deletions resources/coverage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"meta": {"version": "7.2.7", "timestamp": "2023-11-30T09:29:43.013145", "branch_coverage": false, "show_contexts": false}, "files": {"drf_api_action/__init__.py": {"executed_lines": [1], "summary": {"covered_lines": 0, "num_statements": 0, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "drf_api_action/decorators.py": {"executed_lines": [1, 3, 4, 7, 52, 53, 55, 57, 58, 59, 61, 62, 63, 64, 65, 66, 67, 69, 70, 71, 74, 75, 76, 78, 79, 81, 84, 86, 88, 89, 90, 91, 92, 93, 95, 96, 98, 104], "summary": {"covered_lines": 38, "num_statements": 39, "percent_covered": 97.43589743589743, "percent_covered_display": "97", "missing_lines": 1, "excluded_lines": 0}, "missing_lines": [72], "excluded_lines": []}, "drf_api_action/exceptions.py": {"executed_lines": [1, 2, 5, 6, 7, 8, 9, 10], "summary": {"covered_lines": 8, "num_statements": 8, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "drf_api_action/mixins.py": {"executed_lines": [1, 2, 5, 6, 9, 11, 12, 15, 17, 19, 20], "summary": {"covered_lines": 10, "num_statements": 11, "percent_covered": 90.9090909090909, "percent_covered_display": "91", "missing_lines": 1, "excluded_lines": 0}, "missing_lines": [14], "excluded_lines": []}, "drf_api_action/utils.py": {"executed_lines": [1, 4, 5, 9, 10, 11, 13, 14, 17, 23, 24, 25, 26, 27, 30, 41], "summary": {"covered_lines": 15, "num_statements": 21, "percent_covered": 71.42857142857143, "percent_covered_display": "71", "missing_lines": 6, "excluded_lines": 0}, "missing_lines": [36, 37, 38, 47, 48, 49], "excluded_lines": []}, "tests/__init__.py": {"executed_lines": [1], "summary": {"covered_lines": 0, "num_statements": 0, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "tests/functionality_tests/__init__.py": {"executed_lines": [1], "summary": {"covered_lines": 0, "num_statements": 0, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "tests/functionality_tests/test_as_api.py": {"executed_lines": [1, 2, 3, 5, 6, 7, 9, 12, 13, 14, 15, 16, 18, 19, 22, 23, 24, 25, 26, 27, 28, 31, 32, 34, 35, 36, 38, 39, 42, 43, 45, 46, 47, 48, 49, 52, 53, 55, 56, 57, 58, 60, 61, 63, 64, 66, 67, 68, 71, 72, 74, 75, 76, 77, 78], "summary": {"covered_lines": 55, "num_statements": 55, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "tests/test_app/__init__.py": {"executed_lines": [1], "summary": {"covered_lines": 0, "num_statements": 0, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "tests/test_app/migrations/0001_initial.py": {"executed_lines": [3, 6, 8, 10, 13], "summary": {"covered_lines": 5, "num_statements": 5, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "tests/test_app/migrations/__init__.py": {"executed_lines": [1], "summary": {"covered_lines": 0, "num_statements": 0, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "tests/test_app/models.py": {"executed_lines": [1, 4, 5], "summary": {"covered_lines": 3, "num_statements": 3, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "tests/test_app/settings.py": {"executed_lines": [1, 2, 5, 7, 9, 10, 11, 12, 13, 15, 29, 40, 47, 49, 66, 68], "summary": {"covered_lines": 16, "num_statements": 16, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "tests/test_app/urls.py": {"executed_lines": [1, 4, 5, 7, 8, 9, 11], "summary": {"covered_lines": 6, "num_statements": 6, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "tests/test_app/views.py": {"executed_lines": [1, 3, 4, 5, 6, 7, 8, 9, 12, 13, 15, 16, 17, 20, 21, 22, 24, 25, 26, 28, 29, 30, 31, 34, 35, 36, 38, 39, 44, 45, 46, 48, 55, 56, 57, 58, 60, 61, 62, 63, 64, 65, 66], "summary": {"covered_lines": 43, "num_statements": 46, "percent_covered": 93.47826086956522, "percent_covered_display": "93", "missing_lines": 3, "excluded_lines": 0}, "missing_lines": [40, 41, 49], "excluded_lines": []}}, "totals": {"covered_lines": 199, "num_statements": 210, "percent_covered": 94.76190476190476, "percent_covered_display": "95", "missing_lines": 11, "excluded_lines": 0}}
File renamed without changes
6 changes: 3 additions & 3 deletions create_coverage.py → resources/create_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def get_coverage_attributes():
'json',
'-q',
'-o',
'coverage.json'])
with open('coverage.json', 'r') as file_pointer:
'resources/coverage.json'])
with open('resources/coverage.json', 'r') as file_pointer:
data = json.load(file_pointer)
return data

Expand All @@ -29,7 +29,7 @@ def create_coverage_badge(percentage):
badge_svg = pybadges.badge(left_text='coverage',
right_text=f"{str(percentage)}%",
right_color=color)
with open('coverage_badge.svg', 'w') as file_pointer:
with open('resources/coverage_badge.svg', 'w') as file_pointer:
file_pointer.write(badge_svg)


Expand Down
File renamed without changes
File renamed without changes
Binary file added resources/running_shell.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b56884b

Please sign in to comment.