mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-21 10:26:06 +03:00
Add missing python script for HTTP client test
This commit is contained in:
parent
0cd82db486
commit
15aed3b06e
73
tests/device/test_http_client/test_http_client.py
Normal file
73
tests/device/test_http_client/test_http_client.py
Normal file
@ -0,0 +1,73 @@
|
||||
from mock_decorators import setup, teardown
|
||||
from flask import Flask, request
|
||||
from threading import Thread
|
||||
import urllib2
|
||||
import os
|
||||
import ssl
|
||||
|
||||
@setup('HTTP GET request')
|
||||
def setup_http_get(e):
|
||||
app = Flask(__name__)
|
||||
def shutdown_server():
|
||||
func = request.environ.get('werkzeug.server.shutdown')
|
||||
if func is None:
|
||||
raise RuntimeError('Not running with the Werkzeug Server')
|
||||
func()
|
||||
@app.route('/shutdown')
|
||||
def shutdown():
|
||||
shutdown_server()
|
||||
return 'Server shutting down...'
|
||||
@app.route("/")
|
||||
def root():
|
||||
return 'hello!!!'
|
||||
@app.route("/data")
|
||||
def get_data():
|
||||
size = int(request.args['size'])
|
||||
return 'a'*size
|
||||
def flaskThread():
|
||||
app.run(host='0.0.0.0', port=8088)
|
||||
th = Thread(target=flaskThread)
|
||||
th.start()
|
||||
|
||||
@teardown('HTTP GET request')
|
||||
def teardown_http_get(e):
|
||||
response = urllib2.urlopen('http://localhost:8088/shutdown')
|
||||
html = response.read()
|
||||
|
||||
|
||||
@setup('HTTPS GET request')
|
||||
def setup_http_get(e):
|
||||
app = Flask(__name__)
|
||||
def shutdown_server():
|
||||
func = request.environ.get('werkzeug.server.shutdown')
|
||||
if func is None:
|
||||
raise RuntimeError('Not running with the Werkzeug Server')
|
||||
func()
|
||||
@app.route('/shutdown')
|
||||
def shutdown():
|
||||
shutdown_server()
|
||||
return 'Server shutting down...'
|
||||
@app.route("/")
|
||||
def root():
|
||||
return 'hello!!!'
|
||||
@app.route("/data")
|
||||
def get_data():
|
||||
size = int(request.args['size'])
|
||||
return 'a'*size
|
||||
def flaskThread():
|
||||
p = os.path.dirname(os.path.abspath(__file__))
|
||||
context = (p + '/server.crt', p + '/server.key')
|
||||
print context
|
||||
app.run(host='0.0.0.0', port=8088, ssl_context=context)
|
||||
th = Thread(target=flaskThread)
|
||||
th.start()
|
||||
|
||||
@teardown('HTTPS GET request')
|
||||
def teardown_http_get(e):
|
||||
ctx = ssl.create_default_context()
|
||||
ctx.check_hostname = False
|
||||
ctx.verify_mode = ssl.CERT_NONE
|
||||
p = os.path.dirname(os.path.abspath(__file__))
|
||||
response = urllib2.urlopen('https://localhost:8088/shutdown', context=ctx)
|
||||
html = response.read()
|
||||
|
Loading…
x
Reference in New Issue
Block a user