mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-09 20:57:11 +00:00
98_HTTPMOD: updated tests
git-svn-id: https://svn.fhem.de/fhem/trunk@22692 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
5555f28bd3
commit
2cce0ae0c1
@ -3,3 +3,4 @@ attr H2 verbose 5
|
||||
attr H2 fileHeaderSplit --end-of-http-header--
|
||||
attr H2 queueDelay 2
|
||||
attr H2 minSendDelay 2
|
||||
|
||||
|
@ -5,6 +5,17 @@ use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
|
||||
my $hash = $defs{'H2'};
|
||||
my $modVersion = $hash->{ModuleVersion};
|
||||
$modVersion =~ /^([0-9]+)\./;
|
||||
my $major = $1;
|
||||
|
||||
if ($major && $major >= 4) {
|
||||
plan tests => 1;
|
||||
} else {
|
||||
plan skip_all => "This test only works for HTTPMOD version 4 or later, installed is $modVersion";
|
||||
}
|
||||
|
||||
fhem('set H2 reread');
|
||||
|
||||
is(FhemTestUtils_gotLog("AddToQueue prepends type update to URL http://test.url/"), 1, "Match redirected url");
|
||||
|
@ -5,6 +5,14 @@ use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
|
||||
eval "use JSON";
|
||||
if ($@) {
|
||||
plan skip_all => "This test checks an optional JSON-Feature of HTTPMOD and can only be run with the JSON library installed. Please install JSON Library (apt-get install libjson-perl)";
|
||||
} else {
|
||||
plan tests => 3;
|
||||
}
|
||||
|
||||
|
||||
fhem('set H1 reread');
|
||||
InternalTimer(time()+1, sub() {
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
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 get01Data Post Data for Test
|
||||
attr H1 get01URLExpr $old . '.testdata'
|
||||
attr H1 get01HdrExpr $old . '345'
|
||||
attr H1 get01DatExpr $old . '567'
|
||||
@ -13,14 +13,16 @@ 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 reading01Regex "ip":\[192,(\d+),1,24\]
|
||||
attr H2 reading01OExpr $val * 2
|
||||
|
||||
attr H2 reading02Name TestReading2
|
||||
attr H2 reading02JSON modes
|
||||
attr H2 reading02Regex \"([^\"\]\[]+)\"\,
|
||||
attr H2 reading02RegOpt g
|
||||
|
||||
attr H2 reading03Name CombReading
|
||||
attr H2 reading03JSON modes
|
||||
attr H2 reading03Regex \"([^\"\]\[]+)\"\,
|
||||
attr H2 reading03RegOpt g
|
||||
attr H2 reading03RecombineExpr join ' ', @matchlist
|
||||
|
||||
attr H2 set01Name TestSet1
|
||||
|
@ -4,7 +4,7 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
use FHEM::HTTPMOD::Utils qw(:all);
|
||||
|
||||
|
||||
fhem('attr H1 verbose 5');
|
||||
fhem('attr H1 get02IExpr $vale');
|
||||
@ -17,38 +17,15 @@ is(FhemTestUtils_gotLog("header Content-Type: application/json345"), 1, "Header
|
||||
is(FhemTestUtils_gotLog(", data Post Data for Test567"), 1, "Post Data expression in log");
|
||||
|
||||
fhem('set H2 reread');
|
||||
is(FhemTestUtils_gotEvent(qr/H2:TestReading:\s336/xms), 1, "JSON Reading creation with OExpr Expression");
|
||||
is(FhemTestUtils_gotEvent("H2:TestReading2-8: UDP"), 1, "JSON multiple Reading creation");
|
||||
is(FhemTestUtils_gotEvent("H2:CombReading: Off SimpleColor RainbowChase"), 1, "Reading recombine expresion");
|
||||
is(FhemTestUtils_gotEvent(qr/H2:TestReading:\s336/xms), 1, "Regex Reading creation with OExpr Expression");
|
||||
is(FhemTestUtils_gotEvent("H2:TestReading2-10: UDP"), 1, "Regex multiple Reading creation");
|
||||
|
||||
is(FhemTestUtils_gotEvent("H2:CombReading: tvlights 0 Off SimpleColor"), 1, "Reading recombine expresion");
|
||||
is(FhemTestUtils_gotLog(qr/HandleSendQueue\ssends\supdate.*header:\sContent-Type:\sTest-Content.*TestHeader:\sT1E2S3T/xms), 1, "requestHeader");
|
||||
|
||||
fhem('set H2 TestSet1 4');
|
||||
is(FhemTestUtils_gotLog("TestSet1 PostData 8"), 1, "set IExpr1 to Post Data in log");
|
||||
|
||||
my $hash = $defs{'H2'};
|
||||
my $name = 'H2';
|
||||
my $val = 5;
|
||||
my @array = (1,2,3);
|
||||
my %tHash = (a => 10, b => 20);
|
||||
my $exp = '$val * 2';
|
||||
|
||||
my $result = EvalExpr($hash, $exp, {'$val' => $val, '@array' => \@array});
|
||||
#Log3 $name, 3, "$name: result of EvalExpr test 1 = $result";
|
||||
is $result, 10, "simple expression with one scalar in list";
|
||||
|
||||
$exp = '$array[1] * 2';
|
||||
$result = EvalExpr($hash, $exp, {'$val' => $val, '@array' => \@array});
|
||||
is $result, 4, "simple expression with array ref in hash";
|
||||
|
||||
$exp = '$hash{a} * 2';
|
||||
$result = EvalExpr($hash, $exp, {'$val' => $val, '%hash' => \%tHash});
|
||||
is $result, 20, "simple expression with hash ref in hash";
|
||||
|
||||
$exp = '$hash->{a} * 2';
|
||||
$result = EvalExpr($hash, $exp, {'$val' => $val, '$hash' => \%tHash});
|
||||
is $result, 20, "simple expression with hash ref as ref in hash";
|
||||
|
||||
|
||||
done_testing;
|
||||
exit(0);
|
||||
|
||||
|
@ -15,6 +15,18 @@ use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
|
||||
my $hash = $defs{'H2'};
|
||||
my $modVersion = $hash->{ModuleVersion};
|
||||
$modVersion =~ /^([0-9]+)\./;
|
||||
my $major = $1;
|
||||
|
||||
if ($major && $major >= 4) {
|
||||
plan tests => 13;
|
||||
} else {
|
||||
plan skip_all => "This test only works for HTTPMOD version 4 or later, installed is $modVersion";
|
||||
}
|
||||
|
||||
|
||||
fhem('set H1 reread');
|
||||
is(FhemTestUtils_gotEvent(qr/H1:TestReading1:\sRainbowChase/xms), 1, "match simple case with regex compilation");
|
||||
is(FhemTestUtils_gotEvent(qr/H1:TestReading2:\sRainbowChase/xms), 1, "match with options xms with regex compilation");
|
||||
|
@ -3,10 +3,11 @@ attr H1 verbose 5
|
||||
attr H1 minSendDelay 0
|
||||
|
||||
attr H1 reading01Name TestReading1
|
||||
attr H1 reading01JSON MQTT_ip_1
|
||||
attr H1 reading01Regex "ip":\[192,(\d+),1,24\]
|
||||
|
||||
attr H1 reading02Name TestReading2
|
||||
attr H1 reading02JSON modes
|
||||
attr H1 reading02Regex \"([^\"\]\[]+)\"\,
|
||||
attr H1 reading02RegOpt g
|
||||
attr H1 readingMaxAge 0.1
|
||||
|
||||
attr H1 readingMaxAgeReplacement outdated
|
||||
|
@ -7,7 +7,7 @@ use Test::More;
|
||||
|
||||
fhem('get H1 G1');
|
||||
is(FhemTestUtils_gotEvent("H1:TestReading1: 168"), 1, "Normal Reading 1");
|
||||
is(FhemTestUtils_gotEvent("H1:TestReading2-1: Off"), 1, "Normal Reading 2");
|
||||
is(FhemTestUtils_gotEvent("H1:TestReading2-1: tvlights"), 1, "Normal Reading 2");
|
||||
|
||||
sleep 0.15;
|
||||
|
||||
@ -15,7 +15,7 @@ fhem('setreading H1 tr 789');
|
||||
fhem('get H1 G2');
|
||||
|
||||
is(FhemTestUtils_gotEvent("H1:TestReading1: outdated"), 1, "Outdated Reading 1 with mode text");
|
||||
is(FhemTestUtils_gotEvent("H1:TestReading2-1: old - was Off"), 1, "Outdated Reading 2 with mode expression");
|
||||
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");
|
||||
|
@ -5,10 +5,25 @@ use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
|
||||
my $hash = $defs{'H2'};
|
||||
my $modVersion = $hash->{ModuleVersion};
|
||||
$modVersion =~ /^([0-9]+)\./;
|
||||
my $major = $1;
|
||||
|
||||
if ($major && $major >= 4) {
|
||||
plan tests => 3;
|
||||
} else {
|
||||
plan skip_all => "This test only works for HTTPMOD version 4 or later, installed is $modVersion";
|
||||
}
|
||||
|
||||
fhem('attr H2 bodyDecode none');
|
||||
fhem('set H2 reread');
|
||||
|
||||
is(FhemTestUtils_gotEvent("H2:Fhem_Mem"), 1, "memReading");
|
||||
SKIP: {
|
||||
skip "this test can only run on Linux", 1 if (!-e "/proc/$$/status");
|
||||
is(FhemTestUtils_gotEvent("H2:Fhem_Mem"), 1, "memReading");
|
||||
}
|
||||
|
||||
is(FhemTestUtils_gotEvent("H2:TestReading1: \x8e\x6e"), 1, "TestReading without bodyDecode");
|
||||
|
||||
fhem('attr H2 bodyDecode auto');
|
||||
|
Loading…
x
Reference in New Issue
Block a user