Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ Client session
# If you are not using context manager, you need to close session manually
s.close()

# Again, don't forget to await in the AsyncIO mode
await s.close()

# Fetching documents
documents = s.get('resource_type')
# Or if you want only 1, then
Expand Down
6 changes: 3 additions & 3 deletions src/jsonapi_client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,15 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):
logger.info('Exiting session')
if not exc_type:
await self.commit()
self.close()
await self.close()

def close(self):
"""
Close session and invalidate resources.
"""
if self.enable_async:
self._aiohttp_session.close()
self.invalidate()
if self.enable_async:
return self._aiohttp_session.close()

def invalidate(self):
"""
Expand Down
8 changes: 4 additions & 4 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def test_error_404(mocked_fetch, api_schema):
with pytest.raises(DocumentError) as e:
s.get('error')

assert 'Error document was fetched' in str(e)
assert 'Error document was fetched' in str(e.value)


@pytest.mark.asyncio
Expand All @@ -510,8 +510,8 @@ async def test_error_404_async(mocked_fetch, api_schema):
assert e.value.errors['status_code'] == 404
with pytest.raises(DocumentError) as e:
await s.get('error')
assert 'Error document was fetched' in str(e)
s.close()
assert 'Error document was fetched' in str(e.value)
await s.close()


def test_relationships_with_context_manager(mocked_fetch, api_schema):
Expand Down Expand Up @@ -946,7 +946,7 @@ def test_schema_validation(mocked_fetch):
with pytest.raises(ValidationError) as e:
article = s.get('articles')
#article.title.startswith('JSON API paints')
assert 'is not of type \'number\'' in str(e)
assert 'is not of type \'number\'' in str(e.value)


def make_patch_json(ids, type_, field_name=None):
Expand Down