From d48931a37bbfa6bd4511dd07ca0ecb7467bb009c Mon Sep 17 00:00:00 2001 From: StefanStrobel <> Date: Tue, 31 May 2022 18:21:04 +0000 Subject: [PATCH] 98_HTTPMOD: updated tests git-svn-id: https://svn.fhem.de/fhem/trunk@26103 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/t/FHEM/98_HTTPMOD/10_Redirects.cfg | 12 +- fhem/t/FHEM/98_HTTPMOD/10_Redirects.testdata | 24 ++-- fhem/t/FHEM/98_HTTPMOD/11_Cookies.cfg | 10 +- fhem/t/FHEM/98_HTTPMOD/11_Cookies1.testdata | 32 ++--- fhem/t/FHEM/98_HTTPMOD/11_Cookies2.testdata | 30 ++--- fhem/t/FHEM/98_HTTPMOD/12_Chains.cfg | 36 ++--- fhem/t/FHEM/98_HTTPMOD/20_extractAllJSON.cfg | 4 +- fhem/t/FHEM/98_HTTPMOD/30_requestExpr.cfg | 60 ++++----- fhem/t/FHEM/98_HTTPMOD/31_Regexes.cfg | 134 +++++++++---------- fhem/t/FHEM/98_HTTPMOD/32_SetExpr.cfg | 9 ++ fhem/t/FHEM/98_HTTPMOD/32_SetExpr.t | 33 +++++ fhem/t/FHEM/98_HTTPMOD/33_SetExtensions.cfg | 18 +++ fhem/t/FHEM/98_HTTPMOD/33_SetExtensions.t | 58 ++++++++ fhem/t/FHEM/98_HTTPMOD/36_JSONExpr.cfg | 56 ++++---- fhem/t/FHEM/98_HTTPMOD/39_Map.cfg | 15 +++ fhem/t/FHEM/98_HTTPMOD/39_Map.t | 24 ++++ fhem/t/FHEM/98_HTTPMOD/40_maxAge.cfg | 66 ++++----- fhem/t/FHEM/98_HTTPMOD/40_maxAge.t | 49 +++++-- fhem/t/FHEM/98_HTTPMOD/50_Replacements.cfg | 36 ++--- fhem/t/FHEM/98_HTTPMOD/90_SmallFeatures.cfg | 32 ++--- fhem/t/FHEM/98_HTTPMOD/90_SmallFeatures.t | 11 +- fhem/t/FHEM/98_HTTPMOD/99_evalExpr.cfg | 8 +- fhem/t/FHEM/98_HTTPMOD/Charset.testdata | 26 ++-- fhem/t/FHEM/98_HTTPMOD/Charset.testdata-utf8 | 28 ++-- fhem/t/FHEM/98_HTTPMOD/Charset.testdata2 | 94 ++++++------- 25 files changed, 546 insertions(+), 359 deletions(-) create mode 100644 fhem/t/FHEM/98_HTTPMOD/32_SetExpr.cfg create mode 100644 fhem/t/FHEM/98_HTTPMOD/32_SetExpr.t create mode 100644 fhem/t/FHEM/98_HTTPMOD/33_SetExtensions.cfg create mode 100644 fhem/t/FHEM/98_HTTPMOD/33_SetExtensions.t create mode 100644 fhem/t/FHEM/98_HTTPMOD/39_Map.cfg create mode 100644 fhem/t/FHEM/98_HTTPMOD/39_Map.t diff --git a/fhem/t/FHEM/98_HTTPMOD/10_Redirects.cfg b/fhem/t/FHEM/98_HTTPMOD/10_Redirects.cfg index 9f4e64b0c..a90df66c5 100644 --- a/fhem/t/FHEM/98_HTTPMOD/10_Redirects.cfg +++ b/fhem/t/FHEM/98_HTTPMOD/10_Redirects.cfg @@ -1,6 +1,6 @@ -define H2 HTTPMOD file://t/FHEM/98_HTTPMOD/10_Redirects.testdata 0 -attr H2 verbose 5 -attr H2 fileHeaderSplit --end-of-http-header-- -attr H2 queueDelay 2 -attr H2 minSendDelay 2 - +define H2 HTTPMOD file://t/FHEM/98_HTTPMOD/10_Redirects.testdata 0 +attr H2 verbose 5 +attr H2 fileHeaderSplit --end-of-http-header-- +attr H2 queueDelay 2 +attr H2 minSendDelay 2 + diff --git a/fhem/t/FHEM/98_HTTPMOD/10_Redirects.testdata b/fhem/t/FHEM/98_HTTPMOD/10_Redirects.testdata index bcb111081..51067171e 100644 --- a/fhem/t/FHEM/98_HTTPMOD/10_Redirects.testdata +++ b/fhem/t/FHEM/98_HTTPMOD/10_Redirects.testdata @@ -1,13 +1,13 @@ -HTTP/1.1 301 Moved Permanently -Content-Type: text/html -Content-Length: 162 -Connection: close -Location: http://test.url/ ---end-of-http-header-- - -301 Moved Permanently - -

301 Moved Permanently

-
nginx
- +HTTP/1.1 301 Moved Permanently +Content-Type: text/html +Content-Length: 162 +Connection: close +Location: http://test.url/ +--end-of-http-header-- + +301 Moved Permanently + +

301 Moved Permanently

