Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix device test test_http_server #5414

Merged
merged 8 commits into from
Dec 8, 2018
62 changes: 23 additions & 39 deletions tests/device/test_http_server/test_http_server.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ static ESP8266WebServer server(80);
static uint32_t siteHits = 0;
static String siteData = "";


void setup()
{
Serial.begin(115200);
Expand All @@ -26,21 +27,27 @@ void setup()
BS_RUN(Serial);
}

void handle_request()
{
for (uint8_t i=0; i<server.args(); i++){
// skip "plain" which is automatically added during arg parsing for post's
if (server.argName(i) == "plain")
continue;
if(i > 0)
siteData += "\n";
siteData += server.argName(i) + " = " + server.arg(i);
}
siteHits++;
server.send(200, "text/plain", siteData);
}


TEST_CASE("HTTP GET Parameters", "[HTTPServer]")
{
{
siteHits = 0;
server.on("/get", HTTP_GET, [](){
siteData = "";
for (uint8_t i=0; i<server.args(); i++){
if(i > 0)
siteData += "\n";
siteData += server.argName(i) + " = " + server.arg(i);
}
siteHits++;
server.send(200, "text/plain", siteData);
});
siteData = "";
devyte marked this conversation as resolved.
Show resolved Hide resolved
server.on("/get", HTTP_GET, &handle_request);
uint32_t startTime = millis();
while(siteHits == 0 && (millis() - startTime) < 10000)
server.handleClient();
Expand All @@ -52,16 +59,8 @@ TEST_CASE("HTTP POST Parameters", "[HTTPServer]")
{
{
siteHits = 0;
server.on("/post", HTTP_POST, [](){
siteData = "";
for (uint8_t i=0; i<server.args(); i++){
if(i > 0)
siteData += "\n";
siteData += server.argName(i) + " = " + server.arg(i);
}
siteHits++;
server.send(200, "text/plain", siteData);
});
siteData = "";
server.on("/post", HTTP_POST, &handle_request);
uint32_t startTime = millis();
while(siteHits == 0 && (millis() - startTime) < 10000)
server.handleClient();
Expand All @@ -73,16 +72,8 @@ TEST_CASE("HTTP GET+POST Parameters", "[HTTPServer]")
{
{
siteHits = 0;
server.on("/get_and_post", HTTP_POST, [](){
siteData = "";
for (uint8_t i=0; i<server.args(); i++){
if(i > 0)
siteData += "\n";
siteData += server.argName(i) + " = " + server.arg(i);
}
siteHits++;
server.send(200, "text/plain", siteData);
});
siteData = "";
server.on("/get_and_post", HTTP_POST, &handle_request);
uint32_t startTime = millis();
while(siteHits == 0 && (millis() - startTime) < 10000)
server.handleClient();
Expand All @@ -94,15 +85,8 @@ TEST_CASE("HTTP Upload", "[HTTPServer]")
{
{
siteHits = 0;
server.on("/upload", HTTP_POST, [](){
for (uint8_t i=0; i<server.args(); i++){
if(i > 0)
siteData += "\n";
siteData += server.argName(i) + " = " + server.arg(i);
}
siteHits++;
server.send(200, "text/plain", siteData);
}, [](){
siteData = "";
server.on("/upload", HTTP_POST, &handle_request, [](){
HTTPUpload& upload = server.upload();
if(upload.status == UPLOAD_FILE_START){
siteData = upload.filename;
Expand Down
3 changes: 2 additions & 1 deletion tests/device/test_http_server/test_http_server.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections import OrderedDict
from mock_decorators import setup, teardown
from threading import Thread
from poster.encode import MultipartParam
Expand All @@ -24,7 +25,7 @@ def http_test(res, url, get=None, post=None):
@setup('HTTP GET Parameters')
def setup_http_get_params(e):
def testRun():
return http_test('var1 = val with spaces\nva=r+ = so&me%', 'http://etd.local/get', {'var1' : 'val with spaces', 'va=r+' : 'so&me%'})
return http_test('var1 = val with spaces\nva=r+ = so&me%', 'http://etd.local/get', OrderedDict([('var1', 'val with spaces'), ('va=r+', 'so&me%')]))
Thread(target=testRun).start()

@teardown('HTTP GET Parameters')
Expand Down