✅ add tests for server checks
This commit is contained in:
parent
ff8f50e44b
commit
557cd39c13
1 changed files with 27 additions and 2 deletions
|
@ -23,9 +23,13 @@ from spiderweb.tests.views_for_tests import (
|
||||||
form_csrf_exempt,
|
form_csrf_exempt,
|
||||||
form_view_without_csrf,
|
form_view_without_csrf,
|
||||||
text_view,
|
text_view,
|
||||||
unauthorized_view, file_view,
|
unauthorized_view,
|
||||||
|
file_view,
|
||||||
|
)
|
||||||
|
from spiderweb.middleware.gzip import (
|
||||||
|
CheckValidGzipMinimumLength,
|
||||||
|
CheckValidGzipCompressionLevel,
|
||||||
)
|
)
|
||||||
from spiderweb.middleware.gzip import GzipMiddleware, CheckValidGzipMinimumLength, CheckValidGzipCompressionLevel
|
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
|
@ -410,6 +414,27 @@ class TestGzipMiddleware:
|
||||||
assert app(environ, start_response) == [bytes("hi", DEFAULT_ENCODING)]
|
assert app(environ, start_response) == [bytes("hi", DEFAULT_ENCODING)]
|
||||||
assert "content-encoding" not in start_response.get_headers()
|
assert "content-encoding" not in start_response.get_headers()
|
||||||
|
|
||||||
|
def test_invalid_response_length(self):
|
||||||
|
class FakeServer:
|
||||||
|
gzip_minimum_response_length = "asdf"
|
||||||
|
with pytest.raises(ConfigError) as e:
|
||||||
|
CheckValidGzipMinimumLength(server=FakeServer).check()
|
||||||
|
assert e.value.args[0] == CheckValidGzipMinimumLength.INVALID_GZIP_MINIMUM_LENGTH
|
||||||
|
|
||||||
|
def test_negative_response_length(self):
|
||||||
|
class FakeServer:
|
||||||
|
gzip_minimum_response_length = -1
|
||||||
|
with pytest.raises(ConfigError) as e:
|
||||||
|
CheckValidGzipMinimumLength(server=FakeServer).check()
|
||||||
|
assert e.value.args[0] == CheckValidGzipMinimumLength.INVALID_GZIP_MINIMUM_LENGTH
|
||||||
|
|
||||||
|
def test_bad_compression_level(self):
|
||||||
|
class FakeServer:
|
||||||
|
gzip_compression_level = "asdf"
|
||||||
|
with pytest.raises(ConfigError) as e:
|
||||||
|
CheckValidGzipCompressionLevel(server=FakeServer).check()
|
||||||
|
assert e.value.args[0] == CheckValidGzipCompressionLevel.INVALID_GZIP_COMPRESSION_LEVEL
|
||||||
|
|
||||||
|
|
||||||
class TestCorsMiddleware:
|
class TestCorsMiddleware:
|
||||||
# adapted from:
|
# adapted from:
|
||||||
|
|
Loading…
Add table
Reference in a new issue