2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-13 17:26:34 +00:00

98_HTTPMOD: updated tests

git-svn-id: https://svn.fhem.de/fhem/trunk@22691 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
StefanStrobel 2020-08-29 16:17:28 +00:00
parent cf6b137674
commit 5555f28bd3
6 changed files with 125 additions and 0 deletions

View File

@ -0,0 +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

View File

@ -0,0 +1,28 @@
################################################
# test Expressions with JSON readings in config
################################################
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 => 5;
}
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_gotLog(qr/HandleSendQueue\ssends\supdate.*header:\sContent-Type:\sTest-Content.*TestHeader:\sT1E2S3T/xms), 1, "requestHeader");
fhem('attr H1 verbose 5');
fhem('set H2 TestSet1 4');
is(FhemTestUtils_gotLog("TestSet1 PostData 8"), 1, "set IExpr1 to Post Data in log");
done_testing;
exit(0);
1;

View File

@ -0,0 +1,11 @@
defmod GeoTest HTTPMOD none 0
attr GeoTest verbose 3
attr GeoTest enableControlSet 1
attr GeoTest get01Name Tag01
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 get01Replacement01Value {strftime("%d.%m.%Y", localtime( time))}
attr GeoTest getURL file://geocache-planer.de/CAL/anmeldung.php?date=%%date%%&CALID=XYZ
attr GeoTest replacement01Mode expression
attr GeoTest replacement01Regex %%date%%

View File

@ -0,0 +1,18 @@
##############################################
# test replacements
#
##############################################
use strict;
use warnings;
use Test::More;
fhem('set GeoTest reread');
InternalTimer(time()+1, sub() {
is(FhemTestUtils_gotLog(qr/Read callback: Error: geocache\-planer.*date=[\d]+\.\d+\.\d+/), 1, "Expr replacement in URL");
done_testing;
exit(0);
}, 0);
1;

View File

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

View File

@ -0,0 +1,36 @@
##############################################
# test evalExpr Util function
##############################################
use strict;
use warnings;
use Test::More;
use_ok ('FHEM::HTTPMOD::Utils', qw(:all));
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);
1;