From 2b1cfbddff8956f906fa5ee2e095a625ec06d35a Mon Sep 17 00:00:00 2001 From: Allan CORNET Date: Fri, 25 Oct 2024 19:17:38 +0200 Subject: [PATCH] update webtools tests with new url --- modules/webtools/tests/test_websave_1.m | 3 ++- modules/webtools/tests/test_websave_2.m | 1 + modules/webtools/tests/test_websave_3.m | 22 +++++++++++++------- modules/webtools/tests/test_websave_4.m | 5 +++-- modules/webtools/tests/test_websave_5.m | 3 ++- modules/webtools/tests/test_websave_6.m | 1 + modules/webtools/tests/test_websave_delete.m | 1 + modules/webtools/tests/test_websave_get_1.m | 1 + modules/webtools/tests/test_websave_get_2.m | 1 + modules/webtools/tests/test_websave_get_3.m | 1 + modules/webtools/tests/test_websave_patch.m | 2 ++ modules/webtools/tests/test_websave_post.m | 1 + modules/webtools/tests/test_websave_url_1.m | 1 + modules/webtools/tests/test_websave_url_2.m | 1 + modules/webtools/tests/test_websave_url_3.m | 1 + modules/webtools/tests/test_websave_url_4.m | 1 + modules/webtools/tests/test_websave_url_5.m | 1 + 17 files changed, 35 insertions(+), 12 deletions(-) diff --git a/modules/webtools/tests/test_websave_1.m b/modules/webtools/tests/test_websave_1.m index 7702fd32d4..364f412aa1 100644 --- a/modules/webtools/tests/test_websave_1.m +++ b/modules/webtools/tests/test_websave_1.m @@ -12,8 +12,9 @@ %============================================================================= url = 'https://apod.nasa.gov/apod/image/2310/MoValleyEclipse.jpg'; filename = [tempdir(), 'MoValleyEclipse_2.jpg']; +options = weboptions('Timeout', 120); try - destination_filename = websave(filename, url); + destination_filename = websave(filename, url, options); catch ex R = strcmp(ex.message, _('Forbidden (403)')) || ... strcmp(ex.message, _('Timeout was reached')) || ... diff --git a/modules/webtools/tests/test_websave_2.m b/modules/webtools/tests/test_websave_2.m index 7789e8a60b..e88207e9db 100644 --- a/modules/webtools/tests/test_websave_2.m +++ b/modules/webtools/tests/test_websave_2.m @@ -19,6 +19,7 @@ strcmp(ex.message, _('Couldn''t resolve host name')); skip_testsuite(R, ex.message) end +assert_istrue(isfile(destination_filename)); info = dir(destination_filename); assert_istrue(info.bytes > 1000); txt = fileread(destination_filename); diff --git a/modules/webtools/tests/test_websave_3.m b/modules/webtools/tests/test_websave_3.m index 226176bde8..bbe1e70426 100644 --- a/modules/webtools/tests/test_websave_3.m +++ b/modules/webtools/tests/test_websave_3.m @@ -7,14 +7,18 @@ % SPDX-License-Identifier: LGPL-3.0-or-later % LICENCE_BLOCK_END %============================================================================= -url = 'https://neo.gsfc.nasa.gov/wms/wms'; +url = 'https://s.w-x.co/staticmaps/WEB_Current_Weather_Map_1280x720.jpg?crop=16:9&width=800&format=pjpg&auto=webp&quality=60'; filename = [tempdir(), 'earth2.jpg']; +if isfile(filename) + rmfile(filename); +end testPass = false; i = 0; retry = true; while (retry) try - destination_filename = websave(filename, url, 'Time', '2019-06-01', 'Service', 'WMS', 'Layers', 'BlueMarbleNG-TB', 'CRS', 'CRS:84', 'Format', 'image/jpeg', 'Height',768, 'Width', 1024,'BBOX','-180.0,-90.0,180.0,90.0','Version','1.3.0','Request','GetMap'); + destination_filename = websave(filename, url); + testPass = true; catch ex testPass = (strcmp(ex.message, 'Bad Request (400)') == 1); if ~testPass @@ -24,11 +28,13 @@ i = i + 1; retry = ~testPass && (i < 5); end - -R = strcmp(ex.message, _('Forbidden (403)')) || ... -strcmp(ex.message, _('Timeout was reached')) || ... -strcmp(ex.message, _('Couldn''t resolve host name')); -skip_testsuite(R, ex.message) - +if isvar('ex') + R = strcmp(ex.message, _('Forbidden (403)')) || ... + strcmp(ex.message, _('Bad Request (400)')) || ... + strcmp(ex.message, _('Timeout was reached')) || ... + strcmp(ex.message, _('Couldn''t resolve host name')); + skip_testsuite(R, ex.message) +end +assert_istrue(isfile(destination_filename)); assert_istrue(testPass) %============================================================================= diff --git a/modules/webtools/tests/test_websave_4.m b/modules/webtools/tests/test_websave_4.m index 69127af7a1..ea48c45a2a 100644 --- a/modules/webtools/tests/test_websave_4.m +++ b/modules/webtools/tests/test_websave_4.m @@ -12,12 +12,13 @@ options = weboptions('Timeout', Inf); try destination_filename = websave(filename, url, options); - info = dir(destination_filename); - assert_istrue(info.bytes > 0); catch ex R = strcmp(ex.message, _('Forbidden (403)')) || ... strcmp(ex.message, _('Timeout was reached')) || ... strcmp(ex.message, _('Couldn''t resolve host name')); skip_testsuite(R, ex.message) end +assert_istrue(isfile(destination_filename)); +info = dir(destination_filename); +assert_istrue(info.bytes > 0); %============================================================================= diff --git a/modules/webtools/tests/test_websave_5.m b/modules/webtools/tests/test_websave_5.m index 4fdd8a2b4c..1ce7c5a19a 100644 --- a/modules/webtools/tests/test_websave_5.m +++ b/modules/webtools/tests/test_websave_5.m @@ -19,7 +19,8 @@ strcmp(ex.message, _('Couldn''t resolve host name')); skip_testsuite(R, ex.message) end -txt = fileread(filename); +assert_istrue(isfile(destination_filename)); +txt = fileread(destination_filename); st = jsondecode(txt); assert_isequal(st(1).email, 'Eliseo@gardner.biz'); %============================================================================= diff --git a/modules/webtools/tests/test_websave_6.m b/modules/webtools/tests/test_websave_6.m index 5f559f1a9f..5d1958bfb7 100644 --- a/modules/webtools/tests/test_websave_6.m +++ b/modules/webtools/tests/test_websave_6.m @@ -19,6 +19,7 @@ strcmp(ex.message, _('Couldn''t resolve host name')); skip_testsuite(R, ex.message) end +assert_istrue(isfile(destination_filename)); info = dir(destination_filename); assert_istrue(info.bytes > 200); %============================================================================= diff --git a/modules/webtools/tests/test_websave_delete.m b/modules/webtools/tests/test_websave_delete.m index 38e622d284..38e657b868 100644 --- a/modules/webtools/tests/test_websave_delete.m +++ b/modules/webtools/tests/test_websave_delete.m @@ -17,6 +17,7 @@ strcmp(ex.message, _('Couldn''t resolve host name')); skip_testsuite(R, ex.message) end +assert_istrue(isfile(fullname)); R = jsondecode(fileread(fullname)); REF = struct(); assert_isequal(R, REF); diff --git a/modules/webtools/tests/test_websave_get_1.m b/modules/webtools/tests/test_websave_get_1.m index 1f7675dc88..17110eff3a 100644 --- a/modules/webtools/tests/test_websave_get_1.m +++ b/modules/webtools/tests/test_websave_get_1.m @@ -11,6 +11,7 @@ filename = [tempdir(), 'MoValleyEclipse_1.jpg']; try outfilename = websave(filename, url); + assert_istrue(isfile(outfilename)); catch ex R = strcmp(ex.message, _('Forbidden (403)')) || ... strcmp(ex.message, _('Timeout was reached')) || ... diff --git a/modules/webtools/tests/test_websave_get_2.m b/modules/webtools/tests/test_websave_get_2.m index 28eeabe4a3..b84566ec23 100644 --- a/modules/webtools/tests/test_websave_get_2.m +++ b/modules/webtools/tests/test_websave_get_2.m @@ -17,6 +17,7 @@ strcmp(ex.message, _('Couldn''t resolve host name')); skip_testsuite(R, ex.message) end +assert_istrue(isfile(fullname)); R = jsondecode(fileread(fullname)); assert_isequal(R(5).email, 'Hayden@althea.biz'); %============================================================================= \ No newline at end of file diff --git a/modules/webtools/tests/test_websave_get_3.m b/modules/webtools/tests/test_websave_get_3.m index ea5ae484ea..311f8985e0 100644 --- a/modules/webtools/tests/test_websave_get_3.m +++ b/modules/webtools/tests/test_websave_get_3.m @@ -16,6 +16,7 @@ strcmp(ex.message, _('Couldn''t resolve host name')); skip_testsuite(R, ex.message) end +assert_istrue(isfile(fullname)); R = jsondecode(fileread(fullname)); assert_isequal(R(5).email, 'Hayden@althea.biz'); %============================================================================= diff --git a/modules/webtools/tests/test_websave_patch.m b/modules/webtools/tests/test_websave_patch.m index 301f5519fc..537c42d0e9 100644 --- a/modules/webtools/tests/test_websave_patch.m +++ b/modules/webtools/tests/test_websave_patch.m @@ -17,6 +17,7 @@ strcmp(ex.message, _('Couldn''t resolve host name')); skip_testsuite(R, ex.message) end +assert_istrue(isfile(fullname)); R = jsondecode(fileread(fullname)); assert_isequal(R.id, 1); %============================================================================= @@ -29,6 +30,7 @@ strcmp(ex.message, _('Couldn''t resolve host name')); skip_testsuite(R, ex.message) end +assert_istrue(isfile(fullname)); R = jsondecode(fileread(fullname)); assert_isequal(R.id, 1); %============================================================================= diff --git a/modules/webtools/tests/test_websave_post.m b/modules/webtools/tests/test_websave_post.m index 3ccffd7840..9b5a5e6730 100644 --- a/modules/webtools/tests/test_websave_post.m +++ b/modules/webtools/tests/test_websave_post.m @@ -18,6 +18,7 @@ strcmp(ex.message, _('Couldn''t resolve host name')); skip_testsuite(R, ex.message) end +assert_istrue(isfile(fullname)); R = jsondecode(fileread(fullname)); assert_isequal(R.id, 101); %============================================================================= diff --git a/modules/webtools/tests/test_websave_url_1.m b/modules/webtools/tests/test_websave_url_1.m index 7062afda7a..fdd8a87bd8 100644 --- a/modules/webtools/tests/test_websave_url_1.m +++ b/modules/webtools/tests/test_websave_url_1.m @@ -21,6 +21,7 @@ end end skip_testsuite(~ok, 'Timeout reached') +assert_istrue(isfile(fullname)); R = jsondecode(fileread(fullname)); assert_istrue(isstruct(R.args)); assert_isequal(fieldnames(R.args), {'b_'; 'r'}); diff --git a/modules/webtools/tests/test_websave_url_2.m b/modules/webtools/tests/test_websave_url_2.m index 18727597fb..5c71b3804e 100644 --- a/modules/webtools/tests/test_websave_url_2.m +++ b/modules/webtools/tests/test_websave_url_2.m @@ -21,5 +21,6 @@ strcmp(ex.message, _('Couldn''t resolve host name')); skip_testsuite(R, ex.message) end +assert_istrue(isfile(fullname)); R = jsondecode(fileread(fullname)) %============================================================================= diff --git a/modules/webtools/tests/test_websave_url_3.m b/modules/webtools/tests/test_websave_url_3.m index 5e015945ab..6a82a3586d 100644 --- a/modules/webtools/tests/test_websave_url_3.m +++ b/modules/webtools/tests/test_websave_url_3.m @@ -21,5 +21,6 @@ strcmp(ex.message, _('Couldn''t resolve host name')); skip_testsuite(R, ex.message) end +assert_istrue(isfile(fullname)); R = jsondecode(fileread(fullname)) %============================================================================= diff --git a/modules/webtools/tests/test_websave_url_4.m b/modules/webtools/tests/test_websave_url_4.m index 3ccf81a148..f0d8536aa8 100644 --- a/modules/webtools/tests/test_websave_url_4.m +++ b/modules/webtools/tests/test_websave_url_4.m @@ -21,5 +21,6 @@ strcmp(ex.message, _('Couldn''t resolve host name')); skip_testsuite(R, ex.message) end +assert_istrue(isfile(fullname)); R = jsondecode(fileread(fullname)) %============================================================================= diff --git a/modules/webtools/tests/test_websave_url_5.m b/modules/webtools/tests/test_websave_url_5.m index 9e77e315c3..5cb945939d 100644 --- a/modules/webtools/tests/test_websave_url_5.m +++ b/modules/webtools/tests/test_websave_url_5.m @@ -21,5 +21,6 @@ strcmp(ex.message, _('Couldn''t resolve host name')); skip_testsuite(R, ex.message) end +assert_istrue(isfile(fullname)); R = jsondecode(fileread(fullname)) %=============================================================================