Skip to content

Commit

Permalink
Merge branch 'master' into build-download-file-url
Browse files Browse the repository at this point in the history
  • Loading branch information
burnout87 authored Apr 16, 2024
2 parents 0549ff4 + 288c40d commit ad90bb4
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
9 changes: 6 additions & 3 deletions dispatcher_plugin_nb2workflow/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ def construct_parameter_lists(backend_param_dict, ontology_path):
"http://odahub.io/ontology#StartTime": "T1",
"http://odahub.io/ontology#EndTime": "T2",
"http://odahub.io/ontology#AstrophysicalObject": "src_name",
"ThisNameShouldNotExist": "token"
"ThisNameShouldNotExist": "token",
}
par_name_substitution = {}

par_name_substitution = {'token': '_token'}
# There are two name substitutions for "*token":
# 1) if backend notebook defines parameter named "token", it will be renamed by general mechanism (appending "_rename")
# 2) the actual token (represented as SourceQuery parameter "token") will be sent to backend as "_token" request argument

plist = []
source_plist = []
for pname, pval in backend_param_dict.items():
Expand Down
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ def trace_get_func_handler(request: Request):

return Response(test_output_content, status=200)

def return_request_query_dict(request: Request):
parsed_request_query = parse_qs(urlparse(request.url).query)
resp = '{"exceptions": [], "output": {"result": '+json.dumps(parsed_request_query)+'}}'
return Response(resp,
status=200, content_type='application/json')


@pytest.fixture
def mock_backend(httpserver):
Expand All @@ -120,6 +126,7 @@ def mock_backend(httpserver):
httpserver.expect_request(f'/api/v1.0/get/image').respond_with_json(image_json)
# httpserver.expect_request(f'/trace/nb2w-ylp5ovnm/lightcurve').respond_with_data(test_output_html)
httpserver.expect_request(f'/trace/nb2w-ylp5ovnm/lightcurve').respond_with_handler(trace_get_func_handler)
httpserver.expect_request(f'/api/v1.0/get/dummy_echo').respond_with_handler(return_request_query_dict)

@pytest.fixture(scope='session')
def conf_file(tmp_path_factory):
Expand Down
14 changes: 14 additions & 0 deletions tests/responses/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@
}
}
},
"dummy_echo": {
"output": {
"result": {
"comment": "",
"name": "result",
"owl_type": "http://odahub.io/ontology#String",
"python_type": {
"type_object": "<class 'str'>"
},
"value": "foo"
}
},
"parameters": {}
},
"image": {
"output": {
"result": {
Expand Down
30 changes: 30 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def test_instrument_products(dispatcher_live_fixture, mock_backend):
if isinstance(elem, dict) and 'prod_dict' in elem.keys():
prod_dict = elem['prod_dict']
assert prod_dict == {'ascii_binary': 'ascii_binary_query',
'dummy_echo': 'dummy_echo_query',
'image': 'image_query',
'file_download': 'file_download_query',
'lightcurve': 'lightcurve_query',
Expand Down Expand Up @@ -958,3 +959,32 @@ def test_kg_based_instrument_parameters(conf_file, dispatcher_live_fixture, capl
fd.write(conf_bk)
os.remove(tmpkg)

@pytest.mark.parametrize('privileged', [True, False])
def test_underscored_token(dispatcher_live_fixture, mock_backend, privileged):
server = dispatcher_live_fixture
logger.info("constructed server: %s", server)

params = {'instrument': 'example0',
'query_status': 'new',
'query_type': 'Real',
'product_type': 'dummy_echo',
'run_asynch': False,
'api': True}
if privileged:
params['token'] = encoded_token

c = requests.get(server + "/run_analysis",
params = params)

logger.info("content: %s", c.text)
jdata = c.json()
logger.info(json.dumps(jdata, indent=4, sort_keys=True))
logger.info(jdata)
assert c.status_code == 200
product = jdata['products']['text_product_list'][0]['value']
assert 'token' not in product
if privileged:
assert '_token' in product
assert product['_token'][0] == encoded_token
else:
assert '_token' not in product

0 comments on commit ad90bb4

Please sign in to comment.