From c8c364e99fdcd487708ed74e3f9c8b7b49eab4db Mon Sep 17 00:00:00 2001 From: Christopher Liebman Date: Sun, 2 Dec 2018 09:36:39 -0800 Subject: [PATCH] use OrderedDict to force order of get params refactor to share request handler code in tests --- .../test_http_server/test_http_server.ino | 62 +++++++------------ .../test_http_server/test_http_server.py | 3 +- 2 files changed, 25 insertions(+), 40 deletions(-) diff --git a/tests/device/test_http_server/test_http_server.ino b/tests/device/test_http_server/test_http_server.ino index 4231cd066b..c408555822 100644 --- a/tests/device/test_http_server/test_http_server.ino +++ b/tests/device/test_http_server/test_http_server.ino @@ -11,6 +11,7 @@ static ESP8266WebServer server(80); static uint32_t siteHits = 0; static String siteData = ""; + void setup() { Serial.begin(115200); @@ -26,21 +27,27 @@ void setup() BS_RUN(Serial); } +void handle_request() +{ + for (uint8_t i=0; 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 0) - siteData += "\n"; - siteData += server.argName(i) + " = " + server.arg(i); - } - siteHits++; - server.send(200, "text/plain", siteData); - }); + siteData = ""; + server.on("/get", HTTP_GET, &handle_request); uint32_t startTime = millis(); while(siteHits == 0 && (millis() - startTime) < 10000) server.handleClient(); @@ -52,16 +59,8 @@ TEST_CASE("HTTP POST Parameters", "[HTTPServer]") { { siteHits = 0; - server.on("/post", HTTP_POST, [](){ - siteData = ""; - for (uint8_t i=0; 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(); @@ -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 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(); @@ -94,15 +85,8 @@ TEST_CASE("HTTP Upload", "[HTTPServer]") { { siteHits = 0; - server.on("/upload", HTTP_POST, [](){ - for (uint8_t i=0; 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; diff --git a/tests/device/test_http_server/test_http_server.py b/tests/device/test_http_server/test_http_server.py index c6ecde6a22..319a8a7101 100644 --- a/tests/device/test_http_server/test_http_server.py +++ b/tests/device/test_http_server/test_http_server.py @@ -1,3 +1,4 @@ +from collections import OrderedDict from mock_decorators import setup, teardown from threading import Thread from poster.encode import MultipartParam @@ -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')