Skip to content

Commit

Permalink
Add isort and flake8-commas to linters.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgoclawski committed Jul 12, 2024
1 parent 83d1417 commit 5795e15
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 63 deletions.
2 changes: 1 addition & 1 deletion jsonapi_requests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from . import orm
from .base import Api
from .data import JsonApiObject
from . import orm

__all__ = ['Api', 'JsonApiObject', 'orm']
3 changes: 1 addition & 2 deletions jsonapi_requests/configuration.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from collections import namedtuple


Configuration = namedtuple(
'Configuration',
['API_ROOT', 'AUTH', 'VALIDATE_SSL', 'TIMEOUT', 'APPEND_SLASH', 'RETRIES']
['API_ROOT', 'AUTH', 'VALIDATE_SSL', 'TIMEOUT', 'APPEND_SLASH', 'RETRIES'],
)


Expand Down
1 change: 0 additions & 1 deletion jsonapi_requests/orm/repositories.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import collections

import itertools

ObjectKey = collections.namedtuple('ObjectKey', ['type', 'id'])
Expand Down
4 changes: 2 additions & 2 deletions jsonapi_requests/request_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def retrying(self):
return tenacity.Retrying(
reraise=True,
retry=retry_condition,
stop=tenacity.stop_after_attempt(self.config.RETRIES)
stop=tenacity.stop_after_attempt(self.config.RETRIES),
)

def _build_absolute_url(self, api_path):
Expand All @@ -68,7 +68,7 @@ def default_options(self):
'headers': {
'Content-Type': 'application/vnd.api+json',
'Accept': 'application/vnd.api+json',
}
},
}

@property
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get_long_description():
packages=find_packages(exclude=['tests']),
install_requires=parse_requirements('base_requirements.txt'),
extras_require={
'flask': ['flask']
'flask': ['flask'],
},
license='BSD',
classifiers=[
Expand All @@ -39,5 +39,5 @@ def get_long_description():
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
]
],
)
2 changes: 1 addition & 1 deletion tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from flask import Flask

from jsonapi_requests import configuration
from jsonapi_requests import auth
from jsonapi_requests import configuration
from jsonapi_requests import request_factory


Expand Down
50 changes: 25 additions & 25 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_add_relationship_to_parsed_response(self):

def test_remove_relationship_from_parsed_response(self):
parsed = jsonapi_requests.data.JsonApiResponse.from_data(
{'data': {'relationships': {'chicken': {'data': {'type': 'chicken', 'id': '2'}}}}}
{'data': {'relationships': {'chicken': {'data': {'type': 'chicken', 'id': '2'}}}}},
)
del parsed.data.relationships['chicken']
assert parsed.as_data() == {}
Expand All @@ -47,75 +47,75 @@ def test_remove_relationship_from_parsed_response(self):
"links": {
"self": "http://example.com/articles",
"next": "http://example.com/articles?page[offset]=2",
"last": "http://example.com/articles?page[offset]=10"
"last": "http://example.com/articles?page[offset]=10",
},
"data": [{
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON API paints my bikeshed!"
"title": "JSON API paints my bikeshed!",
},
"relationships": {
"author": {
"links": {
"self": "http://example.com/articles/1/relationships/author",
"related": "http://example.com/articles/1/author"
"related": "http://example.com/articles/1/author",
},
"data": {"type": "people", "id": "9"}
"data": {"type": "people", "id": "9"},
},
"comments": {
"links": {
"self": "http://example.com/articles/1/relationships/comments",
"related": "http://example.com/articles/1/comments"
"related": "http://example.com/articles/1/comments",
},
"data": [
{"type": "comments", "id": "5"},
{"type": "comments", "id": "12"}
]
}
{"type": "comments", "id": "12"},
],
},
},
"links": {
"self": "http://example.com/articles/1"
}
"self": "http://example.com/articles/1",
},
}],
"included": [{
"type": "people",
"id": "9",
"attributes": {
"first-name": "Dan",
"last-name": "Gebhardt",
"twitter": "dgeb"
"twitter": "dgeb",
},
"links": {
"self": "http://example.com/people/9"
}
"self": "http://example.com/people/9",
},
}, {
"type": "comments",
"id": "5",
"attributes": {
"body": "First!"
"body": "First!",
},
"relationships": {
"author": {
"data": {"type": "people", "id": "2"}
}
"data": {"type": "people", "id": "2"},
},
},
"links": {
"self": "http://example.com/comments/5"
}
"self": "http://example.com/comments/5",
},
}, {
"type": "comments",
"id": "12",
"attributes": {
"body": "I like XML better"
"body": "I like XML better",
},
"relationships": {
"author": {
"data": {"type": "people", "id": "9"}
}
"data": {"type": "people", "id": "9"},
},
},
"links": {
"self": "http://example.com/comments/12"
}
}]
"self": "http://example.com/comments/12",
},
}],
}
52 changes: 26 additions & 26 deletions tests/test_orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import pytest

