-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial WebServer Test * ignore .pyc files * add poster as requirement to virtualenv
- Loading branch information
Showing
5 changed files
with
202 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ exclude.txt | |
tools/sdk/lib/liblwip_src.a | ||
tools/sdk/lwip/src/build | ||
tools/sdk/lwip/src/liblwip_src.a | ||
|
||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ PyYAML==3.11 | |
six==1.10.0 | ||
Werkzeug==0.11.9 | ||
wheel==0.24.0 | ||
poster==0.8.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
#include <Arduino.h> | ||
#include <ESP8266WiFi.h> | ||
#include <ESP8266WebServer.h> | ||
#include <ESP8266mDNS.h> | ||
#include <BSTest.h> | ||
#include <test_config.h> | ||
#include <pgmspace.h> | ||
|
||
BS_ENV_DECLARE(); | ||
|
||
static ESP8266WebServer server(80); | ||
static uint32_t siteHits = 0; | ||
static String siteData = ""; | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
Serial.setDebugOutput(true); | ||
WiFi.persistent(false); | ||
WiFi.begin(STA_SSID, STA_PASS); | ||
while (WiFi.status() != WL_CONNECTED) { | ||
delay(500); | ||
} | ||
MDNS.begin("etd"); | ||
server.onNotFound([](){ server.send(404); }); | ||
server.begin(); | ||
BS_RUN(Serial); | ||
} | ||
|
||
|
||
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 += "&"; | ||
siteData += server.argName(i) + "=" + server.arg(i); | ||
} | ||
siteHits++; | ||
server.send(200, "text/plain", siteData); | ||
}); | ||
uint32_t startTime = millis(); | ||
while(siteHits == 0 && (millis() - startTime) < 10000) | ||
server.handleClient(); | ||
REQUIRE(siteHits > 0 && siteData.equals("var1=val with spaces&var+=some%")); | ||
} | ||
} | ||
|
||
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 += "&"; | ||
siteData += server.argName(i) + "=" + server.arg(i); | ||
} | ||
siteHits++; | ||
server.send(200, "text/plain", siteData); | ||
}); | ||
uint32_t startTime = millis(); | ||
while(siteHits == 0 && (millis() - startTime) < 10000) | ||
server.handleClient(); | ||
REQUIRE(siteHits > 0 && siteData.equals("var2=val with spaces")); | ||
} | ||
} | ||
|
||
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 += "&"; | ||
siteData += server.argName(i) + "=" + server.arg(i); | ||
} | ||
siteHits++; | ||
server.send(200, "text/plain", siteData); | ||
}); | ||
uint32_t startTime = millis(); | ||
while(siteHits == 0 && (millis() - startTime) < 10000) | ||
server.handleClient(); | ||
REQUIRE(siteHits > 0 && siteData.equals("var3=val with spaces&var+=some%")); | ||
} | ||
} | ||
|
||
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 += "&"; | ||
siteData += server.argName(i) + "=" + server.arg(i); | ||
} | ||
siteHits++; | ||
server.send(200, "text/plain", siteData); | ||
}, [](){ | ||
HTTPUpload& upload = server.upload(); | ||
if(upload.status == UPLOAD_FILE_START){ | ||
siteData = upload.filename; | ||
} else if(upload.status == UPLOAD_FILE_END){ | ||
siteData.concat(":"); | ||
siteData.concat(String(upload.totalSize)); | ||
siteData.concat("&"); | ||
} | ||
}); | ||
uint32_t startTime = millis(); | ||
while(siteHits == 0 && (millis() - startTime) < 10000) | ||
server.handleClient(); | ||
REQUIRE(siteHits > 0 && siteData.equals("test.txt:16&var4=val with spaces")); | ||
} | ||
} | ||
|
||
void loop() | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from mock_decorators import setup, teardown | ||
from threading import Thread | ||
from poster.encode import MultipartParam | ||
from poster.encode import multipart_encode | ||
from poster.streaminghttp import register_openers | ||
import urllib2 | ||
import urllib | ||
|
||
def http_test(res, url, get=None, post=None): | ||
response = '' | ||
try: | ||
if get: | ||
url += '?' + urllib.urlencode(get) | ||
if post: | ||
post = urllib.urlencode(post) | ||
request = urllib2.urlopen(url, post, 2) | ||
response = request.read() | ||
except: | ||
return 1 | ||
if response != res: | ||
return 1 | ||
return 0 | ||
|
||
@setup('HTTP GET Parameters') | ||
def setup_http_get_params(e): | ||
def testRun(): | ||
return http_test('var1=val with spaces&var+=some%', 'http://etd.local/get', {'var1' : 'val with spaces', 'var+' : 'some%'}) | ||
Thread(target=testRun).start() | ||
|
||
@teardown('HTTP GET Parameters') | ||
def teardown_http_get_params(e): | ||
return 0 | ||
|
||
@setup('HTTP POST Parameters') | ||
def setup_http_post_params(e): | ||
def testRun(): | ||
return http_test('var2=val with spaces', 'http://etd.local/post', None, {'var2' : 'val with spaces'}) | ||
Thread(target=testRun).start() | ||
|
||
@teardown('HTTP POST Parameters') | ||
def teardown_http_post_params(e): | ||
return 0 | ||
|
||
@setup('HTTP GET+POST Parameters') | ||
def setup_http_getpost_params(e): | ||
def testRun(): | ||
return http_test('var3=val with spaces&var+=some%', 'http://etd.local/get_and_post', {'var3' : 'val with spaces'}, {'var+' : 'some%'}) | ||
Thread(target=testRun).start() | ||
|
||
@teardown('HTTP GET+POST Parameters') | ||
def teardown_http_getpost_params(e): | ||
return 0 | ||
|
||
@setup('HTTP Upload') | ||
def setup_http_upload(e): | ||
def testRun(): | ||
response = '' | ||
try: | ||
register_openers() | ||
p = MultipartParam("file", "0123456789abcdef", "test.txt", "text/plain; charset=utf8") | ||
datagen, headers = multipart_encode( [("var4", "val with spaces"), p] ) | ||
request = urllib2.Request('http://etd.local/upload', datagen, headers) | ||
response = urllib2.urlopen(request, None, 2).read() | ||
except: | ||
return 1 | ||
if response != 'test.txt:16&var4=val with spaces': | ||
return 1 | ||
return 0 | ||
Thread(target=testRun).start() | ||
|
||
@teardown('HTTP Upload') | ||
def teardown_http_upload(e): | ||
return 0 |