+
nginx
+ \ No newline at end of file diff --git a/fhem/t/FHEM/98_HTTPMOD/11_Cookies.cfg b/fhem/t/FHEM/98_HTTPMOD/11_Cookies.cfg index 286ea63d3..0094d92f9 100644 --- a/fhem/t/FHEM/98_HTTPMOD/11_Cookies.cfg +++ b/fhem/t/FHEM/98_HTTPMOD/11_Cookies.cfg @@ -1,5 +1,5 @@ -define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/11_Cookies1.testdata 0 -attr H1 verbose 4 -attr H1 fileHeaderSplit --end-of-http-header-- -attr H1 queueDelay 0 -attr H1 minSendDelay 0 +define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/11_Cookies1.testdata 0 +attr H1 verbose 4 +attr H1 fileHeaderSplit --end-of-http-header-- +attr H1 queueDelay 0 +attr H1 minSendDelay 0 diff --git a/fhem/t/FHEM/98_HTTPMOD/11_Cookies1.testdata b/fhem/t/FHEM/98_HTTPMOD/11_Cookies1.testdata index 27f8b9f3e..8553462f9 100644 --- a/fhem/t/FHEM/98_HTTPMOD/11_Cookies1.testdata +++ b/fhem/t/FHEM/98_HTTPMOD/11_Cookies1.testdata @@ -1,17 +1,17 @@ -HTTP/1.1 200 OK -Content-Type: text/html -Content-Length: 162 -Connection: close -Location: http://test.url/ -Set-Cookie: dp1=bbl/DE630e14e5^; Domain=.test.url; Path=/; Expires=Tue, 30 Aug 2022 13:47:17 GMT -Set-Cookie: nonsession=BAQAAAXQoEGjGAAaAADMABWEs4WU3NDA3OADKACBjDhTlM2Y5ZjQ1YmUxNzQwYTRjYzM0OTY5YzQzZmZmZmY2ZmQAywABX0u07TLAaYu0UeO4rce7q1K5pFM1stQGag**; Domain=.test.url; Path=/; Expires=Tue, 30 Aug 2022 13:47:17 GMT -Set-Cookie: s=CgAD4ACBfTP9kM2Y5ZjQ1YmUxNzQwYTRjYzM0OTY5YzQzZmZmZmY2ZmRcvqYq; Domain=.test.url; Path=/; HttpOnly -Set-Cookie: ebay=%5Esbf%3D%23000000%5E; Domain=.test.url; Path=/ ---end-of-http-header-- - -Test - -

Test

-
nginx
- +HTTP/1.1 200 OK +Content-Type: text/html +Content-Length: 162 +Connection: close +Location: http://test.url/ +Set-Cookie: dp1=bbl/DE630e14e5^; Domain=.test.url; Path=/; Expires=Tue, 30 Aug 2022 13:47:17 GMT +Set-Cookie: nonsession=BAQAAAXQoEGjGAAaAADMABWEs4WU3NDA3OADKACBjDhTlM2Y5ZjQ1YmUxNzQwYTRjYzM0OTY5YzQzZmZmZmY2ZmQAywABX0u07TLAaYu0UeO4rce7q1K5pFM1stQGag**; Domain=.test.url; Path=/; Expires=Tue, 30 Aug 2022 13:47:17 GMT +Set-Cookie: s=CgAD4ACBfTP9kM2Y5ZjQ1YmUxNzQwYTRjYzM0OTY5YzQzZmZmZmY2ZmRcvqYq; Domain=.test.url; Path=/; HttpOnly +Set-Cookie: ebay=%5Esbf%3D%23000000%5E; Domain=.test.url; Path=/ +--end-of-http-header-- + +Test + +

Test

+
nginx
+ \ No newline at end of file diff --git a/fhem/t/FHEM/98_HTTPMOD/11_Cookies2.testdata b/fhem/t/FHEM/98_HTTPMOD/11_Cookies2.testdata index c78206071..601bd8cf3 100644 --- a/fhem/t/FHEM/98_HTTPMOD/11_Cookies2.testdata +++ b/fhem/t/FHEM/98_HTTPMOD/11_Cookies2.testdata @@ -1,16 +1,16 @@ -HTTP/1.1 200 OK -Content-Type: text/html -Content-Length: 162 -Connection: close -Location: http://test.url/ -Set-Cookie: dp1=bbl/DE630e14e5^; Domain=.test.url; Path=/; Expires=Tue, 30 Aug 2022 13:47:17 GMT -Set-Cookie: s=CgAD4ACBfTP9kM2Y5ZjQ1YmUxNzQwYTRjYzM0OTY5YzQzZmZmZmY2ZmRcvqYq; Domain=.test.url; Path=/; HttpOnly -Set-Cookie: ebay=%5Esbf%3D%23000000%5E; Domain=.test.url; Path=/ ---end-of-http-header-- - -Test - -

Test

-
nginx
- +HTTP/1.1 200 OK +Content-Type: text/html +Content-Length: 162 +Connection: close +Location: http://test.url/ +Set-Cookie: dp1=bbl/DE630e14e5^; Domain=.test.url; Path=/; Expires=Tue, 30 Aug 2022 13:47:17 GMT +Set-Cookie: s=CgAD4ACBfTP9kM2Y5ZjQ1YmUxNzQwYTRjYzM0OTY5YzQzZmZmZmY2ZmRcvqYq; Domain=.test.url; Path=/; HttpOnly +Set-Cookie: ebay=%5Esbf%3D%23000000%5E; Domain=.test.url; Path=/ +--end-of-http-header-- + +Test + +

Test

