Skip to content
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

Fix bug with trailing slashes in xdmod_host. #24

Merged
merged 3 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
43 changes: 27 additions & 16 deletions tests/integration/test_datawarehouse_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
VALID_DATE = '2020-01-01'
VALID_DIMENSION = 'Resource'
VALID_VALUES = {
'duration': 'Previous month',
'duration': 'Yesterday',
'realm': 'Jobs',
'metric': 'CPU Hours: Total',
'dimension': VALID_DIMENSION,
Expand All @@ -44,7 +44,7 @@
'aggregation_unit': 'Auto',
'parameter': 'duration',
'fields': ['Nodes'],
'show_progress': True,
'show_progress': False,
}
KEY_ERROR_TEST_VALUES_AND_MATCHES = {
'duration': (INVALID_STR, 'Invalid value for `duration`'),
Expand Down Expand Up @@ -92,8 +92,16 @@
method + ':end_date',
]
date_malformed_test_params += [
(method, 'start_date', {'duration': (INVALID_STR, VALID_DATE)}),
(method, 'end_date', {'duration': (VALID_DATE, INVALID_STR)}),
(
method,
'start_date',
{'duration':(INVALID_STR, VALID_DATE)}
aaronweeden marked this conversation as resolved.
Show resolved Hide resolved
),
(
method,
'end_date',
{'duration': (VALID_DATE, INVALID_STR)}
RodneyCodess marked this conversation as resolved.
Show resolved Hide resolved
),
]
value_error_test_methods += [method]
if 'filters' in METHOD_PARAMS[method]:
Expand All @@ -107,8 +115,11 @@


@pytest.fixture(scope='module')
def dw_methods():
with DataWarehouse(VALID_XDMOD_URL) as dw:
def dw_methods(request):
xdmod_host = VALID_XDMOD_URL
if hasattr(request, "param"):
RodneyCodess marked this conversation as resolved.
Show resolved Hide resolved
xdmod_host = request.param
with DataWarehouse(xdmod_host) as dw:
yield __get_dw_methods(dw)


Expand Down Expand Up @@ -152,16 +163,7 @@ def test_KeyError(dw_methods, method, params, match):

@pytest.mark.parametrize(
'method',
[
'get_data',
'get_raw_data',
'describe_realms',
'describe_metrics',
'describe_dimensions',
'get_filter_values',
'describe_raw_realms',
'describe_raw_fields',
],
list(METHOD_PARAMS.keys()),
)
def test_RuntimeError_outside_context(
dw_methods_outside_runtime_context,
Expand Down Expand Up @@ -439,3 +441,12 @@ def test_case_insensitive(dw_methods, method, param, value1, value2):
data1 = __run_method(dw_methods, method, {param: value1})
data2 = __run_method(dw_methods, method, {param: value2})
assert data1.equals(data2)


@pytest.mark.parametrize(
'dw_methods,method',
[(VALID_XDMOD_URL + "/", method)for method in list(METHOD_PARAMS.keys())],
RodneyCodess marked this conversation as resolved.
Show resolved Hide resolved
indirect=['dw_methods']
RodneyCodess marked this conversation as resolved.
Show resolved Hide resolved
)
def test_trailing_slashes(dw_methods, method):
__run_method(dw_methods, method)
6 changes: 5 additions & 1 deletion tests/unit/test_datawarehouse_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

@pytest.fixture(scope='module', autouse=True)
def set_environ():
token = os.environ['XDMOD_API_TOKEN'] if 'XDMOD_API_TOKEN' in os.environ else ''
token = (
os.environ['XDMOD_API_TOKEN']
if 'XDMOD_API_TOKEN' in os.environ
else ''
)
os.environ['XDMOD_API_TOKEN'] = INVALID_STR
yield
os.environ['XDMOD_API_TOKEN'] = token
Expand Down
2 changes: 1 addition & 1 deletion xdmod_data/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .__version__ import __version__
from .__version__ import __version__
2 changes: 2 additions & 0 deletions xdmod_data/_http_requester.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
import re
import requests
from urllib.parse import urlencode
import xdmod_data._validator as _validator
Expand All @@ -10,6 +11,7 @@ class _HttpRequester:
def __init__(self, xdmod_host):
self.__in_runtime_context = False
_validator._assert_str('xdmod_host', xdmod_host)
xdmod_host = re.sub('/+$', '', xdmod_host)
self.__xdmod_host = xdmod_host
try:
self.__api_token = os.environ['XDMOD_API_TOKEN']
Expand Down
2 changes: 2 additions & 0 deletions xdmod_data/warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,3 +441,5 @@ def __describe_metrics_or_dimensions(self, realm, m_or_d):
('id', 'label', 'description'),
'id',
)


Loading