2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 12:49:34 +00:00

98_HTTPMOD: updated tests

git-svn-id: https://svn.fhem.de/fhem/trunk@26103 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
StefanStrobel 2022-05-31 18:21:04 +00:00
parent fcef8a3e56
commit d48931a37b
25 changed files with 546 additions and 359 deletions

View File

@ -1,6 +1,6 @@
define H2 HTTPMOD file://t/FHEM/98_HTTPMOD/10_Redirects.testdata 0 define H2 HTTPMOD file://t/FHEM/98_HTTPMOD/10_Redirects.testdata 0
attr H2 verbose 5 attr H2 verbose 5
attr H2 fileHeaderSplit --end-of-http-header-- attr H2 fileHeaderSplit --end-of-http-header--
attr H2 queueDelay 2 attr H2 queueDelay 2
attr H2 minSendDelay 2 attr H2 minSendDelay 2

View File

@ -1,13 +1,13 @@
HTTP/1.1 301 Moved Permanently HTTP/1.1 301 Moved Permanently
Content-Type: text/html Content-Type: text/html
Content-Length: 162 Content-Length: 162
Connection: close Connection: close
Location: http://test.url/ Location: http://test.url/
--end-of-http-header-- --end-of-http-header--
<html> <html>
<head><title>301 Moved Permanently</title></head> <head><title>301 Moved Permanently</title></head>
<body> <body>
<center><h1>301 Moved Permanently</h1></center> <center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center> <hr><center>nginx</center>
</body> </body>
</html> </html>

View File

@ -1,5 +1,5 @@
define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/11_Cookies1.testdata 0 define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/11_Cookies1.testdata 0
attr H1 verbose 4 attr H1 verbose 4
attr H1 fileHeaderSplit --end-of-http-header-- attr H1 fileHeaderSplit --end-of-http-header--
attr H1 queueDelay 0 attr H1 queueDelay 0
attr H1 minSendDelay 0 attr H1 minSendDelay 0

View File

@ -1,17 +1,17 @@
HTTP/1.1 200 OK HTTP/1.1 200 OK
Content-Type: text/html Content-Type: text/html
Content-Length: 162 Content-Length: 162
Connection: close Connection: close
Location: http://test.url/ Location: http://test.url/
Set-Cookie: dp1=bbl/DE630e14e5^; Domain=.test.url; Path=/; Expires=Tue, 30 Aug 2022 13:47:17 GMT 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: 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: s=CgAD4ACBfTP9kM2Y5ZjQ1YmUxNzQwYTRjYzM0OTY5YzQzZmZmZmY2ZmRcvqYq; Domain=.test.url; Path=/; HttpOnly
Set-Cookie: ebay=%5Esbf%3D%23000000%5E; Domain=.test.url; Path=/ Set-Cookie: ebay=%5Esbf%3D%23000000%5E; Domain=.test.url; Path=/
--end-of-http-header-- --end-of-http-header--
<html> <html>
<head><title>Test</title></head> <head><title>Test</title></head>
<body> <body>
<center><h1>Test</h1></center> <center><h1>Test</h1></center>
<hr><center>nginx</center> <hr><center>nginx</center>
</body> </body>
</html> </html>

View File

@ -1,16 +1,16 @@
HTTP/1.1 200 OK HTTP/1.1 200 OK
Content-Type: text/html Content-Type: text/html
Content-Length: 162 Content-Length: 162
Connection: close Connection: close
Location: http://test.url/ Location: http://test.url/
Set-Cookie: dp1=bbl/DE630e14e5^; Domain=.test.url; Path=/; Expires=Tue, 30 Aug 2022 13:47:17 GMT 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: s=CgAD4ACBfTP9kM2Y5ZjQ1YmUxNzQwYTRjYzM0OTY5YzQzZmZmZmY2ZmRcvqYq; Domain=.test.url; Path=/; HttpOnly
Set-Cookie: ebay=%5Esbf%3D%23000000%5E; Domain=.test.url; Path=/ Set-Cookie: ebay=%5Esbf%3D%23000000%5E; Domain=.test.url; Path=/
--end-of-http-header-- --end-of-http-header--
<html> <html>
<head><title>Test</title></head> <head><title>Test</title></head>
<body> <body>
<center><h1>Test</h1></center> <center><h1>Test</h1></center>
<hr><center>nginx</center> <hr><center>nginx</center>
</body> </body>
</html> </html>

