cache-unit-test
Unit test Python library for testing cache systems like varnish
Based on the work of @onyxfish (https://gist.github.com/onyxfish)
- cachetest.py : productive
- wordpresscachetest.py : not usable yet
user@localhost> python3.3 exampletest
Python test launcher
With the unittest python system, you may have a unittest launcher, and many tests on different folders
#!/usr/bin/env python
import sys, getopt
import json
import re
import random
import unittest
import argparse
import cacheunittest
from cacheunittest import CacheUnitTest
import unittest
import os
import sys
if __name__ == "__main__":
os.environ['MOZ_HEADLESS'] = '1'
argparse=argparse.ArgumentParser(description="Proxy directives tests app", add_help=True)
argparse.add_argument("--host", default="127.0.0.1", help="define a target varnish host")
argparse.add_argument("--httpport", type=int, default=80, help="override the default http port 80")
argparse.add_argument("--httpsport", type=int, default=443, help="override the default https port 443")
argparse.add_argument("--verbosity", type=int, default=2, help="verbosity level")
argparse.add_argument("-p", "--path", default=".", help="code path")
args = argparse.parse_args()
verbosity = args.verbosity
codePath = args.path
cacheunittest.proxyhost = args.host
cacheunittest.proxyhttpport = args.httpport
cacheunittest.proxyhttpsport = args.httpsport
print("")
print("")
print("Discovering ", codePath, " for artetest*.py tests")
print("")
tests = unittest.TestSuite()
loader = unittest.TestLoader()
tests_auto = loader.discover(codePath, pattern="artetest*.py", top_level_dir=None)
result = unittest.TextTestRunner(verbosity=verbosity).run(tests_auto)
print(result)
if result.wasSuccessful():
print("")
print("")
print("")
print("")
print(" All tests were successfully passed")
print(" GGGGGOOOOOOOODDDDDD JOB !!!!")
print("")
print("")
print("")
print("")
sys.exit(0)
else:
print("")
print(" OOps something wrong happened")
print("")
print("###########################")
print("###########################")
print("###########################")
print("# KEEP THE FAITH! #")
print("###########################")
print("###########################")
print("###########################")
sys.exit(2)
cache unit test
Varnish configuration
The tests are only valid if the varnish configuration contains the following setup Based on:
- https://www.varnish-software.com/wiki/content/tutorials/varnish/sample_vclTemplate.html
- https://docs.varnish-software.com/tutorials/hit-miss-logging/
- https://www.varnish-software.com/wiki/content/tutorials/varnish/multiple_varnishes.html
- https://varnish-cache.org/docs/trunk/users-guide/purging.html
It's probably a good idea to put some security around it via a test on client.ip for example
Example VCL (docs/example.vcl):
acl dev {
# ACL we'll use later to allow purges
"localhost";
"127.0.0.1";
"::1";
}
sub vcl_recv {
# To avoid any hack based on these headers
unset req.http.x-cache;
unset req.http.X-Back;
if (req.url ~ "^/static/") {
set req.http.X-Back = "STATIC";
} else {
set req.http.X-Back = "WORDPRESS";
}
if (req.method == "PURGE") {
if (!client.ip ~ dev) {
return(synth(405,"Not allowed."));
}
return (purge);
}
}
sub vcl_hit {
set req.http.x-cache = "HIT";
if (obj.ttl <= 0 and obj.grace > 0s) {
set req.http.x-cache = "HIT_GRACED";
}
}
sub vcl_miss {
set req.http.x-cache = "MISS";
}
sub vcl_pass {
set req.http.x-cache = "PASS";
}
sub vcl_pipe {
set req.http.x-cache = "PIPE";
}
sub vcl_synth {
if (!client.ip ~ dev) {
set resp.http.X-Back = "VARNISH";
set resp.http.x-cache = "SYNTH";
}
}
sub vcl_deliver {
if (!client.ip ~ dev) {
if (obj.hits > 0) {
set resp.http.X-NumberOfHits = obj.hits;
}
set resp.http.X-Varnish-Server = server.identity;
set resp.http.X-Back = req.http.X-Back;
set resp.http.X-Cache = req.http.X-Cache;
}
}
Metadata
Release files for cacheunittest 1.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cacheunittest-1.3.0.tar.gz | 5.9 kB | Without provenance | Details for cacheunittest-1.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cacheunittest-1.3.0-py3-none-any.whl | Python 3 | none | any | Details for cacheunittest-1.3.0-py3-none-any.whl |
Total release size: 11.8 kB
Release files / cacheunittest-1.3.0.tar.gz
| Download URL | cacheunittest-1.3.0.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
762ee979b1ec7a77bff900a8031d6c03b4a91c3556f5fca1abac6a21ad85d141
|
|
BLAKE2b-256 checksum How to use checksums |
fbf813fe56998d335b4737d14ffce17dc14b33ccdd6e1fccd894d9e48b15638c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.7
|
Release files / cacheunittest-1.3.0-py3-none-any.whl
| Download URL | cacheunittest-1.3.0-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5490147ad9c659b0cde3d178df701d4f7761ff43efe4bf0408a10871e08ad462
|
|
BLAKE2b-256 checksum How to use checksums |
3df73503fb532d7ed1b5ae183cd38c6c9ede4f2f992073dd22f351f7d5d90270
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.7
|
Security for cacheunittest 1.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.