Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions tests/support/wsgisupp.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
#
# --- BEGIN_HEADER ---
#
# wsgisupp - test support library for WSGI
# Copyright (C) 2003-2025 The MiG Project by the Science HPC Center at UCPH
# Copyright (C) 2003-2026 The MiG Project by the Science HPC Center at UCPH
#
# This file is part of MiG.
#
Expand All @@ -19,7 +19,8 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#
# -- END_HEADER ---
#
Expand All @@ -29,15 +30,9 @@
from collections import namedtuple
import codecs
from io import BytesIO
from werkzeug.datastructures import MultiDict

from tests.support._env import PY2
from urllib.parse import urlencode, urlparse

if PY2:
from urllib import urlencode
from urlparse import urlparse
else:
from urllib.parse import urlencode, urlparse
from werkzeug.datastructures import MultiDict


# named type representing the tuple that is passed to WSGI handlers
Expand All @@ -49,14 +44,14 @@
in the WSGI specs but records the calls to it such that they can be
inspected and, for our purposes, asserted against."""

def __init__(self):

Check warning on line 47 in tests/support/wsgisupp.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

Missing docstring in __init__

Check warning on line 47 in tests/support/wsgisupp.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

Missing docstring in __init__
self.calls = []

def __call__(self, status, headers, exc=None):

Check warning on line 50 in tests/support/wsgisupp.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

Missing docstring in public method

Check warning on line 50 in tests/support/wsgisupp.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

Missing docstring in public method
self.calls.append((status, headers, exc))


def create_wsgi_environ(configuration, wsgi_url, method='GET', query=None, headers=None, form=None):

Check warning on line 54 in tests/support/wsgisupp.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (100 > 80 characters)

Check warning on line 54 in tests/support/wsgisupp.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (100 > 80 characters)
"""Populate the necessary variables that will constitute a valid WSGI
environment given a URL to which we will make a requests under test and
various other options that set up the nature of that request."""
Expand All @@ -75,7 +70,7 @@
body = urlencode(MultiDict(form)).encode('ascii')

headers = headers or {}
if not 'Content-Type' in headers:

Check warning on line 73 in tests/support/wsgisupp.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

test for membership should be 'not in'

Check warning on line 73 in tests/support/wsgisupp.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

test for membership should be 'not in'
headers['Content-Type'] = 'application/x-www-form-urlencoded'

headers['Content-Length'] = str(len(body))
Expand All @@ -85,7 +80,10 @@
wsgi_input = ()

class _errors:
def close():
"""Internal helper to ignore wsgi.errors close method calls"""

def close(self, *ars, **kwargs):

Check failure on line 85 in tests/support/wsgisupp.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused variable 'ars' (100% confidence)

Check failure on line 85 in tests/support/wsgisupp.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused method 'close' (60% confidence)

Check failure on line 85 in tests/support/wsgisupp.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused variable 'ars' (100% confidence)

Check failure on line 85 in tests/support/wsgisupp.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused method 'close' (60% confidence)
""""Simply ignore"""

Check warning on line 86 in tests/support/wsgisupp.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

Use """triple double quotes""" (found """"-quotes)

Check warning on line 86 in tests/support/wsgisupp.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

Use """triple double quotes""" (found """"-quotes)
pass

environ = {}
Expand Down Expand Up @@ -114,11 +112,11 @@
return environ


def create_wsgi_start_response():

Check warning on line 115 in tests/support/wsgisupp.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

Missing docstring in public function

Check warning on line 115 in tests/support/wsgisupp.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

Missing docstring in public function
return FakeWsgiStartResponse()


def prepare_wsgi(configuration, url, **kwargs):

Check warning on line 119 in tests/support/wsgisupp.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

Missing docstring in public function

Check failure on line 119 in tests/support/wsgisupp.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused function 'prepare_wsgi' (60% confidence)

Check warning on line 119 in tests/support/wsgisupp.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

Missing docstring in public function

Check failure on line 119 in tests/support/wsgisupp.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused function 'prepare_wsgi' (60% confidence)
return _PreparedWsgi(
create_wsgi_environ(configuration, url, **kwargs),
create_wsgi_start_response()
Expand All @@ -133,10 +131,10 @@
return decoded_value


class WsgiAssertMixin:

Check failure on line 134 in tests/support/wsgisupp.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused class 'WsgiAssertMixin' (60% confidence)

Check failure on line 134 in tests/support/wsgisupp.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused class 'WsgiAssertMixin' (60% confidence)
"""Custom assertions for verifying server code executed under test."""

def assertWsgiResponse(self, wsgi_result, fake_wsgi, expected_status_code):

Check warning on line 137 in tests/support/wsgisupp.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

Missing docstring in public method

Check failure on line 137 in tests/support/wsgisupp.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused method 'assertWsgiResponse' (60% confidence)

Check warning on line 137 in tests/support/wsgisupp.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

Missing docstring in public method

Check failure on line 137 in tests/support/wsgisupp.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused method 'assertWsgiResponse' (60% confidence)
assert isinstance(fake_wsgi, _PreparedWsgi)

content = _trigger_and_unpack_result(wsgi_result)
Expand Down
Loading