Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/testing/mozbase/mozhttpd/tests/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 3 kB image not shown  

SSL paths.py   Interaktion und
PortierbarkeitPython

 
#!/usr/bin/env python

# Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/

from urllib.error import HTTPError
from urllib.request import urlopen

import mozhttpd
import mozunit
import pytest


def try_get(url, expected_contents):
    f = urlopen(url)
    assert f.getcode() == 200
    assert f.read() == expected_contents


def try_get_expect_404(url):
    with pytest.raises(HTTPError) as excinfo:
        urlopen(url)
    assert excinfo.value.code == 404


@pytest.fixture(name="httpd_basic")
def fixture_httpd_basic(tmpdir):
    d1 = tmpdir.mkdir("d1")
    d1.join("test1.txt").write("test 1 contents")

    d2 = tmpdir.mkdir("d2")
    d2.join("test2.txt").write("test 2 contents")

    httpd = mozhttpd.MozHttpd(
        port=0,
        docroot=str(d1),
        path_mappings={"/files": str(d2)},
    )
    httpd.start(block=False)

    yield httpd

    httpd.stop()
    d1.remove()
    d2.remove()


def test_basic(httpd_basic):
    """Test that requests to docroot and a path mapping work as expected."""
    try_get(httpd_basic.get_url("/test1.txt"), b"test 1 contents")
    try_get(httpd_basic.get_url("/files/test2.txt"), b"test 2 contents")
    try_get_expect_404(httpd_basic.get_url("/files/test2_nope.txt"))


@pytest.fixture(name="httpd_substring_mappings")
def fixture_httpd_substring_mappings(tmpdir):
    d1 = tmpdir.mkdir("d1")
    d1.join("test1.txt").write("test 1 contents")

    d2 = tmpdir.mkdir("d2")
    d2.join("test2.txt").write("test 2 contents")

    httpd = mozhttpd.MozHttpd(
        port=0,
        path_mappings={"/abcxyz": str(d1), "/abc": str(d2)},
    )
    httpd.start(block=False)
    yield httpd
    httpd.stop()
    d1.remove()
    d2.remove()


def test_substring_mappings(httpd_substring_mappings):
    httpd = httpd_substring_mappings
    try_get(httpd.get_url("/abcxyz/test1.txt"), b"test 1 contents")
    try_get(httpd.get_url("/abc/test2.txt"), b"test 2 contents")


@pytest.fixture(name="httpd_multipart_path_mapping")
def fixture_httpd_multipart_path_mapping(tmpdir):
    d1 = tmpdir.mkdir("d1")
    d1.join("test1.txt").write("test 1 contents")

    httpd = mozhttpd.MozHttpd(
        port=0,
        path_mappings={"/abc/def/ghi": str(d1)},
    )
    httpd.start(block=False)
    yield httpd
    httpd.stop()
    d1.remove()


def test_multipart_path_mapping(httpd_multipart_path_mapping):
    """Test that a path mapping with multiple directories works."""
    httpd = httpd_multipart_path_mapping
    try_get(httpd.get_url("/abc/def/ghi/test1.txt"), b"test 1 contents")
    try_get_expect_404(httpd.get_url("/abc/test1.txt"))
    try_get_expect_404(httpd.get_url("/abc/def/test1.txt"))


@pytest.fixture(name="httpd_no_docroot")
def fixture_httpd_no_docroot(tmpdir):
    d1 = tmpdir.mkdir("d1")
    httpd = mozhttpd.MozHttpd(
        port=0,
        path_mappings={"/foo": str(d1)},
    )
    httpd.start(block=False)
    yield httpd
    httpd.stop()
    d1.remove()


def test_no_docroot(httpd_no_docroot):
    """Test that path mappings with no docroot work."""
    try_get_expect_404(httpd_no_docroot.get_url())


if __name__ == "__main__":
    mozunit.main()

100%


¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.19Angebot  Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können  ¤

*Eine klare Vorstellung vom Zielzustand






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung ist noch experimentell.