View File

@ -1,18 +1,18 @@
define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/11_Cookies1.testdata 0 define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/11_Cookies1.testdata 0
attr H1 verbose 5 attr H1 verbose 5
attr H1 fileHeaderSplit --end-of-http-header-- attr H1 fileHeaderSplit --end-of-http-header--
attr H1 queueDelay 0 attr H1 queueDelay 0
attr H1 minSendDelay 0 attr H1 minSendDelay 0
attr H1 get01Name O1 attr H1 get01Name O1
attr H1 get01Regex <center>(.*)</center> attr H1 get01Regex <center>(.*)</center>
attr H1 get01FollowGet O2 attr H1 get01FollowGet O2
attr H1 get02Name O2 attr H1 get02Name O2
attr H1 get02Regex <cen(.*)<h1> attr H1 get02Regex <cen(.*)<h1>
attr H1 get02FollowGet O3 attr H1 get02FollowGet O3
attr H1 get03Name O3 attr H1 get03Name O3
attr H1 get03Regex <c(.*)<h1> attr H1 get03Regex <c(.*)<h1>
attr H1 maxGetChain 5 attr H1 maxGetChain 5

View File

@ -1,3 +1,3 @@
define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON.testdata 0 define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON.testdata 0
attr H1 extractAllJSON 1 attr H1 extractAllJSON 1
attr H1 verbose 5 attr H1 verbose 5

View File

@ -1,30 +1,30 @@
define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON 0 define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON 0
attr H1 verbose 3 attr H1 verbose 3
attr H1 get01Name TestGet attr H1 get01Name TestGet
attr H1 get01Header1 Content-Type: application/json attr H1 get01Header1 Content-Type: application/json
attr H1 get01Data Post Data for Test attr H1 get01Data Post Data for Test
attr H1 get01URLExpr $old . '.testdata' attr H1 get01URLExpr $old . '.testdata'
attr H1 get01HdrExpr $old . '345' attr H1 get01HdrExpr $old . '345'
attr H1 get01DatExpr $old . '567' attr H1 get01DatExpr $old . '567'
define H2 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON.testdata 0 define H2 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON.testdata 0
attr H2 requestHeader1 Content-Type: Test-Content attr H2 requestHeader1 Content-Type: Test-Content
attr H2 requestHeader2 TestHeader: T1E2S3T attr H2 requestHeader2 TestHeader: T1E2S3T
attr H2 verbose 5 attr H2 verbose 5
attr H2 minSendDelay 0 attr H2 minSendDelay 0
attr H2 reading01Name TestReading attr H2 reading01Name TestReading
attr H2 reading01Regex "ip":\[192,(\d+),1,24\] attr H2 reading01Regex "ip":\[192,(\d+),1,24\]
attr H2 reading01OExpr $val * 2 attr H2 reading01OExpr $val * 2
attr H2 reading02Name TestReading2 attr H2 reading02Name TestReading2
attr H2 reading02Regex \"([^\"\]\[]+)\"\, attr H2 reading02Regex \"([^\"\]\[]+)\"\,
attr H2 reading02RegOpt g attr H2 reading02RegOpt g
attr H2 reading03Name CombReading attr H2 reading03Name CombReading
attr H2 reading03Regex \"([^\"\]\[]+)\"\, attr H2 reading03Regex \"([^\"\]\[]+)\"\,
attr H2 reading03RegOpt g attr H2 reading03RegOpt g
attr H2 reading03RecombineExpr join ' ', @matchlist attr H2 reading03RecombineExpr join ' ', @matchlist
attr H2 set01Name TestSet1 attr H2 set01Name TestSet1
attr H2 set01Data TestSet1 PostData $val attr H2 set01Data TestSet1 PostData $val
attr H2 set01IExpr $val * 2 attr H2 set01IExpr $val * 2

