Skip to content

Commit

Permalink
Fix bug with trailing slashes in xdmod_host. (#24)
Browse files Browse the repository at this point in the history
Co-authored-by: Aaron Weeden <[email protected]>
  • Loading branch information
RodneyCodess and aaronweeden authored Jun 5, 2024
1 parent 014e223 commit 82edbdc
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Remove limit on number of results returned from `get_filter_values()` ([\#21](https://github.com/ubccr/xdmod-data/pull/21)).
- Add a "Feedback / Feature Requests" section to the README ([\#22](https://github.com/ubccr/xdmod-notebooks/pull/22)).
- Improve performance of validation of filters and raw fields ([\#18](https://github.com/ubccr/xdmod-data/pull/18)).
- Fix bug with trailing slashes in `xdmod_host` ([\#24](https://github.com/ubccr/xdmod-data/pull/24)).

## v1.0.0 (2023-07-21)
- Initial release.
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)},
),
(
method,
'end_date',
{'duration': (VALID_DATE, INVALID_STR)},
),
]
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'):
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())],
indirect=['dw_methods'],
)
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: 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

0 comments on commit 82edbdc

Please sign in to comment.