-
Notifications
You must be signed in to change notification settings - Fork 94
feature: async support #225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e8e7c9d
tests: add pytest-aiohttp plugin
phanak-sap 08a7a7f
feat: add support for async http library aiohttp
mnunzio ac550d8
Added: prefix async getattr, atom response
Albo90 724bf70
added tests
Albo90 bf18c73
updated dev-requirements.txt
Albo90 1966c26
feat: update async_client tests
mnunzio 5998c03
feat: update dev-requirements.txt
mnunzio b90e362
feat: clean useless code
mnunzio 24dc3c8
Merge branch 'master' of https://github.com/SAP/python-pyodata into a…
phanak-sap 4fe4d9e
chore: fix dev-requirements duplicate after merge
phanak-sap 3f4b950
tests: move client tests to integration/networking_libraries
phanak-sap 4399050
ci: set fail-fast: false so all matrix jobs runs
phanak-sap 8bc2c69
tests: aiohttp - switch from unittest to pytest warnings
phanak-sap 213def7
Merge branch 'async-feature' of https://github.com/SAP/python-pyodata…
phanak-sap 917de92
tests: requests - switch from unittest to pytest warnings
phanak-sap 771312c
tests: add first httpx sync client tests
phanak-sap 5c40988
tests: rest of sync httpx client tests
phanak-sap 718635c
tests: fix small typo
phanak-sap f72fd36
tests: rm unecessary init.py (autogenerated)
phanak-sap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
tests/integration/networking_libraries/test_aiohttp_client.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| """ Test the pyodata integration with aiohttp client, based on asyncio | ||
|
|
||
| https://docs.aiohttp.org/en/stable/ | ||
| """ | ||
| import aiohttp | ||
| from aiohttp import web | ||
| import pytest | ||
|
|
||
| import pyodata.v2.service | ||
| from pyodata import Client | ||
| from pyodata.exceptions import PyODataException, HttpError | ||
| from pyodata.v2.model import ParserError, PolicyWarning, PolicyFatal, PolicyIgnore, Config | ||
|
|
||
| SERVICE_URL = '' | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_invalid_odata_version(): | ||
| """Check handling of request for invalid OData version implementation""" | ||
|
|
||
| with pytest.raises(PyODataException) as e_info: | ||
| async with aiohttp.ClientSession() as client: | ||
| await Client.build_async_client(SERVICE_URL, client, 'INVALID VERSION') | ||
|
|
||
| assert str(e_info.value).startswith('No implementation for selected odata version') | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_create_client_for_local_metadata(metadata): | ||
| """Check client creation for valid use case with local metadata""" | ||
|
|
||
| async with aiohttp.ClientSession() as client: | ||
| service_client = await Client.build_async_client(SERVICE_URL, client, metadata=metadata) | ||
|
|
||
| assert isinstance(service_client, pyodata.v2.service.Service) | ||
| assert service_client.schema.is_valid == True | ||
|
|
||
| assert len(service_client.schema.entity_sets) != 0 | ||
|
|
||
| @pytest.mark.asyncio | ||
| def generate_metadata_response(headers=None, body=None, status=200): | ||
|
|
||
| async def metadata_response(request): | ||
| return web.Response(status=status, headers=headers, body=body) | ||
|
|
||
| return metadata_response | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("content_type", ['application/xml', 'application/atom+xml', 'text/xml']) | ||
| @pytest.mark.asyncio | ||
| async def test_create_service_application(aiohttp_client, metadata, content_type): | ||
| """Check client creation for valid MIME types""" | ||
|
|
||
| app = web.Application() | ||
| app.router.add_get('/$metadata', generate_metadata_response(headers={'content-type': content_type}, body=metadata)) | ||
| client = await aiohttp_client(app) | ||
|
|
||
| service_client = await Client.build_async_client(SERVICE_URL, client) | ||
|
|
||
| assert isinstance(service_client, pyodata.v2.service.Service) | ||
|
|
||
| # one more test for '/' terminated url | ||
|
|
||
| service_client = await Client.build_async_client(SERVICE_URL + '/', client) | ||
|
|
||
| assert isinstance(service_client, pyodata.v2.service.Service) | ||
| assert service_client.schema.is_valid | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_metadata_not_reachable(aiohttp_client): | ||
| """Check handling of not reachable service metadata""" | ||
|
|
||
| app = web.Application() | ||
| app.router.add_get('/$metadata', generate_metadata_response(headers={'content-type': 'text/html'}, status=404)) | ||
| client = await aiohttp_client(app) | ||
|
|
||
| with pytest.raises(HttpError) as e_info: | ||
| await Client.build_async_client(SERVICE_URL, client) | ||
|
|
||
| assert str(e_info.value).startswith('Metadata request failed') | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_metadata_saml_not_authorized(aiohttp_client): | ||
| """Check handling of not SAML / OAuth unauthorized response""" | ||
|
|
||
| app = web.Application() | ||
| app.router.add_get('/$metadata', generate_metadata_response(headers={'content-type': 'text/html; charset=utf-8'})) | ||
| client = await aiohttp_client(app) | ||
|
|
||
| with pytest.raises(HttpError) as e_info: | ||
| await Client.build_async_client(SERVICE_URL, client) | ||
|
|
||
| assert str(e_info.value).startswith('Metadata request did not return XML, MIME type:') | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_client_custom_configuration(aiohttp_client, metadata): | ||
| """Check client creation for custom configuration""" | ||
|
|
||
| namespaces = { | ||
| 'edmx': "customEdmxUrl.com", | ||
| 'edm': 'customEdmUrl.com' | ||
| } | ||
|
|
||
| custom_config = Config( | ||
| xml_namespaces=namespaces, | ||
| default_error_policy=PolicyFatal(), | ||
| custom_error_policies={ | ||
| ParserError.ANNOTATION: PolicyWarning(), | ||
| ParserError.ASSOCIATION: PolicyIgnore() | ||
| }) | ||
|
|
||
| app = web.Application() | ||
| app.router.add_get('/$metadata', | ||
| generate_metadata_response(headers={'content-type': 'application/xml'}, body=metadata)) | ||
| client = await aiohttp_client(app) | ||
|
|
||
| with pytest.raises(PyODataException) as e_info: | ||
| await Client.build_async_client(SERVICE_URL, client, config=custom_config, namespaces=namespaces) | ||
|
|
||
| assert str(e_info.value) == 'You cannot pass namespaces and config at the same time' | ||
|
|
||
| with pytest.warns(DeprecationWarning,match='Passing namespaces directly is deprecated. Use class Config instead'): | ||
| service = await Client.build_async_client(SERVICE_URL, client, namespaces=namespaces) | ||
|
|
||
| assert isinstance(service, pyodata.v2.service.Service) | ||
| assert service.schema.config.namespaces == namespaces | ||
|
|
||
| service = await Client.build_async_client(SERVICE_URL, client, config=custom_config) | ||
|
|
||
| assert isinstance(service, pyodata.v2.service.Service) | ||
| assert service.schema.config == custom_config |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you kill all async here? What's the difference between the regular client?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, await (asynchronous wait) is calling the asynchronous _async_fetch_metadata function.