from jsonapi_requests import data
from jsonapi_requests import request_factory
from jsonapi_requests import orm
from jsonapi_requests import request_factory


class TestApiModel:
Expand Down Expand Up @@ -62,10 +62,10 @@ def test_refresh_with_relationships(self):
mock_api.endpoint.return_value.get.return_value.content = data.JsonApiResponse(
data=data.JsonApiObject(
type='test', id='123', relationships={
'other': data.Relationship(data=data.ResourceIdentifier(id='1', type='test'))
}
'other': data.Relationship(data=data.ResourceIdentifier(id='1', type='test')),
},
),
included=[mock.MagicMock(id='1', type='test', attributes={'name': 'alice'})]
included=[mock.MagicMock(id='1', type='test', attributes={'name': 'alice'})],
)
orm_api = orm.OrmApi(mock_api)

Expand All @@ -84,9 +84,9 @@ class Meta:
def test_from_response_with_relationships(self):
response_content = data.JsonApiResponse(
data=data.JsonApiObject(type='test', relationships={
'other': data.Relationship(data=data.ResourceIdentifier(id='1', type='test'))
'other': data.Relationship(data=data.ResourceIdentifier(id='1', type='test')),
}),
included=[mock.MagicMock(id='1', type='test', attributes={'name': 'alice'})]
included=[mock.MagicMock(id='1', type='test', attributes={'name': 'alice'})],
)
orm_api = orm.OrmApi(mock.MagicMock())

Expand All @@ -103,8 +103,8 @@ class Meta:
def test_from_response_with_relationship_with_none_type(self):
response_content = data.JsonApiResponse(
data=data.JsonApiObject(id='1', type='test', relationships={
'other': data.Relationship(data=data.ResourceIdentifier(id=None, type=None))
})
'other': data.Relationship(data=data.ResourceIdentifier(id=None, type=None)),
}),
)
orm_api = orm.OrmApi(mock.MagicMock())

Expand All @@ -123,7 +123,7 @@ def test_issue_19_attributes_are_readable_with_multiple_relations(self):
data=data.JsonApiObject(
type='designs',
relationships={'sub_designs': data.Relationship(data=[data.ResourceIdentifier(id=3, type='designs')])},
attributes={'name': 'doctor_x'}
attributes={'name': 'doctor_x'},
),
)
orm_api = orm.OrmApi(mock.MagicMock())
Expand All @@ -145,7 +145,7 @@ def test_saving_new(self):
mock_api.endpoint.return_value.post.return_value.content.data = data.JsonApiObject(
attributes={'name': 'doctor_x'},
id='1',
type='test'
type='test',
)
orm_api = orm.OrmApi(mock_api)

Expand All @@ -162,7 +162,7 @@ class Meta:
design.save()
assert design.id == '1'
mock_api.endpoint.return_value.post.assert_called_with(
object=data.JsonApiObject.from_data({'type': 'designs', 'attributes': {'name': 'doctor_x'}})
object=data.JsonApiObject.from_data({'type': 'designs', 'attributes': {'name': 'doctor_x'}}),
)

def test_saving_new_custom_path(self):
Expand All @@ -171,7 +171,7 @@ def test_saving_new_custom_path(self):
mock_api.endpoint.return_value.post.return_value.content.data = data.JsonApiObject(
attributes={'name': 'doctor_x'},
id='1',
type='test'
type='test',
)
orm_api = orm.OrmApi(mock_api)

Expand All @@ -190,7 +190,7 @@ class Meta:
assert design.id == '1'
mock_api.endpoint.assert_called_with('designs')
mock_api.endpoint.return_value.post.assert_called_with(
object=data.JsonApiObject.from_data({'type': 'design', 'attributes': {'name': 'doctor_x'}})
object=data.JsonApiObject.from_data({'type': 'design', 'attributes': {'name': 'doctor_x'}}),
)

def test_creating_with_id(self):
Expand All @@ -211,7 +211,7 @@ class Meta:
design.create()
assert design.raw_object.id == '1'
mock_api.endpoint.return_value.post.assert_called_with(
object=data.JsonApiObject.from_data({'id': '1', 'type': 'designs', 'attributes': {'name': 'doctor_x'}})
object=data.JsonApiObject.from_data({'id': '1', 'type': 'designs', 'attributes': {'name': 'doctor_x'}}),
)

