Skip to content

Commit

Permalink
Hotfix :: OData connector (#84)
Browse files Browse the repository at this point in the history
* patch odata $metadata (cf. tuomur/python-odata#22)

* add test
  • Loading branch information
fspot authored Jun 21, 2019
1 parent 7ce3ea4 commit 1d76ffd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
]

setup(name='toucan_connectors',
version='0.17.0',
version='0.17.1',
description='Toucan Toco Connectors',
author='Toucan Toco',
author_email='[email protected]',
Expand Down
8 changes: 7 additions & 1 deletion tests/odata/test_odata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

import pandas as pd
import pytest
from odata.metadata import MetaData

from toucan_connectors.odata.odata_connector import ODataConnector, ODataDataSource


def test_get_df():
def test_get_df(mocker):
"""
It should make a query to the canonical service and return the right results
"""
spy_load_metadata = mocker.spy(MetaData, 'load_document')
expected_df = pd.read_json('tests/odata/fixtures/records.json', orient='records')

provider = ODataConnector(
Expand All @@ -33,6 +35,10 @@ def test_get_df():
except socket.error:
pytest.skip('Could not connect to the standard example OData service.')

assert spy_load_metadata.call_count == 1
args, _ = spy_load_metadata.call_args
assert args[0].url.endswith('/$metadata')

provider.auth = None
try:
provider.get_df(data_source)
Expand Down
12 changes: 12 additions & 0 deletions toucan_connectors/odata/odata_connector.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import pandas as pd
from odata import ODataService
from odata.metadata import MetaData

from toucan_connectors.common import Auth
from toucan_connectors.toucan_connector import ToucanConnector, ToucanDataSource


# monkey patch MetaData's __init__
# (cf. https://github.com/tuomur/python-odata/issues/22)
def metadata_init_patched(self, service):
self._original_init(service)
self.url = service.url.rstrip('/') + '/$metadata'


MetaData._original_init = MetaData.__init__
MetaData.__init__ = metadata_init_patched


class ODataDataSource(ToucanDataSource):
entity: str
query: dict
Expand Down

0 comments on commit 1d76ffd

Please sign in to comment.