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

98_HTTPMOD: update Tests

git-svn-id: https://svn.fhem.de/fhem/trunk@23941 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
StefanStrobel 2021-03-13 10:07:19 +00:00
parent c2d15b47b4
commit 49032447f3
6 changed files with 147 additions and 2 deletions

View File

@ -0,0 +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 <center>(.*)</center>
attr H1 get01FollowGet O2
attr H1 get02Name O2
attr H1 get02Regex <cen(.*)<h1>
attr H1 get02FollowGet O3
attr H1 get03Name O3
attr H1 get03Regex <c(.*)<h1>
attr H1 maxGetChain 5

View File

@ -0,0 +1,40 @@
##############################################
# test cookies
##############################################
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 => 7;
} else {
plan skip_all => "This test only works for HTTPMOD version 4 or later, installed is $modVersion";
}
fhem 'get H1 O1';
is(FhemTestUtils_gotEvent("O1: <h1>Test</h1>"), 1, "got O1");
is(FhemTestUtils_gotEvent("O2: ter>"), 1, "got O2");
is(FhemTestUtils_gotEvent("O3: enter>"), 1, "got O3");
fhem 'attr H1 maxGetChain 1';
FhemTestUtils_resetLogs();
FhemTestUtils_resetEvents();
fhem 'get H1 O1';
is(FhemTestUtils_gotEvent("O1: <h1>Test</h1>"), 1, "got O1");
is(FhemTestUtils_gotEvent("O2: ter>"), 1, "got O2");
is(FhemTestUtils_gotEvent("O3: enter>"), 0, "no O3, chain too long");
is(FhemTestUtils_gotLog("chain would get longer "), 1, "chain too long");
done_testing;
exit(0);
1;

View File

@ -7,3 +7,11 @@ 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

View File

@ -4,6 +4,7 @@
use strict;
use warnings;
use Test::More;
use FHEM::Modbus::TestUtils qw(:all);
my $hash = $defs{'H2'};
my $modVersion = $hash->{ModuleVersion};
@ -11,7 +12,7 @@ $modVersion =~ /^([0-9]+)\./;
my $major = $1;
if ($major && $major >= 4) {
plan tests => 3;
plan tests => 9;
} else {
plan skip_all => "This test only works for HTTPMOD version 4 or later, installed is $modVersion";
}
@ -27,12 +28,28 @@ SKIP: {
is(FhemTestUtils_gotEvent("H2:TestReading1: \x8e\x6e"), 1, "TestReading without bodyDecode");
CheckAndReset();
fhem('attr H2 bodyDecode auto');
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 dumpBuffers .');
fhem('attr H2 verbose 5');
fhem('set H2 reread');
# todo: check
CheckAndReset();
fhem 'set H3 reread';
is(FhemTestUtils_gotEvent("H3:Test: Pr\xfcfe"), 1, "TestReading with body decode and Encode none");
CheckAndReset();
fhem 'deleteattr H3 bodyDecode';
fhem 'set H3 reread';
is(FhemTestUtils_gotEvent("H3:Test: Pr\xc3\xbcfe"), 1, "TestReading with body decode and Encode none");
done_testing;
exit(0);

View File

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

View File

@ -0,0 +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--
<html><head>
<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">
<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;}
table {width: 100%; max-width: 1024px; margin: auto;}
td {vertical-align: top;}
td.header {vertical-align: middle;}
input {width: 100%; box-sizing: border-box;} select {width: 100%;}</style>
</head><body>
<script>function set(line){
var value = document.getElementById('value'+line).value.replace(/\.$/, '');
value = value.replace(':', '.');
value = value.replace('---', '');
if(isNaN(value)==false || value == ''){
window.open(document.getElementById('main_link').href+'S'+line+'='+value,'_self');
}}
function setbit(line){
var x=document.getElementById('value'+line); var value=0;
for (var i=0; i<x.options.length; i++) {
if(x.options[i].selected){
value=value+eval(x.options[i].value);
}}
window.open(document.getElementById('main_link').href+'S'+line+'='+value,'_self');
}</script>
<font face='Arial'>
<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>
<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>
<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>
<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>
<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>
<table align=center><tr><td class="header">
<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>
</body>
</html>