mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 18:59:33 +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:
parent
fcef8a3e56
commit
d48931a37b
9
fhem/t/FHEM/98_HTTPMOD/32_SetExpr.cfg
Normal file
9
fhem/t/FHEM/98_HTTPMOD/32_SetExpr.cfg
Normal 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
|
33
fhem/t/FHEM/98_HTTPMOD/32_SetExpr.t
Normal file
33
fhem/t/FHEM/98_HTTPMOD/32_SetExpr.t
Normal 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;
|
18
fhem/t/FHEM/98_HTTPMOD/33_SetExtensions.cfg
Normal file
18
fhem/t/FHEM/98_HTTPMOD/33_SetExtensions.cfg
Normal 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
|
||||||
|
|
||||||
|
|
58
fhem/t/FHEM/98_HTTPMOD/33_SetExtensions.t
Normal file
58
fhem/t/FHEM/98_HTTPMOD/33_SetExtensions.t
Normal 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;
|
15
fhem/t/FHEM/98_HTTPMOD/39_Map.cfg
Normal file
15
fhem/t/FHEM/98_HTTPMOD/39_Map.cfg
Normal 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
|
||||||
|
|
24
fhem/t/FHEM/98_HTTPMOD/39_Map.t
Normal file
24
fhem/t/FHEM/98_HTTPMOD/39_Map.t
Normal 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;
|
@ -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;
|
||||||
|
@ -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';
|
||||||
|
Loading…
Reference in New Issue
Block a user