def test_saving_updated(self):
Expand All @@ -231,7 +231,7 @@ class Meta:
design.id = '1'
design.save()
mock_api.endpoint.return_value.patch.assert_called_with(
object=data.JsonApiObject.from_data({'id': '1', 'type': 'designs', 'attributes': {'name': 'doctor_x'}})
object=data.JsonApiObject.from_data({'id': '1', 'type': 'designs', 'attributes': {'name': 'doctor_x'}}),
)

def test_saving_updated_with_some_server_side_changes(self):
Expand All @@ -240,7 +240,7 @@ def test_saving_updated_with_some_server_side_changes(self):
mock_api.endpoint.return_value.patch.return_value.content = mock.MagicMock(
data=mock.Mock(
type='designs',
attributes={'name': 'doctor_x', 'status': 'complete'}
attributes={'name': 'doctor_x', 'status': 'complete'},
),
)
orm_api = orm.OrmApi(mock_api)
Expand All @@ -258,15 +258,15 @@ class Meta:
design.id = '1'
design.save()
mock_api.endpoint.return_value.patch.assert_called_with(
object=data.JsonApiObject.from_data({'id': '1', 'type': 'designs', 'attributes': {'name': 'doctor_x'}})
object=data.JsonApiObject.from_data({'id': '1', 'type': 'designs', 'attributes': {'name': 'doctor_x'}}),
)
assert design.status == 'complete'

def test_saving_updated_with_metadata(self):
mock_api = mock.MagicMock()
mock_api.endpoint.return_value.patch.return_value.status_code = 200
mock_api.endpoint.return_value.patch.return_value.content = data.JsonApiResponse.from_data({
'meta': {'success-level': 'great'}
'meta': {'success-level': 'great'},
})
orm_api = orm.OrmApi(mock_api)

Expand All @@ -282,7 +282,7 @@ class Meta:
design.id = '1'
design.save()
mock_api.endpoint.return_value.patch.assert_called_with(
object=data.JsonApiObject.from_data({'id': '1', 'type': 'designs', 'attributes': {'name': 'doctor_x'}})
object=data.JsonApiObject.from_data({'id': '1', 'type': 'designs', 'attributes': {'name': 'doctor_x'}}),
)
assert design.name == 'doctor_x'

Expand All @@ -292,14 +292,14 @@ def test_relation_to_main_object(self):
id=2,
type='designs',
relationships={'sub_designs': mock.Mock(data=mock.Mock(id=3, type='designs'))},
attributes={'name': 'doctor_x'}
attributes={'name': 'doctor_x'},
),
included=[
mock.Mock(
id=3,
type='designs',
relationships={'sub_designs': mock.Mock(data=mock.Mock(id=2, type='designs'))},
attributes={'name': 'doctor_y'}
attributes={'name': 'doctor_y'},
),
],
)
Expand Down Expand Up @@ -336,8 +336,8 @@ class Meta:
object=data.JsonApiObject.from_data({
'id': '1',
'type': 'designs',
'relationships': {'others': {'data': [{'type': 'designs', 'id': '1'}]}}
})
'relationships': {'others': {'data': [{'type': 'designs', 'id': '1'}]}},
}),
)

def test_getting_list(self):
Expand Down Expand Up @@ -378,11 +378,11 @@ def test_getting_list_with_relationships(self):
mock_api.endpoint.return_value.get.return_value.content = mock.MagicMock(
data=[mock.Mock(
type='test', id='123', attributes={'name': 'bob'},
relationships={'other': mock.Mock(data=mock.Mock(id='1', type='test'))}
relationships={'other': mock.Mock(data=mock.Mock(id='1', type='test'))},
), mock.MagicMock(
type='test', id='1', attributes={'name': 'alice'}
type='test', id='1', attributes={'name': 'alice'},
)],
included=[]
included=[],
)
orm_api = orm.OrmApi(mock_api)

Expand Down
7 changes: 4 additions & 3 deletions tests/test_request_factory.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from unittest import mock

import pytest
import requests
from unittest import mock

from jsonapi_requests import request_factory
from jsonapi_requests import data
from jsonapi_requests import configuration
from jsonapi_requests import data
from jsonapi_requests import request_factory


@pytest.fixture
Expand Down
3 changes: 3 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ description = run linters
skip_install = true
deps =
flake8
flake8-commas
isort
commands =
flake8
isort --check --diff .

0 comments on commit 5795e15

Please sign in to comment.