+
nginx
+ \ No newline at end of file diff --git a/fhem/t/FHEM/98_HTTPMOD/12_Chains.cfg b/fhem/t/FHEM/98_HTTPMOD/12_Chains.cfg index f5aaa4e1d..75dfabe72 100644 --- a/fhem/t/FHEM/98_HTTPMOD/12_Chains.cfg +++ b/fhem/t/FHEM/98_HTTPMOD/12_Chains.cfg @@ -1,18 +1,18 @@ -define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/11_Cookies1.testdata 0 -attr H1 verbose 5 -attr H1 fileHeaderSplit --end-of-http-header-- -attr H1 queueDelay 0 -attr H1 minSendDelay 0 - -attr H1 get01Name O1 -attr H1 get01Regex
(.*)
-attr H1 get01FollowGet O2 - -attr H1 get02Name O2 -attr H1 get02Regex -attr H1 get02FollowGet O3 - -attr H1 get03Name O3 -attr H1 get03Regex - -attr H1 maxGetChain 5 +define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/11_Cookies1.testdata 0 +attr H1 verbose 5 +attr H1 fileHeaderSplit --end-of-http-header-- +attr H1 queueDelay 0 +attr H1 minSendDelay 0 + +attr H1 get01Name O1 +attr H1 get01Regex
(.*)
+attr H1 get01FollowGet O2 + +attr H1 get02Name O2 +attr H1 get02Regex +attr H1 get02FollowGet O3 + +attr H1 get03Name O3 +attr H1 get03Regex + +attr H1 maxGetChain 5 diff --git a/fhem/t/FHEM/98_HTTPMOD/20_extractAllJSON.cfg b/fhem/t/FHEM/98_HTTPMOD/20_extractAllJSON.cfg index 1a285a3c3..3936df234 100644 --- a/fhem/t/FHEM/98_HTTPMOD/20_extractAllJSON.cfg +++ b/fhem/t/FHEM/98_HTTPMOD/20_extractAllJSON.cfg @@ -1,3 +1,3 @@ -define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON.testdata 0 -attr H1 extractAllJSON 1 +define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON.testdata 0 +attr H1 extractAllJSON 1 attr H1 verbose 5 \ No newline at end of file diff --git a/fhem/t/FHEM/98_HTTPMOD/30_requestExpr.cfg b/fhem/t/FHEM/98_HTTPMOD/30_requestExpr.cfg index 768f07c78..e30068700 100644 --- a/fhem/t/FHEM/98_HTTPMOD/30_requestExpr.cfg +++ b/fhem/t/FHEM/98_HTTPMOD/30_requestExpr.cfg @@ -1,30 +1,30 @@ -define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON 0 -attr H1 verbose 3 -attr H1 get01Name TestGet -attr H1 get01Header1 Content-Type: application/json -attr H1 get01Data Post Data for Test -attr H1 get01URLExpr $old . '.testdata' -attr H1 get01HdrExpr $old . '345' -attr H1 get01DatExpr $old . '567' - -define H2 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON.testdata 0 -attr H2 requestHeader1 Content-Type: Test-Content -attr H2 requestHeader2 TestHeader: T1E2S3T -attr H2 verbose 5 -attr H2 minSendDelay 0 -attr H2 reading01Name TestReading -attr H2 reading01Regex "ip":\[192,(\d+),1,24\] -attr H2 reading01OExpr $val * 2 - -attr H2 reading02Name TestReading2 -attr H2 reading02Regex \"([^\"\]\[]+)\"\, -attr H2 reading02RegOpt g - -attr H2 reading03Name CombReading -attr H2 reading03Regex \"([^\"\]\[]+)\"\, -attr H2 reading03RegOpt g -attr H2 reading03RecombineExpr join ' ', @matchlist - -attr H2 set01Name TestSet1 -attr H2 set01Data TestSet1 PostData $val -attr H2 set01IExpr $val * 2 +define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON 0 +attr H1 verbose 3 +attr H1 get01Name TestGet +attr H1 get01Header1 Content-Type: application/json +attr H1 get01Data Post Data for Test +attr H1 get01URLExpr $old . '.testdata' +attr H1 get01HdrExpr $old . '345' +attr H1 get01DatExpr $old . '567' + +define H2 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON.testdata 0 +attr H2 requestHeader1 Content-Type: Test-Content +attr H2 requestHeader2 TestHeader: T1E2S3T +attr H2 verbose 5 +attr H2 minSendDelay 0 +attr H2 reading01Name TestReading +attr H2 reading01Regex "ip":\[192,(\d+),1,24\] +attr H2 reading01OExpr $val * 2 + +attr H2 reading02Name TestReading2 +attr H2 reading02Regex \"([^\"\]\[]+)\"\, +attr H2 reading02RegOpt g + +attr H2 reading03Name CombReading +attr H2 reading03Regex \"([^\"\]\[]+)\"\, +attr H2 reading03RegOpt g +attr H2 reading03RecombineExpr join ' ', @matchlist + +attr H2 set01Name TestSet1 +attr H2 set01Data TestSet1 PostData $val +attr H2 set01IExpr $val * 2 diff --git a/fhem/t/FHEM/98_HTTPMOD/31_Regexes.cfg b/fhem/t/FHEM/98_HTTPMOD/31_Regexes.cfg index a6d636da7..b2185dee0 100644 --- a/fhem/t/FHEM/98_HTTPMOD/31_Regexes.cfg +++ b/fhem/t/FHEM/98_HTTPMOD/31_Regexes.cfg @@ -1,67 +1,67 @@ -define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON.testdata 0 -attr H1 verbose 5 -attr H1 minSendDelay 0 - -attr H1 regexDecode none -attr H1 regexCompile 1 - -attr H1 reading01Name TestReading1 -attr H1 reading01Regex \"SimpleColor\",\"([^\"]+)\" - -attr H1 reading02Name TestReading2 -attr H1 reading02Regex \" SimpleColor \" ,\" ([^\"]+) \" -attr H1 reading02RegOpt xms - -attr H1 reading03Name TestReading3 -attr H1 reading03Regex \" SimpleColor \" ,\" ([^\"]+) \" - -attr H1 reading10Name TestReading4 -attr H1 reading10Regex code . \" : (\d+) -attr H1 reading10RegOpt gxms -attr H1 reading10RecombineExpr join ' ', @matchlist - - -define H2 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON.testdata 0 -attr H2 verbose 5 -attr H2 minSendDelay 0 - -attr H2 regexDecode none -attr H2 regexCompile 0 - -attr H2 reading01Name TestReading1 -attr H2 reading01Regex \"SimpleColor\",\"([^\"]+)\" - -attr H2 reading02Name TestReading2 -attr H2 reading02Regex \" SimpleColor \" ,\" ([^\"]+) \" -attr H2 reading02RegOpt xms - -attr H2 reading03Name TestReading3 -attr H2 reading03Regex \" SimpleColor \" ,\" ([^\"]+) \" - -attr H2 reading10Name TestReading4 -attr H2 reading10Regex code . \" : (\d+) -attr H2 reading10RegOpt gxms -attr H2 reading10RecombineExpr join ' ', @matchlist - - -define H3 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON.testdata 0 -attr H3 verbose 3 -attr H3 reading01Name TestReading -attr H3 reading01JSON MQTT_ip_1 -attr H3 preProcessRegex s/168/466/g - -define H4 HTTPMOD file://t/FHEM/98_HTTPMOD/Login.testdata 0 -attr H4 verbose 3 -attr H4 minSendDelay 0 -attr H4 queueDelay 0 -attr H4 showMatched 1 -attr H4 authRetries 1 - -attr H4 reAuthRegex Login required -attr H4 sid01URL file://t/FHEM/98_HTTPMOD/JSON.testdata -attr H4 sid02URL file://t/FHEM/98_HTTPMOD/JSON3.testdata -attr H4 idRegex session ([\d]+) -#attr H4 dontRequeueAfterAuth 1 - -attr H4 reading01Name TestReading -attr H4 reading01JSON MQTT_ip_1 +define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON.testdata 0 +attr H1 verbose 5 +attr H1 minSendDelay 0 + +attr H1 regexDecode none +attr H1 regexCompile 1 + +attr H1 reading01Name TestReading1 +attr H1 reading01Regex \"SimpleColor\",\"([^\"]+)\" + +attr H1 reading02Name TestReading2 +attr H1 reading02Regex \" SimpleColor \" ,\" ([^\"]+) \" +attr H1 reading02RegOpt xms + +attr H1 reading03Name TestReading3 +attr H1 reading03Regex \" SimpleColor \" ,\" ([^\"]+) \" + +attr H1 reading10Name TestReading4 +attr H1 reading10Regex code . \" : (\d+) +attr H1 reading10RegOpt gxms +attr H1 reading10RecombineExpr join ' ', @matchlist + + +define H2 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON.testdata 0 +attr H2 verbose 5 +attr H2 minSendDelay 0 + +attr H2 regexDecode none +attr H2 regexCompile 0 + +attr H2 reading01Name TestReading1 +attr H2 reading01Regex \"SimpleColor\",\"([^\"]+)\" + +attr H2 reading02Name TestReading2 +attr H2 reading02Regex \" SimpleColor \" ,\" ([^\"]+) \" +attr H2 reading02RegOpt xms + +attr H2 reading03Name TestReading3 +attr H2 reading03Regex \" SimpleColor \" ,\" ([^\"]+) \" + +attr H2 reading10Name TestReading4 +attr H2 reading10Regex code . \" : (\d+) +attr H2 reading10RegOpt gxms +attr H2 reading10RecombineExpr join ' ', @matchlist + + +define H3 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON.testdata 0 +attr H3 verbose 3 +attr H3 reading01Name TestReading +attr H3 reading01JSON MQTT_ip_1 +attr H3 preProcessRegex s/168/466/g + +define H4 HTTPMOD file://t/FHEM/98_HTTPMOD/Login.testdata 0 +attr H4 verbose 3 +attr H4 minSendDelay 0 +attr H4 queueDelay 0 +attr H4 showMatched 1 +attr H4 authRetries 1 + +attr H4 reAuthRegex Login required +attr H4 sid01URL file://t/FHEM/98_HTTPMOD/JSON.testdata +attr H4 sid02URL file://t/FHEM/98_HTTPMOD/JSON3.testdata +attr H4 idRegex session ([\d]+) +#attr H4 dontRequeueAfterAuth 1 + +attr H4 reading01Name TestReading +attr H4 reading01JSON MQTT_ip_1 diff --git a/fhem/t/FHEM/98_HTTPMOD/32_SetExpr.cfg b/fhem/t/FHEM/98_HTTPMOD/32_SetExpr.cfg new file mode 100644 index 000000000..dff30e5f9 --- /dev/null +++ b/fhem/t/FHEM/98_HTTPMOD/32_SetExpr.cfg @@ -0,0 +1,9 @@ +define H1 HTTPMOD none 0 + +attr H1 set01Name Msg +attr H1 set01TextArg 1 +attr H1 set01URL https://api.testurl.local/send?text=$val +attr H1 verbose 5 +attr H1 timeout 0.1 +attr H1 queueDelay 0 +attr H1 minSendDelay 0 \ No newline at end of file diff --git a/fhem/t/FHEM/98_HTTPMOD/32_SetExpr.t b/fhem/t/FHEM/98_HTTPMOD/32_SetExpr.t new file mode 100644 index 000000000..674e467fc --- /dev/null +++ b/fhem/t/FHEM/98_HTTPMOD/32_SetExpr.t @@ -0,0 +1,33 @@ +############################################## +# test set expressions +############################################## +use strict; +use warnings; +use Test::More; +#use Data::Dumper; + +my $hash = $defs{'H1'}; +my $modVersion = $hash->{ModuleVersion}; +$modVersion =~ /^([0-9]+)\./; +my $major = $1; + +if ($major && $major >= 4) { + plan tests => 2; +} else { + plan skip_all => "This test only works for HTTPMOD version 4 or later, installed is $modVersion"; +} + +fhem 'set H1 Msg Hallo Du da'; +is(FhemTestUtils_gotLog("HandleSendQueue sends set01 with timeout.*text=Hallo Du da"), 1, "send normal request"); +FhemTestUtils_resetLogs(); + +fhem 'attr H1 set01IExpr $val =~ s/\s/%20/g;; $val;'; +fhem 'set H1 Msg Hallo Du da'; +is(FhemTestUtils_gotLog("HandleSendQueue sends set01 with timeout.*text=Hallo%20Du%20da"), 1, "send normal request"); +FhemTestUtils_resetLogs(); + + +done_testing; +exit(0); + +1; diff --git a/fhem/t/FHEM/98_HTTPMOD/33_SetExtensions.cfg b/fhem/t/FHEM/98_HTTPMOD/33_SetExtensions.cfg new file mode 100644 index 000000000..4fd201b86 --- /dev/null +++ b/fhem/t/FHEM/98_HTTPMOD/33_SetExtensions.cfg @@ -0,0 +1,18 @@ +define H1 HTTPMOD none 0 + +attr global mseclog 1 +attr H1 useSetExtensions 1 +attr H1 verbose 5 +attr H1 timeout 0.1 +attr H1 queueDelay 0 +attr H1 minSendDelay 0 + +attr H1 set01Name on +attr H1 set01NoArg 1 +attr H1 set01URL https://api.testurl.local/send?state=on + +attr H1 set02Name off +attr H1 set02NoArg 1 +attr H1 set02URL https://api.testurl.local/send?state=off + + diff --git a/fhem/t/FHEM/98_HTTPMOD/33_SetExtensions.t b/fhem/t/FHEM/98_HTTPMOD/33_SetExtensions.t new file mode 100644 index 000000000..6a83b13ca --- /dev/null +++ b/fhem/t/FHEM/98_HTTPMOD/33_SetExtensions.t @@ -0,0 +1,58 @@ +############################################## +# test set extensions +############################################## +use strict; +use warnings; +use Test::More; +use FHEM::Modbus::TestUtils qw(:all); + +#use Data::Dumper; + +my $hash = $defs{'H1'}; +my $modVersion = $hash->{ModuleVersion}; +$modVersion =~ /^([0-9]+)\./; +my $major = $1; + +if ($major && $major >= 4) { + plan tests => 7; +} else { + plan skip_all => "This test only works for HTTPMOD version 4 or later, installed is $modVersion"; +} + +NextStep(); + + +sub testStep10 { + fhem 'set H1 toggle'; + return 0.1; +} + +sub testStep11 { # check result + #is(FhemTestUtils_gotEvent(qr/Master:Test1: 6/), 1, "Combined retrieve integer value with expressions on both sides from local slave"); + is(FhemTestUtils_gotLog('HandleSendQueue sends set01.*state=on'), 1,'saw set on in log'); + CheckAndReset(); + return 0.1; +} + + +sub testStep20 { + fhem 'set H1 off-for-timer 0.5'; + return 0.6; +} + +sub testStep21 { + #is(FhemTestUtils_gotEvent(qr/Master:Test1: 6/), 1, "Combined retrieve integer value with expressions on both sides from local slave"); + is(FhemTestUtils_gotLog('HandleSendQueue sends set02.*state=off'), 1,'saw set off in log'); + is(FhemTestUtils_gotLog('HandleSendQueue sends set01.*state=on'), 1,'saw set on in log'); + + my $t1 = FhemTestUtils_getLogTime('HandleSendQueue sends set02.*state=off'); + my $t2 = FhemTestUtils_getLogTime('HandleSendQueue sends set01.*state=on'); + my $d = $t2 - $t1; + + ok($d >= 0.4, 'time big enough'); + ok($d < 0.6, 'time not too big'); + CheckAndReset(); + return; +} + +1; diff --git a/fhem/t/FHEM/98_HTTPMOD/36_JSONExpr.cfg b/fhem/t/FHEM/98_HTTPMOD/36_JSONExpr.cfg index 3a03a1658..d934d0cba 100644 --- a/fhem/t/FHEM/98_HTTPMOD/36_JSONExpr.cfg +++ b/fhem/t/FHEM/98_HTTPMOD/36_JSONExpr.cfg @@ -1,28 +1,28 @@ -define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON 0 -attr H1 verbose 3 -attr H1 get01Name TestGet -attr H1 get01Data Post Data for Test -attr H1 get01Header1 Content-Type: application/json -attr H1 get01URLExpr $old . '.testdata' -attr H1 get01HdrExpr $old . '345' -attr H1 get01DatExpr $old . '567' - -define H2 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON.testdata 0 -attr H2 requestHeader1 Content-Type: Test-Content -attr H2 requestHeader2 TestHeader: T1E2S3T -attr H2 verbose 5 -attr H2 minSendDelay 0 -attr H2 reading01Name TestReading -attr H2 reading01JSON MQTT_ip_1 -attr H2 reading01OExpr $val * 2 - -attr H2 reading02Name TestReading2 -attr H2 reading02JSON modes - -attr H2 reading03Name CombReading -attr H2 reading03JSON modes -attr H2 reading03RecombineExpr join ' ', @matchlist - -attr H2 set01Name TestSet1 -attr H2 set01Data TestSet1 PostData $val -attr H2 set01IExpr $val * 2 +define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON 0 +attr H1 verbose 3 +attr H1 get01Name TestGet +attr H1 get01Data Post Data for Test +attr H1 get01Header1 Content-Type: application/json +attr H1 get01URLExpr $old . '.testdata' +attr H1 get01HdrExpr $old . '345' +attr H1 get01DatExpr $old . '567' + +define H2 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON.testdata 0 +attr H2 requestHeader1 Content-Type: Test-Content +attr H2 requestHeader2 TestHeader: T1E2S3T +attr H2 verbose 5 +attr H2 minSendDelay 0 +attr H2 reading01Name TestReading +attr H2 reading01JSON MQTT_ip_1 +attr H2 reading01OExpr $val * 2 + +attr H2 reading02Name TestReading2 +attr H2 reading02JSON modes + +attr H2 reading03Name CombReading +attr H2 reading03JSON modes +attr H2 reading03RecombineExpr join ' ', @matchlist + +attr H2 set01Name TestSet1 +attr H2 set01Data TestSet1 PostData $val +attr H2 set01IExpr $val * 2 diff --git a/fhem/t/FHEM/98_HTTPMOD/39_Map.cfg b/fhem/t/FHEM/98_HTTPMOD/39_Map.cfg new file mode 100644 index 000000000..1a7b2d0c8 --- /dev/null +++ b/fhem/t/FHEM/98_HTTPMOD/39_Map.cfg @@ -0,0 +1,15 @@ +define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON.testdata 0 +attr H1 verbose 5 +attr H1 minSendDelay 0 + +attr H1 regexDecode none +attr H1 regexCompile 1 + +attr H1 reading01Name TestReading1 +attr H1 reading01Regex \"code1\":(\d+) +attr H1 reading01Map 1:very low, 2:low, 3:medium, 4:high, 5:very high + +attr H1 reading02Name TestReading2 +attr H1 reading02Regex \"code2\":(\d+) +attr H1 reading02Map 1:very low, 2:low, 3:medium + diff --git a/fhem/t/FHEM/98_HTTPMOD/39_Map.t b/fhem/t/FHEM/98_HTTPMOD/39_Map.t new file mode 100644 index 000000000..0c09d83f1 --- /dev/null +++ b/fhem/t/FHEM/98_HTTPMOD/39_Map.t @@ -0,0 +1,24 @@ +############################################## +# test map +# +############################################## +use strict; +use warnings; +use Test::More; +use FHEM::Modbus::TestUtils qw(:all); + +NextStep(); + +sub testStep1 { + LogStep "Read and process data"; + fhem('set H1 reread'); +} + +sub testStep2 { + LogStep "check results"; + is(FhemTestUtils_gotEvent(qr/H1:TestReading1:\smedium/xms), 1, "match simple regex match with map"); + is(FhemTestUtils_gotEvent(qr/H1:TestReading2:\s4/xms), 1, "match simple regex match with map and no match - keep input value"); + CheckAndReset(); +} + +1; diff --git a/fhem/t/FHEM/98_HTTPMOD/40_maxAge.cfg b/fhem/t/FHEM/98_HTTPMOD/40_maxAge.cfg index 5d80666d8..f0bf9bfad 100644 --- a/fhem/t/FHEM/98_HTTPMOD/40_maxAge.cfg +++ b/fhem/t/FHEM/98_HTTPMOD/40_maxAge.cfg @@ -1,33 +1,33 @@ -define H1 HTTPMOD none 0 -attr H1 verbose 5 -attr H1 minSendDelay 0 - -attr H1 reading01Name TestReading1 -attr H1 reading01Regex "ip":\[192,(\d+),1,24\] - -attr H1 reading02Name TestReading2 -attr H1 reading02Regex \"([^\"\]\[]+)\"\, -attr H1 reading02RegOpt g -attr H1 readingMaxAge 0.1 - -attr H1 readingMaxAgeReplacement outdated -attr H1 readingMaxAgeReplacementMode text - -attr H1 reading02MaxAgeReplacement "old - was $val" -attr H1 reading02MaxAgeReplacementMode expression - -attr H1 reading02-2MaxAgeReplacement tr -attr H1 reading02-2MaxAgeReplacementMode reading - -attr H1 reading02-3MaxAgeReplacement NAME -attr H1 reading02-3MaxAgeReplacementMode internal - -attr H1 reading02-4MaxAgeReplacement 0 -attr H1 reading02-4MaxAgeReplacementMode delete - -attr H1 get01URL file://t/FHEM/98_HTTPMOD/JSON.testdata -attr H1 get01Name G1 - -attr H1 get02URL file://t/FHEM/98_HTTPMOD/empty.testdata -attr H1 get02Name G2 - +define H1 HTTPMOD none 0 +attr H1 verbose 5 +attr H1 minSendDelay 0 + +attr H1 reading01Name TestReading1 +attr H1 reading01Regex "ip":\[192,(\d+),1,24\] + +attr H1 reading02Name TestReading2 +attr H1 reading02Regex \"([^\"\]\[]+)\"\, +attr H1 reading02RegOpt g +attr H1 readingMaxAge 0.1 + +attr H1 readingMaxAgeReplacement outdated +attr H1 readingMaxAgeReplacementMode text + +attr H1 reading02MaxAgeReplacement "old - was $val" +attr H1 reading02MaxAgeReplacementMode expression + +attr H1 reading02-2MaxAgeReplacement tr +attr H1 reading02-2MaxAgeReplacementMode reading + +attr H1 reading02-3MaxAgeReplacement NAME +attr H1 reading02-3MaxAgeReplacementMode internal + +attr H1 reading02-4MaxAgeReplacement 0 +attr H1 reading02-4MaxAgeReplacementMode delete + +attr H1 get01URL file://t/FHEM/98_HTTPMOD/JSON.testdata +attr H1 get01Name G1 + +attr H1 get02URL file://t/FHEM/98_HTTPMOD/empty.testdata +attr H1 get02Name G2 + diff --git a/fhem/t/FHEM/98_HTTPMOD/40_maxAge.t b/fhem/t/FHEM/98_HTTPMOD/40_maxAge.t index e9e9a4e3f..f1216ece9 100644 --- a/fhem/t/FHEM/98_HTTPMOD/40_maxAge.t +++ b/fhem/t/FHEM/98_HTTPMOD/40_maxAge.t @@ -1,26 +1,49 @@ ############################################## # test MaxAge ############################################## + +package main; use strict; use warnings; use Test::More; +use Time::HiRes qw( gettimeofday tv_interval); # return time as float, not just full seconds +use FHEM::HTTPMOD::Utils qw(:all); +use FHEM::Modbus::TestUtils qw(:all); -fhem('get H1 G1'); -is(FhemTestUtils_gotEvent("H1:TestReading1: 168"), 1, "Normal Reading 1"); -is(FhemTestUtils_gotEvent("H1:TestReading2-1: tvlights"), 1, "Normal Reading 2"); +fhem 'attr global mseclog 1'; +NextStep(); -sleep 0.15; -fhem('setreading H1 tr 789'); -fhem('get H1 G2'); +sub testStep1 { + LogStep "TestStep1: get H1 G1"; + fhem('get H1 G1'); + return 1; +} -is(FhemTestUtils_gotEvent("H1:TestReading1: outdated"), 1, "Outdated Reading 1 with mode text"); -is(FhemTestUtils_gotEvent("H1:TestReading2-1: old - was tvlights"), 1, "Outdated Reading 2 with mode expression"); -is(FhemTestUtils_gotEvent("H1:TestReading2-2: 789"), 1, "Outdated Reading 3 with mode reading"); -is(FhemTestUtils_gotEvent("H1:TestReading2-3: H1"), 1, "Outdated Reading 4 with mode internal"); -is(FhemTestUtils_gotEvent("H1:TestReading2-4:"), 1, "Outdated Reading 5 with mode delete"); +sub testStep2 { + LogStep "check normal readings"; + is(FhemTestUtils_gotEvent("H1:TestReading1: 168"), 1, "Normal Reading 1"); + is(FhemTestUtils_gotEvent("H1:TestReading2-1: tvlights"), 1, "Normal Reading 2"); + CheckAndReset(); + return 1; +} -done_testing; -exit(0); +sub testStep10 { + LogStep "get H1 G2"; + fhem('setreading H1 tr 789'); + fhem('get H1 G2'); + return 1; +} + +sub testStep11 { + LogStep "check outdated readings"; + is(FhemTestUtils_gotEvent("H1:TestReading1: outdated"), 1, "Outdated Reading 1 with mode text"); + is(FhemTestUtils_gotEvent("H1:TestReading2-1: old - was tvlights"), 1, "Outdated Reading 2 with mode expression"); + is(FhemTestUtils_gotEvent("H1:TestReading2-2: 789"), 1, "Outdated Reading 3 with mode reading"); + is(FhemTestUtils_gotEvent("H1:TestReading2-3: H1"), 1, "Outdated Reading 4 with mode internal"); + is(FhemTestUtils_gotEvent("H1:TestReading2-4:"), 0, "Outdated Reading 5 with mode delete"); + CheckAndReset(); + return 1; +} 1; diff --git a/fhem/t/FHEM/98_HTTPMOD/50_Replacements.cfg b/fhem/t/FHEM/98_HTTPMOD/50_Replacements.cfg index efc3b7969..bbeedd23a 100644 --- a/fhem/t/FHEM/98_HTTPMOD/50_Replacements.cfg +++ b/fhem/t/FHEM/98_HTTPMOD/50_Replacements.cfg @@ -1,18 +1,18 @@ -define GeoTest HTTPMOD none 0 -attr GeoTest minSendDelay 0 -attr GeoTest verbose 5 -attr GeoTest enableControlSet 1 - -attr GeoTest replacement01Mode expression -attr GeoTest replacement01Regex %%date%% - -attr GeoTest get01Name Tag01 -attr GeoTest get01Poll 1 -attr GeoTest get01Regex (?s)Zeit auswählen
(?[A-Za-z]+).-.(?[0-9\.]{10}).*?09:15<\/td>(?.*?)<\/td>.*?12:15<\/td>(?.*?)<\/td> -attr GeoTest getURL file://geocache-planer.de/CAL/anmeldung.php?date=%%date%%&CALID=XYZ -attr GeoTest get01Replacement01Value {strftime("%d.%m.%Y", localtime( time))} - -attr GeoTest get02Name Test2 -#attr GeoTest get02Replacement01Value {my $NAME = "GeoTest" ;;fhem("deletereading ".$NAME." message");;fhem("deletereading ".$NAME." auth.*");;my @chars=('a'..'z','A'..'Z','0'..'9'); my $r; foreach(1..16) {$r.=$chars[rand @chars];};; fhem("setreading ".$NAME." auth_randomString64 ".$r);; $r;;} -attr GeoTest get02Replacement01Value {my $NAME = "GeoTest" ;;fhem("deletereading ".$NAME." message");;fhem("deletereading ".$NAME." auth.*");;my @chars=('a'..'z','A'..'Z','0'..'9');; my $r;; foreach(1..16) {$r.=$chars[rand @chars];;};; fhem("setreading ".$NAME." auth_randomString64 ".$r);; $r;;} -attr GeoTest get02Poll 1 +define GeoTest HTTPMOD none 0 +attr GeoTest minSendDelay 0 +attr GeoTest verbose 5 +attr GeoTest enableControlSet 1 + +attr GeoTest replacement01Mode expression +attr GeoTest replacement01Regex %%date%% + +attr GeoTest get01Name Tag01 +attr GeoTest get01Poll 1 +attr GeoTest get01Regex (?s)Zeit auswählen
(?[A-Za-z]+).-.(?[0-9\.]{10}).*?09:15<\/td>(?.*?)<\/td>.*?12:15<\/td>(?.*?)<\/td> +attr GeoTest getURL file://geocache-planer.de/CAL/anmeldung.php?date=%%date%%&CALID=XYZ +attr GeoTest get01Replacement01Value {strftime("%d.%m.%Y", localtime( time))} + +attr GeoTest get02Name Test2 +#attr GeoTest get02Replacement01Value {my $NAME = "GeoTest" ;;fhem("deletereading ".$NAME." message");;fhem("deletereading ".$NAME." auth.*");;my @chars=('a'..'z','A'..'Z','0'..'9'); my $r; foreach(1..16) {$r.=$chars[rand @chars];};; fhem("setreading ".$NAME." auth_randomString64 ".$r);; $r;;} +attr GeoTest get02Replacement01Value {my $NAME = "GeoTest" ;;fhem("deletereading ".$NAME." message");;fhem("deletereading ".$NAME." auth.*");;my @chars=('a'..'z','A'..'Z','0'..'9');; my $r;; foreach(1..16) {$r.=$chars[rand @chars];;};; fhem("setreading ".$NAME." auth_randomString64 ".$r);; $r;;} +attr GeoTest get02Poll 1 diff --git a/fhem/t/FHEM/98_HTTPMOD/90_SmallFeatures.cfg b/fhem/t/FHEM/98_HTTPMOD/90_SmallFeatures.cfg index 8e9562acf..58ac7351f 100644 --- a/fhem/t/FHEM/98_HTTPMOD/90_SmallFeatures.cfg +++ b/fhem/t/FHEM/98_HTTPMOD/90_SmallFeatures.cfg @@ -1,17 +1,17 @@ -define H2 HTTPMOD file://t/FHEM/98_HTTPMOD/Charset.testdata 0 -attr H2 verbose 5 -attr H2 fileHeaderSplit --end-of-http-header-- -attr H2 memReading 1 -attr H2 minSendDelay 0 - -attr H2 reading01Name TestReading1 -attr H2 reading01Regex erraschung mit (.*) - -define H3 HTTPMOD file://t/FHEM/98_HTTPMOD/Charset.testdata2 0 -attr H3 verbose 5 -attr H3 fileHeaderSplit --end-of-http-header-- -attr H3 minSendDelay 0 -attr H3 bodyDecode auto -attr H3 reading01Name Test -attr H3 reading01Regex >([^ ]+) auf neue +define H2 HTTPMOD file://t/FHEM/98_HTTPMOD/Charset.testdata 0 +attr H2 verbose 5 +attr H2 fileHeaderSplit --end-of-http-header-- +attr H2 memReading 1 +attr H2 minSendDelay 0 + +attr H2 reading01Name TestReading1 +attr H2 reading01Regex erraschung mit (.*) + +define H3 HTTPMOD file://t/FHEM/98_HTTPMOD/Charset.testdata2 0 +attr H3 verbose 5 +attr H3 fileHeaderSplit --end-of-http-header-- +attr H3 minSendDelay 0 +attr H3 bodyDecode auto +attr H3 reading01Name Test +attr H3 reading01Regex >([^ ]+) auf neue attr H3 reading01Encode none \ No newline at end of file diff --git a/fhem/t/FHEM/98_HTTPMOD/90_SmallFeatures.t b/fhem/t/FHEM/98_HTTPMOD/90_SmallFeatures.t index 70f7ee7af..0eb34d581 100644 --- a/fhem/t/FHEM/98_HTTPMOD/90_SmallFeatures.t +++ b/fhem/t/FHEM/98_HTTPMOD/90_SmallFeatures.t @@ -12,7 +12,7 @@ $modVersion =~ /^([0-9]+)\./; my $major = $1; if ($major && $major >= 4) { - plan tests => 9; + plan tests => 11; } else { plan skip_all => "This test only works for HTTPMOD version 4 or later, installed is $modVersion"; } @@ -34,12 +34,19 @@ fhem('attr H2 readingEncode utf8'); fhem('set H2 reread'); is(FhemTestUtils_gotEvent("H2:TestReading1: \xc3\x84\x6e"), 1, "TestReading with body decode"); + +CheckAndReset(); +fhem('attr H2 bodyDecode UTF8'); +fhem('attr H2 readingEncode utf8'); +fhem('set H2 reread'); +is(FhemTestUtils_gotEvent("H2:TestReading1: \xef\xbf\xbd"), 1, "TestReading with body decode UTF8"); + CheckAndReset(); fhem('attr H2 dumpBuffers .'); fhem('attr H2 verbose 5'); fhem('set H2 reread'); - # todo: check +# problem: where can we write buffers (with permission) during testing? CheckAndReset(); fhem 'set H3 reread'; diff --git a/fhem/t/FHEM/98_HTTPMOD/99_evalExpr.cfg b/fhem/t/FHEM/98_HTTPMOD/99_evalExpr.cfg index 25ceb57f9..e56de3588 100644 --- a/fhem/t/FHEM/98_HTTPMOD/99_evalExpr.cfg +++ b/fhem/t/FHEM/98_HTTPMOD/99_evalExpr.cfg @@ -1,4 +1,4 @@ -define H2 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON 0 -attr H2 verbose 5 -attr H2 get01Name TestGet -attr H2 get01Data Post Data for Test +define H2 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON 0 +attr H2 verbose 5 +attr H2 get01Name TestGet +attr H2 get01Data Post Data for Test diff --git a/fhem/t/FHEM/98_HTTPMOD/Charset.testdata b/fhem/t/FHEM/98_HTTPMOD/Charset.testdata index ffb292692..0f430d3e1 100644 --- a/fhem/t/FHEM/98_HTTPMOD/Charset.testdata +++ b/fhem/t/FHEM/98_HTTPMOD/Charset.testdata @@ -1,13 +1,13 @@ -HTTP/1.1 200 OK -Content-Type: text/html; charset=cp437 ---end-of-http-header-- - -Test - -