View File

@ -1,67 +1,67 @@
define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON.testdata 0 define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON.testdata 0
attr H1 verbose 5 attr H1 verbose 5
attr H1 minSendDelay 0 attr H1 minSendDelay 0
attr H1 regexDecode none attr H1 regexDecode none
attr H1 regexCompile 1 attr H1 regexCompile 1
attr H1 reading01Name TestReading1 attr H1 reading01Name TestReading1
attr H1 reading01Regex \"SimpleColor\",\"([^\"]+)\" attr H1 reading01Regex \"SimpleColor\",\"([^\"]+)\"
attr H1 reading02Name TestReading2 attr H1 reading02Name TestReading2
attr H1 reading02Regex \" SimpleColor \" ,\" ([^\"]+) \" attr H1 reading02Regex \" SimpleColor \" ,\" ([^\"]+) \"
attr H1 reading02RegOpt xms attr H1 reading02RegOpt xms
attr H1 reading03Name TestReading3 attr H1 reading03Name TestReading3
attr H1 reading03Regex \" SimpleColor \" ,\" ([^\"]+) \" attr H1 reading03Regex \" SimpleColor \" ,\" ([^\"]+) \"
attr H1 reading10Name TestReading4 attr H1 reading10Name TestReading4
attr H1 reading10Regex code . \" : (\d+) attr H1 reading10Regex code . \" : (\d+)
attr H1 reading10RegOpt gxms attr H1 reading10RegOpt gxms
attr H1 reading10RecombineExpr join ' ', @matchlist attr H1 reading10RecombineExpr join ' ', @matchlist
define H2 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON.testdata 0 define H2 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON.testdata 0
attr H2 verbose 5 attr H2 verbose 5
attr H2 minSendDelay 0 attr H2 minSendDelay 0
attr H2 regexDecode none attr H2 regexDecode none
attr H2 regexCompile 0 attr H2 regexCompile 0
attr H2 reading01Name TestReading1 attr H2 reading01Name TestReading1
attr H2 reading01Regex \"SimpleColor\",\"([^\"]+)\" attr H2 reading01Regex \"SimpleColor\",\"([^\"]+)\"
attr H2 reading02Name TestReading2 attr H2 reading02Name TestReading2
attr H2 reading02Regex \" SimpleColor \" ,\" ([^\"]+) \" attr H2 reading02Regex \" SimpleColor \" ,\" ([^\"]+) \"
attr H2 reading02RegOpt xms attr H2 reading02RegOpt xms
attr H2 reading03Name TestReading3 attr H2 reading03Name TestReading3
attr H2 reading03Regex \" SimpleColor \" ,\" ([^\"]+) \" attr H2 reading03Regex \" SimpleColor \" ,\" ([^\"]+) \"
attr H2 reading10Name TestReading4 attr H2 reading10Name TestReading4
attr H2 reading10Regex code . \" : (\d+) attr H2 reading10Regex code . \" : (\d+)
attr H2 reading10RegOpt gxms attr H2 reading10RegOpt gxms
attr H2 reading10RecombineExpr join ' ', @matchlist attr H2 reading10RecombineExpr join ' ', @matchlist
define H3 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON.testdata 0 define H3 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON.testdata 0
attr H3 verbose 3 attr H3 verbose 3
attr H3 reading01Name TestReading attr H3 reading01Name TestReading
attr H3 reading01JSON MQTT_ip_1 attr H3 reading01JSON MQTT_ip_1
attr H3 preProcessRegex s/168/466/g attr H3 preProcessRegex s/168/466/g
define H4 HTTPMOD file://t/FHEM/98_HTTPMOD/Login.testdata 0 define H4 HTTPMOD file://t/FHEM/98_HTTPMOD/Login.testdata 0
attr H4 verbose 3 attr H4 verbose 3
attr H4 minSendDelay 0 attr H4 minSendDelay 0
attr H4 queueDelay 0 attr H4 queueDelay 0
attr H4 showMatched 1 attr H4 showMatched 1
attr H4 authRetries 1 attr H4 authRetries 1
attr H4 reAuthRegex Login required attr H4 reAuthRegex Login required
attr H4 sid01URL file://t/FHEM/98_HTTPMOD/JSON.testdata attr H4 sid01URL file://t/FHEM/98_HTTPMOD/JSON.testdata
attr H4 sid02URL file://t/FHEM/98_HTTPMOD/JSON3.testdata attr H4 sid02URL file://t/FHEM/98_HTTPMOD/JSON3.testdata
attr H4 idRegex session ([\d]+) attr H4 idRegex session ([\d]+)
#attr H4 dontRequeueAfterAuth 1 #attr H4 dontRequeueAfterAuth 1
attr H4 reading01Name TestReading attr H4 reading01Name TestReading
attr H4 reading01JSON MQTT_ip_1 attr H4 reading01JSON MQTT_ip_1

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -1,28 +1,28 @@
define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON 0 define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON 0
attr H1 verbose 3 attr H1 verbose 3
attr H1 get01Name TestGet attr H1 get01Name TestGet
attr H1 get01Data Post Data for Test attr H1 get01Data Post Data for Test
attr H1 get01Header1 Content-Type: application/json attr H1 get01Header1 Content-Type: application/json
attr H1 get01URLExpr $old . '.testdata' attr H1 get01URLExpr $old . '.testdata'
attr H1 get01HdrExpr $old . '345' attr H1 get01HdrExpr $old . '345'
attr H1 get01DatExpr $old . '567' attr H1 get01DatExpr $old . '567'
define H2 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON.testdata 0 define H2 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON.testdata 0
attr H2 requestHeader1 Content-Type: Test-Content attr H2 requestHeader1 Content-Type: Test-Content
attr H2 requestHeader2 TestHeader: T1E2S3T attr H2 requestHeader2 TestHeader: T1E2S3T
attr H2 verbose 5 attr H2 verbose 5
attr H2 minSendDelay 0 attr H2 minSendDelay 0
attr H2 reading01Name TestReading attr H2 reading01Name TestReading
attr H2 reading01JSON MQTT_ip_1 attr H2 reading01JSON MQTT_ip_1
attr H2 reading01OExpr $val * 2 attr H2 reading01OExpr $val * 2
attr H2 reading02Name TestReading2 attr H2 reading02Name TestReading2
attr H2 reading02JSON modes attr H2 reading02JSON modes
attr H2 reading03Name CombReading attr H2 reading03Name CombReading
attr H2 reading03JSON modes attr H2 reading03JSON modes
attr H2 reading03RecombineExpr join ' ', @matchlist attr H2 reading03RecombineExpr join ' ', @matchlist
attr H2 set01Name TestSet1 attr H2 set01Name TestSet1
attr H2 set01Data TestSet1 PostData $val attr H2 set01Data TestSet1 PostData $val
attr H2 set01IExpr $val * 2 attr H2 set01IExpr $val * 2

