Skip to content

Commit

Permalink
v3.2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo-moreno committed Jun 9, 2021
1 parent e054526 commit 27b8dc8
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/runtests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
poetry-version: ${{ matrix.poetry-version }}
- name: Setup dependencies
run: poetry install
- name: Run linter
run: poetry run flake8
- name: Run tests
run: poetry run pytest --cov=spook && poetry run coverage xml
- name: Upload to codecov
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "spook"
version = "3.2.6"
version = "3.2.7"
description = "Django Rest Framework library to interconnect external APIs"
authors = ["Pablo Moreno <[email protected]>"]
license = "MIT"
Expand All @@ -20,7 +20,7 @@ classifiers = [

[tool.poetry.dependencies]
python = ">=3.7,<4"
django = ">= 1.11.0"
django = ">= 2.2.0"
djangorestframework = ">= 3.3.1"
requests = ">= 2.24.0"
coverage = ">= 5.3"
Expand All @@ -31,6 +31,7 @@ wheel = "^0.34.2"
pytest = "^6.0.1"
coverage = "^5.3"
pytest-cov = "^2.12.0"
flake8 = "^3.9.2"

[build-system]
requires = ["poetry>=0.12"]
Expand Down
5 changes: 2 additions & 3 deletions spook/resources.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import enum
from json import JSONDecodeError

import requests
Expand Down Expand Up @@ -79,7 +78,7 @@ def get_headers(self) -> dict:
def get_response_data(self, response) -> Union[dict, str]:
try:
response_data = response.json()
except (JSONDecodeError, Exception) as e:
except (JSONDecodeError, Exception):
response_data = response.content

return response_data
Expand Down Expand Up @@ -176,7 +175,7 @@ def post(self, data: dict, query: dict = None) -> APIResourceResponse:
validated_data = self.validate(data, action="create")
response = self.http.post(
self.get_url(),
data=validated_data,
json=validated_data,
headers=self.get_headers(),
params=query,
)
Expand Down
16 changes: 15 additions & 1 deletion spook/tests/test_spook.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,22 @@
from rest_framework.exceptions import ValidationError
from rest_framework.test import APITestCase

from spook.resources import APIResource
from spook.tests.mocks import (
ProductResource,
get_mocked_products,
PRODUCTS,
retrieve_product,
create_product,
CREATED_PRODUCT,
update_product,
UPDATED_PRODUCT,
delete_product,
server_error,
server_validation_error,
server_permission_error,
)
from spook.utils import get_model_slug
from spook.tests.mocks import *


class TestAPIResource(APITestCase):
Expand Down
15 changes: 13 additions & 2 deletions spook/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@
from unittest.mock import patch
from rest_framework.test import APITestCase

from spook.views import *
from spook.tests.mocks import *
from spook.tests.mocks import (
ProductSerializer,
ProductResource,
get_mocked_products,
PRODUCTS,
retrieve_product,
create_product,
CREATED_PRODUCT,
update_product,
UPDATED_PRODUCT,
delete_product,
)
from spook.tests.utils import MockedRequest
from spook.views import APIResourceListCreateView, APIResourceRetrieveUpdateDestroyView


class NoResourceView(APIResourceListCreateView):
Expand Down
4 changes: 0 additions & 4 deletions spook/tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
from json import JSONDecodeError

from django.db import connection
from django.db.models.base import ModelBase
from rest_framework.test import APITestCase


class MockedResponse(object):
def __init__(self, data, status_code=200):
Expand Down
1 change: 0 additions & 1 deletion spook/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def list(self, request, *args, **kwargs):
resource = self.get_resource()
token = self.get_token(request)
params = request.query_params
serializer = self.get_serializer_class()
context = {
"request": request,
}
Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
ignore = E501,F401,F403

0 comments on commit 27b8dc8

Please sign in to comment.