Skip to content

Commit

Permalink
testing validators latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
burnout87 committed May 28, 2024
1 parent 17535fb commit 676b75f
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cdci_data_analysis/flask_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def run_api_instr_list():
logger.warning('\nThe endpoint \'/api/instr-list\' is deprecated and you will be automatically redirected to the '
'\'/instr-list\' endpoint. Please use this one in the future.\n')

if app.config['conf'].products_url is not None and validators.url(app.config['conf'].products_url):
if app.config['conf'].products_url is not None and validators.url(app.config['conf'].products_url, simple_host=True):
# TODO remove the dispatch-data part, better to have it extracted from the configuration file
redirection_url = os.path.join(app.config['conf'].products_url, 'dispatch-data/instr-list')
if request.args:
Expand Down Expand Up @@ -160,7 +160,7 @@ def download_products():

@app.route("/download_file", methods=['POST', 'GET', 'HEAD'])
def download_file():
if app.config['conf'].products_url is not None and validators.url(app.config['conf'].products_url):
if app.config['conf'].products_url is not None and validators.url(app.config['conf'].products_url, simple_host=True):
# TODO remove the dispatch-data part, better to have it extracted from the configuration file
redirection_url = os.path.join(app.config['conf'].products_url, 'dispatch-data/download_products')
if request.args:
Expand Down
33 changes: 33 additions & 0 deletions cdci_data_analysis/pytest_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,19 @@ def dispatcher_test_conf_with_external_products_url_fn(dispatcher_test_conf_fn):
yield fn


@pytest.fixture
def dispatcher_test_conf_with_default_route_products_url_fn(dispatcher_test_conf_fn):
fn = dispatcher_test_conf_fn
with open(fn, "r+") as f:
data = f.read()
data = re.sub('(\s+products_url:).*\n', '\n products_url: http://0.0.0.0:1234/mmoda/\n', data)
f.seek(0)
f.write(data)
f.truncate()

yield fn


@pytest.fixture
def dispatcher_test_conf_no_resubmit_timeout_fn(dispatcher_test_conf_fn):
fn = dispatcher_test_conf_fn
Expand Down Expand Up @@ -677,6 +690,13 @@ def dispatcher_test_conf_with_external_products_url(dispatcher_test_conf_with_ex
yield loaded_yaml['dispatcher']


@pytest.fixture
def dispatcher_test_conf_with_default_route_products_url(dispatcher_test_conf_with_default_route_products_url_fn):
with open(dispatcher_test_conf_with_default_route_products_url_fn) as yaml_f:
loaded_yaml = yaml.load(yaml_f, Loader=yaml.SafeLoader)
yield loaded_yaml['dispatcher']


def dispatcher_test_conf_with_no_resubmit_timeout(dispatcher_test_conf_with_no_resubmit_timeout_fn):
with open(dispatcher_test_conf_with_no_resubmit_timeout_fn) as yaml_f:
loaded_yaml = yaml.load(yaml_f, Loader=yaml.SafeLoader)
Expand Down Expand Up @@ -1126,6 +1146,19 @@ def dispatcher_live_fixture_with_external_products_url(pytestconfig, dispatcher_
os.kill(pid, signal.SIGINT)


@pytest.fixture
def dispatcher_live_fixture_with_default_route_products_url(pytestconfig, dispatcher_test_conf_with_default_route_products_url_fn, dispatcher_debug):
dispatcher_state = start_dispatcher(pytestconfig.rootdir, dispatcher_test_conf_with_default_route_products_url_fn)

service = dispatcher_state['url']
pid = dispatcher_state['pid']

yield service

kill_child_processes(pid, signal.SIGINT)
os.kill(pid, signal.SIGINT)


@pytest.fixture
def dispatcher_live_fixture_with_renku_options(pytestconfig, dispatcher_test_conf_with_renku_options_fn, dispatcher_debug):
dispatcher_state = start_dispatcher(pytestconfig.rootdir, dispatcher_test_conf_with_renku_options_fn)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ MarkupSafe==2.0.1
# TODO: needed by some plugins: migrate
simple_logger
matplotlib
validators==0.27.0
validators==0.28.0
pillow>=10.0.1 # not directly required, pinned by Snyk to avoid a vulnerability
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"nbformat",
"giturlparse",
"sentry-sdk",
"validators==0.27.0",
"validators==0.28.0",
"jsonschema"
]

Expand Down
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
dispatcher_test_conf_with_gallery_fn,
dispatcher_test_conf_with_gallery_no_resolver_fn,
dispatcher_live_fixture_with_external_products_url,
dispatcher_live_fixture_with_default_route_products_url,
dispatcher_test_conf_with_external_products_url_fn,
dispatcher_test_conf_with_default_route_products_url_fn,
dispatcher_test_conf_with_external_products_url,
dispatcher_test_conf_with_default_route_products_url,
dispatcher_test_conf_no_resubmit_timeout_fn,
dispatcher_test_conf_with_matrix_options,
dispatcher_test_conf_with_matrix_options_fn,
Expand Down
49 changes: 49 additions & 0 deletions tests/test_server_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,31 @@ def test_download_file_redirection_external_products_url(dispatcher_live_fixture
assert redirection_url == redirection_header_location_url


@pytest.mark.fast
@pytest.mark.parametrize("include_args", [True, False])
def test_download_file_redirection_default_route_products_url(dispatcher_live_fixture_with_default_route_products_url,
dispatcher_test_conf_with_default_route_products_url,
include_args):
server = dispatcher_live_fixture_with_default_route_products_url

logger.info("constructed server: %s", server)

url_request = os.path.join(server, "download_file")

if include_args:
url_request += '?a=4566&token=aaaaaaaaaa'

c = requests.get(url_request, allow_redirects=False)

assert c.status_code == 302
redirection_header_location_url = c.headers["Location"]
redirection_url = os.path.join(dispatcher_test_conf_with_default_route_products_url['products_url'], 'dispatch-data/download_products')
if include_args:
redirection_url += '?a=4566&token=aaaaaaaaaa'
redirection_url += '&from_request_files_dir=True&download_file=True&download_products=False'
assert redirection_url == redirection_header_location_url


@pytest.mark.fast
@pytest.mark.parametrize("include_args", [True, False])
def test_download_file_redirection_no_custom_products_url(dispatcher_live_fixture_no_products_url,
Expand Down Expand Up @@ -854,6 +879,30 @@ def test_instrument_list_redirection_external_products_url(dispatcher_live_fixtu
assert redirection_url == redirection_header_location_url


@pytest.mark.fast
@pytest.mark.parametrize("include_args", [True, False])
def test_instrument_list_redirection_default_route_products_url(dispatcher_live_fixture_with_default_route_products_url,
dispatcher_test_conf_with_default_route_products_url,
include_args):
server = dispatcher_live_fixture_with_default_route_products_url

logger.info("constructed server: %s", server)

url_request = os.path.join(server, "api/instr-list")

if include_args:
url_request += '?a=4566&token=aaaaaaaaaa'

c = requests.get(url_request, allow_redirects=False)

assert c.status_code == 302
redirection_header_location_url = c.headers["Location"]
redirection_url = os.path.join(dispatcher_test_conf_with_default_route_products_url['products_url'], 'dispatch-data/instr-list')
if include_args:
redirection_url += '?a=4566&token=aaaaaaaaaa'
assert redirection_url == redirection_header_location_url


@pytest.mark.fast
@pytest.mark.parametrize("allow_redirect", [True, False])
@pytest.mark.parametrize("include_args", [True, False])
Expand Down

0 comments on commit 676b75f

Please sign in to comment.