Test Data

-
for HTTPMOD Test
- -šberraschung mit Žnderungen ‚Š - - - +HTTP/1.1 200 OK +Content-Type: text/html; charset=cp437 +--end-of-http-header-- + +Test + +

Test Data

+
for HTTPMOD Test
+ +šberraschung mit Žnderungen ‚Š + + + diff --git a/fhem/t/FHEM/98_HTTPMOD/Charset.testdata-utf8 b/fhem/t/FHEM/98_HTTPMOD/Charset.testdata-utf8 index 6d6fdaa93..dad77c265 100644 --- a/fhem/t/FHEM/98_HTTPMOD/Charset.testdata-utf8 +++ b/fhem/t/FHEM/98_HTTPMOD/Charset.testdata-utf8 @@ -1,14 +1,14 @@ -HTTP/1.1 200 OK -Content-Type: text/html; charset=cp437 ---end-of-http-header-- - -Test - -

Test Data

-
for HTTPMOD Test
- -Überraschung mit Änderungen éè -kleine Umlaute: äöü - - - +HTTP/1.1 200 OK +Content-Type: text/html; charset=cp437 +--end-of-http-header-- + +Test + +

Test Data

+
for HTTPMOD Test
+ +Überraschung mit Änderungen éè +kleine Umlaute: äöü + + + diff --git a/fhem/t/FHEM/98_HTTPMOD/Charset.testdata2 b/fhem/t/FHEM/98_HTTPMOD/Charset.testdata2 index 928691a62..784dff12d 100644 --- a/fhem/t/FHEM/98_HTTPMOD/Charset.testdata2 +++ b/fhem/t/FHEM/98_HTTPMOD/Charset.testdata2 @@ -1,48 +1,48 @@ -HTTP/1.1 200 OK -Content-Type: text/html; charset=utf-8 -Cache-Control: no-cache, no-store, must-revalidate -Pragma: no-cache -Expires: 0 -Length: unspecified ---end-of-http-header-- - - - -BSB-LAN - - - - -

BSB-LAN

- - - - -
- HeizungsfunktionenSensoren - Zeichne LogdateiPrüfe auf neue Parameter
- Einstellungen - URL-BefehleHandbuchFAQ

-
-
712 Heizkreis 1 - Reduziertsollwert: 21.0 °C -
- +HTTP/1.1 200 OK +Content-Type: text/html; charset=utf-8 +Cache-Control: no-cache, no-store, must-revalidate +Pragma: no-cache +Expires: 0 +Length: unspecified +--end-of-http-header-- + + + +BSB-LAN + + + + +

BSB-LAN

+ + + + +
+ HeizungsfunktionenSensoren + Zeichne LogdateiPrüfe auf neue Parameter
+ Einstellungen + URL-BefehleHandbuchFAQ

+
+
712 Heizkreis 1 - Reduziertsollwert: 21.0 °C +
+ \ No newline at end of file