-
Notifications
You must be signed in to change notification settings - Fork 692
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add integration test for static-expires-uri
- Loading branch information
Showing
4 changed files
with
101 additions
and
0 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/usr/bin/python3 | ||
|
||
|
||
import os | ||
import requests | ||
import signal | ||
import socket | ||
import subprocess | ||
import time | ||
import unittest | ||
|
||
|
||
TESTS_DIR = os.path.dirname(__file__) | ||
UWSGI_BINARY = os.getenv("UWSGI_BINARY", os.path.join(TESTS_DIR, "..", "uwsgi")) | ||
UWSGI_ADDR = "127.0.0.1" | ||
UWSGI_PORT = 8000 | ||
UWSGI_HTTP = f"{UWSGI_ADDR}:{UWSGI_PORT}" | ||
|
||
|
||
class BaseTest: | ||
""" | ||
Container class to avoid base test being run | ||
""" | ||
|
||
class UwsgiServerTest(unittest.TestCase): | ||
""" | ||
Test case with a server instance available on a socket for requests | ||
""" | ||
|
||
@classmethod | ||
def uwsgi_ready(cls): | ||
try: | ||
s = socket.socket() | ||
s.connect( | ||
( | ||
UWSGI_ADDR, | ||
UWSGI_PORT, | ||
) | ||
) | ||
except socket.error: | ||
return False | ||
else: | ||
return True | ||
finally: | ||
s.close() | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
# launch server | ||
cls.testserver = subprocess.Popen( | ||
[UWSGI_BINARY, "--http-socket", UWSGI_HTTP] + cls.ARGS | ||
) | ||
|
||
# ensure server is ready | ||
retries = 10 | ||
while not cls.uwsgi_ready() and retries > 0: | ||
time.sleep(0.1) | ||
retries = retries - 1 | ||
if retries == 0: | ||
raise RuntimeError("uwsgi test server is not available") | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
cls.testserver.send_signal(signal.SIGTERM) | ||
cls.testserver.wait() | ||
|
||
|
||
class StaticTest(BaseTest.UwsgiServerTest): | ||
|
||
ARGS = [ | ||
"--plugin", | ||
"python3", # provide a request plugin if no embedded request plugin | ||
os.path.join(TESTS_DIR, "static", "config.ini"), | ||
] | ||
|
||
def test_static_expires(self): | ||
with requests.get(f"http://{UWSGI_HTTP}/foobar/config.ini") as r: | ||
self.assertTrue("Expires" in r.headers) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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,4 @@ | ||
[uwsgi] | ||
need-app = False | ||
static-map = /foobar=t/static | ||
static-expires-uri = ^/foobar/ 315360000 |