View File

@ -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

View File

@ -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;

View File

@ -1,33 +1,33 @@
define H1 HTTPMOD none 0 define H1 HTTPMOD none 0
attr H1 verbose 5 attr H1 verbose 5
attr H1 minSendDelay 0 attr H1 minSendDelay 0
attr H1 reading01Name TestReading1 attr H1 reading01Name TestReading1
attr H1 reading01Regex "ip":\[192,(\d+),1,24\] attr H1 reading01Regex "ip":\[192,(\d+),1,24\]
attr H1 reading02Name TestReading2 attr H1 reading02Name TestReading2
attr H1 reading02Regex \"([^\"\]\[]+)\"\, attr H1 reading02Regex \"([^\"\]\[]+)\"\,
attr H1 reading02RegOpt g attr H1 reading02RegOpt g
attr H1 readingMaxAge 0.1 attr H1 readingMaxAge 0.1
attr H1 readingMaxAgeReplacement outdated attr H1 readingMaxAgeReplacement outdated
attr H1 readingMaxAgeReplacementMode text attr H1 readingMaxAgeReplacementMode text
attr H1 reading02MaxAgeReplacement "old - was $val" attr H1 reading02MaxAgeReplacement "old - was $val"
attr H1 reading02MaxAgeReplacementMode expression attr H1 reading02MaxAgeReplacementMode expression
attr H1 reading02-2MaxAgeReplacement tr attr H1 reading02-2MaxAgeReplacement tr
attr H1 reading02-2MaxAgeReplacementMode reading attr H1 reading02-2MaxAgeReplacementMode reading
attr H1 reading02-3MaxAgeReplacement NAME attr H1 reading02-3MaxAgeReplacement NAME
attr H1 reading02-3MaxAgeReplacementMode internal attr H1 reading02-3MaxAgeReplacementMode internal
attr H1 reading02-4MaxAgeReplacement 0 attr H1 reading02-4MaxAgeReplacement 0
attr H1 reading02-4MaxAgeReplacementMode delete attr H1 reading02-4MaxAgeReplacementMode delete
attr H1 get01URL file://t/FHEM/98_HTTPMOD/JSON.testdata attr H1 get01URL file://t/FHEM/98_HTTPMOD/JSON.testdata
attr H1 get01Name G1 attr H1 get01Name G1
attr H1 get02URL file://t/FHEM/98_HTTPMOD/empty.testdata attr H1 get02URL file://t/FHEM/98_HTTPMOD/empty.testdata
attr H1 get02Name G2 attr H1 get02Name G2

