From 3824bc9a50c6464a392a1266aa91c04571924236 Mon Sep 17 00:00:00 2001 From: Spiros Delviniotis Date: Wed, 10 May 2017 18:26:27 +0200 Subject: [PATCH] applied requested changes Signed-off-by: Spiros Delviniotis --- hepcrawl/utils.py | 6 +++--- tests/functional/WSP/test_wsp.py | 31 +++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/hepcrawl/utils.py b/hepcrawl/utils.py index 9794a621..ae614533 100644 --- a/hepcrawl/utils.py +++ b/hepcrawl/utils.py @@ -78,9 +78,9 @@ def local_list_files(local_folder, target_folder): def list_missing_files(remote_folder, target_folder, file_names): missing_files = [] - for filename in file_names: - destination_file = os.path.join(target_folder, filename) - source_file = os.path.join(remote_folder, filename) + for file_name in file_names: + destination_file = os.path.join(target_folder, file_name) + source_file = os.path.join(remote_folder, file_name) if not os.path.exists(destination_file): missing_files.append(source_file) diff --git a/tests/functional/WSP/test_wsp.py b/tests/functional/WSP/test_wsp.py index 4626c19d..5898b5cd 100644 --- a/tests/functional/WSP/test_wsp.py +++ b/tests/functional/WSP/test_wsp.py @@ -53,8 +53,8 @@ def expected_results(): @pytest.fixture(scope="function") def set_up_ftp_environment(): - netrc_location = os.path.join(os.path.dirname( - os.path.realpath(__file__)), + netrc_location = os.path.join( + os.path.dirname(os.path.realpath(__file__)), os.path.join('fixtures', 'ftp_server', '.netrc') ) @@ -72,9 +72,9 @@ def set_up_ftp_environment(): @pytest.fixture(scope="function") def set_up_local_environment(): - package_location = os.path.join(os.path.dirname( - os.path.realpath(__file__)), - 'fixtures/ftp_server/WSP/' + package_location = os.path.join( + os.path.dirname(os.path.realpath(__file__)), + os.path.join('fixtures', 'ftp_server', 'WSP') ) yield { @@ -86,7 +86,16 @@ def set_up_local_environment(): } clean_dir() - clean_dir(package_location + 'IDAQPv20i01-03160015-1510863') + remove_generated_files(package_location) + + +def remove_generated_files(package_location): + for _, dirs, files in os.walk(package_location): + for dir_name in dirs: + clean_dir(os.path.join(package_location, dir_name)) + for file_name in files: + if '.zip' not in file_name: + os.unlink(os.path.join(package_location, file_name)) def clean_dir(path='/tmp/WSP/'): @@ -110,8 +119,10 @@ def test_wsp_ftp(set_up_ftp_environment, expected_results): **set_up_ftp_environment.get('CRAWLER_ARGUMENTS') ) - assert [override_generated_fields(result) for result in results] == \ - [override_generated_fields(expected) for expected in expected_results] + gotten_results = [override_generated_fields(result) for result in results] + expected_results = [override_generated_fields(expected) for expected in expected_results] + + assert gotten_results == expected_results def test_wsp_local_package_path(set_up_local_environment, expected_results): @@ -128,7 +139,7 @@ def test_wsp_local_package_path(set_up_local_environment, expected_results): **set_up_local_environment.get('CRAWLER_ARGUMENTS') ) - gottern_results = [override_generated_fields(result) for result in results] + gotten_results = [override_generated_fields(result) for result in results] expected_results = [override_generated_fields(expected) for expected in expected_results] - assert gottern_results == expected_results + assert gotten_results == expected_results