Skip to content

Remove unnecessary request made when runtime context is entered. #55

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

Open
wants to merge 5 commits into
base: v1.x.y
Choose a base branch
from
Open
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
18 changes: 9 additions & 9 deletions tests/unit/test_datawarehouse_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ def test___enter___RuntimeError_xdmod_host_malformed():
),
match=(
r'(Invalid URL \'.*\': No host supplied|'
+ r'Invalid URL \'https:\?Bearer=' + INVALID_STR + "': "
+ r'No schema supplied. Perhaps you meant http://https:\?Bearer='
+ INVALID_STR + r'\?)'
+ r'Invalid URL \'https:/controllers/metric_explorer.php\':'
+ r' No schema supplied. Perhaps you meant'
+ r' http://https:/controllers/metric_explorer.php\?)'
),
):
with DataWarehouse('https://'): # pragma: no cover
pass
with DataWarehouse('https://') as dw:
dw.describe_realms()


def test___enter___RuntimeError_xdmod_host_unresolved():
invalid_host = 'https://' + INVALID_STR + '.xdmod.org'
with pytest.raises(Exception):
with DataWarehouse(invalid_host): # pragma: no cover
pass
with DataWarehouse(invalid_host) as dw:
dw.describe_realms()


def test___enter___RuntimeError_xdmod_host_unsupported_protocol():
Expand All @@ -66,8 +66,8 @@ def test___enter___RuntimeError_xdmod_host_unsupported_protocol():
requests.exceptions.InvalidSchema,
match="No connection adapters were found for '" + invalid_host,
):
with DataWarehouse(invalid_host): # pragma no cover
pass
with DataWarehouse(invalid_host) as dw:
dw.describe_realms()


def test___enter___RuntimeError_401():
Expand Down
10 changes: 0 additions & 10 deletions xdmod_data/_http_requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def __init__(self, xdmod_host):
def _start_up(self):
self.__in_runtime_context = True
self.__requests_session = requests.Session()
self.__assert_connection_to_xdmod_host()

def _tear_down(self):
if self.__requests_session is not None:
Expand Down Expand Up @@ -112,15 +111,6 @@ def _request_json(self, path, post_fields=None):
response = self.__request(path, post_fields)
return json.loads(response)

def __assert_connection_to_xdmod_host(self):
try:
self.__request()
except RuntimeError as e: # pragma: no cover
raise RuntimeError(
"Could not connect to xdmod_host '" + self.__xdmod_host
+ "': " + str(e),
) from None

def __request(self, path='', post_fields=None, stream=False):
_validator._assert_runtime_context(self.__in_runtime_context)
url = self.__xdmod_host + path
Expand Down
5 changes: 1 addition & 4 deletions xdmod_data/warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class DataWarehouse:
"""Access the XDMoD data warehouse via XDMoD's network API.
"""Request data from an XDMoD data warehouse via the XDMoD REST API.

Methods must be called within a runtime context using the ``with``
keyword, e.g.,
Expand All @@ -24,9 +24,6 @@ class DataWarehouse:
------
KeyError
If the `XDMOD_API_TOKEN` environment variable has not been set.
RuntimeError
If a connection cannot be made to the XDMoD server specified by
`xdmod_host`.
TypeError
If `xdmod_host` is not a string.
"""
Expand Down