mirror of
https://github.com/jamesroberts/fastwsgi.git
synced 2025-12-20 13:49:31 -06:00
Adds WSGI validator test
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import pytest
|
||||
import fastwsgi
|
||||
import time
|
||||
from multiprocessing import Process
|
||||
|
||||
|
||||
@@ -10,10 +11,12 @@ PORT = 8080
|
||||
class ServerProcess:
|
||||
def __init__(self, application, host=HOST, port=PORT) -> None:
|
||||
self.process = Process(target=fastwsgi.run, args=(application, host, port))
|
||||
self.endpoint = f"http://{host}:{port}"
|
||||
|
||||
def __enter__(self):
|
||||
self.process.start()
|
||||
return self.process
|
||||
time.sleep(1) # Allow server to start
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_value, exc_tb):
|
||||
if self.process.is_alive():
|
||||
|
||||
@@ -6,11 +6,11 @@ app = Flask(__name__)
|
||||
|
||||
@app.get("/")
|
||||
def hello_world():
|
||||
return "Hello, World!", 200
|
||||
return "Hello, Flask!", 200
|
||||
|
||||
|
||||
def test_uwsgi_hello_world(server_process):
|
||||
with server_process(app):
|
||||
result = requests.get("http://127.0.0.1:8080/")
|
||||
with server_process(app) as server:
|
||||
result = requests.get(server.endpoint)
|
||||
assert result.status_code == 200
|
||||
assert result.text == "Hello, World!"
|
||||
assert result.text == "Hello, Flask!"
|
||||
|
||||
@@ -3,11 +3,11 @@ import requests
|
||||
|
||||
def wsgi_app(environ, start_response):
|
||||
start_response('200 OK', [('Content-Type', 'text/html')])
|
||||
return [b"Hello, World!"]
|
||||
return [b"Hello, WSGI!"]
|
||||
|
||||
|
||||
def test_uwsgi_hello_world(server_process):
|
||||
with server_process(wsgi_app):
|
||||
result = requests.get("http://127.0.0.1:8080/")
|
||||
with server_process(wsgi_app) as server:
|
||||
result = requests.get(server.endpoint)
|
||||
assert result.status_code == 200
|
||||
assert result.text == "Hello, World!"
|
||||
assert result.text == "Hello, WSGI!"
|
||||
|
||||
19
tests/test_valid_wsgi_server.py
Normal file
19
tests/test_valid_wsgi_server.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import requests
|
||||
|
||||
from wsgiref.validate import validator
|
||||
|
||||
|
||||
def simple_app(environ, start_response):
|
||||
status = '200 OK'
|
||||
headers = [('Content-type', 'text/plain')]
|
||||
start_response(status, headers)
|
||||
return [b"Valid"]
|
||||
|
||||
|
||||
validator_app = validator(simple_app)
|
||||
|
||||
|
||||
def test_get_valid_wsgi_server(server_process):
|
||||
with server_process(validator_app) as server:
|
||||
result = requests.get(server.endpoint)
|
||||
assert result.text == "Valid"
|
||||
Reference in New Issue
Block a user