View File

@ -1,26 +1,49 @@
############################################## ##############################################
# test MaxAge # test MaxAge
############################################## ##############################################
package main;
use strict; use strict;
use warnings; use warnings;
use Test::More; 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'); fhem 'attr global mseclog 1';
is(FhemTestUtils_gotEvent("H1:TestReading1: 168"), 1, "Normal Reading 1"); NextStep();
is(FhemTestUtils_gotEvent("H1:TestReading2-1: tvlights"), 1, "Normal Reading 2");
sleep 0.15;
fhem('setreading H1 tr 789'); sub testStep1 {
fhem('get H1 G2'); LogStep "TestStep1: get H1 G1";
fhem('get H1 G1');
return 1;
}
is(FhemTestUtils_gotEvent("H1:TestReading1: outdated"), 1, "Outdated Reading 1 with mode text"); sub testStep2 {
is(FhemTestUtils_gotEvent("H1:TestReading2-1: old - was tvlights"), 1, "Outdated Reading 2 with mode expression"); LogStep "check normal readings";
is(FhemTestUtils_gotEvent("H1:TestReading2-2: 789"), 1, "Outdated Reading 3 with mode reading"); is(FhemTestUtils_gotEvent("H1:TestReading1: 168"), 1, "Normal Reading 1");
is(FhemTestUtils_gotEvent("H1:TestReading2-3: H1"), 1, "Outdated Reading 4 with mode internal"); is(FhemTestUtils_gotEvent("H1:TestReading2-1: tvlights"), 1, "Normal Reading 2");
is(FhemTestUtils_gotEvent("H1:TestReading2-4:"), 1, "Outdated Reading 5 with mode delete"); CheckAndReset();
return 1;
}
done_testing; sub testStep10 {
exit(0); 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; 1;

View File

@ -1,18 +1,18 @@
define GeoTest HTTPMOD none 0 define GeoTest HTTPMOD none 0
attr GeoTest minSendDelay 0 attr GeoTest minSendDelay 0
attr GeoTest verbose 5 attr GeoTest verbose 5
attr GeoTest enableControlSet 1 attr GeoTest enableControlSet 1
attr GeoTest replacement01Mode expression attr GeoTest replacement01Mode expression
attr GeoTest replacement01Regex %%date%% attr GeoTest replacement01Regex %%date%%
attr GeoTest get01Name Tag01 attr GeoTest get01Name Tag01
attr GeoTest get01Poll 1 attr GeoTest get01Poll 1
attr GeoTest get01Regex (?s)Zeit auswählen<br>(?<Tag01_WochenTag>[A-Za-z]+).-.(?<Tag01_Datum>[0-9\.]{10}).*?<td>09:15<\/td><td>(?<Tag01_09Uhr>.*?)<\/td>.*?<td>12:15<\/td><td>(?<Tag01_12Uhr>.*?)<\/td> attr GeoTest get01Regex (?s)Zeit auswählen<br>(?<Tag01_WochenTag>[A-Za-z]+).-.(?<Tag01_Datum>[0-9\.]{10}).*?<td>09:15<\/td><td>(?<Tag01_09Uhr>.*?)<\/td>.*?<td>12:15<\/td><td>(?<Tag01_12Uhr>.*?)<\/td>
attr GeoTest getURL file://geocache-planer.de/CAL/anmeldung.php?date=%%date%%&CALID=XYZ 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 get01Replacement01Value {strftime("%d.%m.%Y", localtime( time))}
attr GeoTest get02Name Test2 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 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 attr GeoTest get02Poll 1

View File

@ -1,17 +1,17 @@
define H2 HTTPMOD file://t/FHEM/98_HTTPMOD/Charset.testdata 0 define H2 HTTPMOD file://t/FHEM/98_HTTPMOD/Charset.testdata 0
attr H2 verbose 5 attr H2 verbose 5
attr H2 fileHeaderSplit --end-of-http-header-- attr H2 fileHeaderSplit --end-of-http-header--
attr H2 memReading 1 attr H2 memReading 1
attr H2 minSendDelay 0 attr H2 minSendDelay 0
attr H2 reading01Name TestReading1 attr H2 reading01Name TestReading1
attr H2 reading01Regex erraschung mit (.*) attr H2 reading01Regex erraschung mit (.*)
define H3 HTTPMOD file://t/FHEM/98_HTTPMOD/Charset.testdata2 0 define H3 HTTPMOD file://t/FHEM/98_HTTPMOD/Charset.testdata2 0
attr H3 verbose 5 attr H3 verbose 5
attr H3 fileHeaderSplit --end-of-http-header-- attr H3 fileHeaderSplit --end-of-http-header--
attr H3 minSendDelay 0 attr H3 minSendDelay 0
attr H3 bodyDecode auto attr H3 bodyDecode auto
attr H3 reading01Name Test attr H3 reading01Name Test
attr H3 reading01Regex >([^ ]+) auf neue attr H3 reading01Regex >([^ ]+) auf neue
attr H3 reading01Encode none attr H3 reading01Encode none

View File

@ -12,7 +12,7 @@ $modVersion =~ /^([0-9]+)\./;
my $major = $1; my $major = $1;
if ($major && $major >= 4) { if ($major && $major >= 4) {
plan tests => 9; plan tests => 11;
} else { } else {
plan skip_all => "This test only works for HTTPMOD version 4 or later, installed is $modVersion"; 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'); fhem('set H2 reread');
is(FhemTestUtils_gotEvent("H2:TestReading1: \xc3\x84\x6e"), 1, "TestReading with body decode"); 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(); CheckAndReset();
fhem('attr H2 dumpBuffers .'); fhem('attr H2 dumpBuffers .');
fhem('attr H2 verbose 5'); fhem('attr H2 verbose 5');
fhem('set H2 reread'); fhem('set H2 reread');
# todo: check # todo: check
# problem: where can we write buffers (with permission) during testing?
CheckAndReset(); CheckAndReset();
fhem 'set H3 reread'; fhem 'set H3 reread';

View File

@ -1,4 +1,4 @@
define H2 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON 0 define H2 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON 0
attr H2 verbose 5 attr H2 verbose 5
attr H2 get01Name TestGet attr H2 get01Name TestGet
attr H2 get01Data Post Data for Test attr H2 get01Data Post Data for Test

View File

@ -1,13 +1,13 @@
HTTP/1.1 200 OK HTTP/1.1 200 OK
Content-Type: text/html; charset=cp437 Content-Type: text/html; charset=cp437
--end-of-http-header-- --end-of-http-header--
<html> <html>
<head><title>Test</title></head> <head><title>Test</title></head>
<body> <body>
<center><h1>Test Data</h1></center> <center><h1>Test Data</h1></center>
<hr><center>for HTTPMOD Test</center> <hr><center>for HTTPMOD Test</center>
šberraschung mit Žnderungen ‚Š šberraschung mit Žnderungen ‚Š
</body> </body>
</html> </html>

View File

@ -1,14 +1,14 @@
HTTP/1.1 200 OK HTTP/1.1 200 OK
Content-Type: text/html; charset=cp437 Content-Type: text/html; charset=cp437
--end-of-http-header-- --end-of-http-header--
<html> <html>
<head><title>Test</title></head> <head><title>Test</title></head>
<body> <body>
<center><h1>Test Data</h1></center> <center><h1>Test Data</h1></center>
<hr><center>for HTTPMOD Test</center> <hr><center>for HTTPMOD Test</center>
Überraschung mit Änderungen éè Überraschung mit Änderungen éè
kleine Umlaute: äöü kleine Umlaute: äöü
</body> </body>
</html> </html>

View File

@ -1,48 +1,48 @@
HTTP/1.1 200 OK HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8 Content-Type: text/html; charset=utf-8
Cache-Control: no-cache, no-store, must-revalidate Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache Pragma: no-cache
Expires: 0 Expires: 0
Length: unspecified Length: unspecified
--end-of-http-header-- --end-of-http-header--
<html><head> <html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> <meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<title>BSB-LAN</title> <title>BSB-LAN</title>
<style>A:link {color:blue;text-decoration: none;} A:visited {color:blue;text-decoration: none;} A:hover {color:red;text-decoration: none;background-color:yellow} A:active {color:blue;text-decoration: none;} A:focus {color:red;text-decoration: none;} <style>A:link {color:blue;text-decoration: none;} A:visited {color:blue;text-decoration: none;} A:hover {color:red;text-decoration: none;background-color:yellow} A:active {color:blue;text-decoration: none;} A:focus {color:red;text-decoration: none;}
table {width: 100%; max-width: 1024px; margin: auto;} table {width: 100%; max-width: 1024px; margin: auto;}
td {vertical-align: top;} td {vertical-align: top;}
td.header {vertical-align: middle;} td.header {vertical-align: middle;}
input {width: 100%; box-sizing: border-box;} select {width: 100%;}</style> input {width: 100%; box-sizing: border-box;} select {width: 100%;}</style>
</head><body> </head><body>
<script>function set(line){ <script>function set(line){
var value = document.getElementById('value'+line).value.replace(/\.$/, ''); var value = document.getElementById('value'+line).value.replace(/\.$/, '');
value = value.replace(':', '.'); value = value.replace(':', '.');
value = value.replace('---', ''); value = value.replace('---', '');
if(isNaN(value)==false || value == ''){ if(isNaN(value)==false || value == ''){
window.open(document.getElementById('main_link').href+'S'+line+'='+value,'_self'); window.open(document.getElementById('main_link').href+'S'+line+'='+value,'_self');
}} }}
function setbit(line){ function setbit(line){
var x=document.getElementById('value'+line); var value=0; var x=document.getElementById('value'+line); var value=0;
for (var i=0; i<x.options.length; i++) { for (var i=0; i<x.options.length; i++) {
if(x.options[i].selected){ if(x.options[i].selected){
value=value+eval(x.options[i].value); value=value+eval(x.options[i].value);
}} }}
window.open(document.getElementById('main_link').href+'S'+line+'='+value,'_self'); window.open(document.getElementById('main_link').href+'S'+line+'='+value,'_self');
}</script> }</script>
<font face='Arial'> <font face='Arial'>
<center><h1><a href='/4444/' ID=main_link>BSB-LAN</A></h1></center> <center><h1><a href='/4444/' ID=main_link>BSB-LAN</A></h1></center>
<table align=center><tr bgcolor=#f0f0f0><td class="header" width=20% align=center> <table align=center><tr bgcolor=#f0f0f0><td class="header" width=20% align=center>
<a href='/4444/K'>Heizungsfunktionen</a></td> <a href='/4444/K'>Heizungsfunktionen</a></td>
<td class="header" width=20% align=center><a href='/4444/K49'>Sensoren</a></td><td class="header" width=20% align=center> <td class="header" width=20% align=center><a href='/4444/K49'>Sensoren</a></td><td class="header" width=20% align=center>
<a href='/4444/DG'>Zeichne Logdatei</a></td><td class="header" width=20% align=center><a href='/4444/Q'>Prüfe auf neue Parameter</a></td></tr> <a href='/4444/DG'>Zeichne Logdatei</a></td><td class="header" width=20% align=center><a href='/4444/Q'>Prüfe auf neue Parameter</a></td></tr>
<tr bgcolor=#f0f0f0><td class="header" width=20% align=center> <tr bgcolor=#f0f0f0><td class="header" width=20% align=center>
<a href='/4444/C'>Einstellungen</a></td><td class="header" width=20% align=center> <a href='/4444/C'>Einstellungen</a></td><td class="header" width=20% align=center>
<a href='https://1coderookie.github.io/BSB-LPB-LAN/kap08.html#81-auflistung-und-beschreibung-der-url-befehle' target='_new'>URL-Befehle</a></td> <a href='https://1coderookie.github.io/BSB-LPB-LAN/kap08.html#81-auflistung-und-beschreibung-der-url-befehle' target='_new'>URL-Befehle</a></td>
<td class="header" width=20% align=center><a href='https://1coderookie.github.io/BSB-LPB-LAN/inhaltsverzeichnis.html' target='new'>Handbuch</a></td> <td class="header" width=20% align=center><a href='https://1coderookie.github.io/BSB-LPB-LAN/inhaltsverzeichnis.html' target='new'>Handbuch</a></td>
<td class="header" width=20% align=center><a href='https://1coderookie.github.io/BSB-LPB-LAN/kap15.html' target='_new'>FAQ</a></td></tr></table><p></p> <td class="header" width=20% align=center><a href='https://1coderookie.github.io/BSB-LPB-LAN/kap15.html' target='_new'>FAQ</a></td></tr></table><p></p>
<table align=center><tr><td class="header"> <table align=center><tr><td class="header">
<tr><td> 712 Heizkreis 1 - Reduziertsollwert: 21.0 &deg;C</td><td> <tr><td> 712 Heizkreis 1 - Reduziertsollwert: 21.0 &deg;C</td><td>
<input type=text id='value712' VALUE='21.0'></td><td><input type=button value='Set' onclick="set(712)"></td></tr></td></tr></table> <input type=text id='value712' VALUE='21.0'></td><td><input type=button value='Set' onclick="set(712)"></td></tr></td></tr></table>
</body> </body>
</html> </html>