Skip to main content

HTTP_TESTING

Description

This project aims to help to create e2e tests, by chaining http calls and verifications on target pages. IMPORTANT: Since only http calls involved, no javascript will run.

Concept

This project is built on pytest.

Each .py file in test represents several tests scenario on one target site, we can provide the site's hostname as a local variable, the framework know how to construct http call from that.

Each test function in the .py test file represent a scenario of test which is consisted by several steps. For example, test user's account page, first, we authenticate the client by post user's name and password, then access the account page to verify some values. Each step is described by calling the variable check which is a pytest fixture.

Tutorial

Install

pip install pytest-httptesting

Create test suite

# test/test_example.py

from http_testing.assertion_elements.cookies_assertion import Cookie
from http_testing.assertions import Assertions, NegativeAssertions
from http_testing.page_checker import PageChecker

host = "www.google.com"  # madatory: used in the `check` fixture
scheme = "https"  # "https" by default
port = None  # None by default


def test_scenario_one(check: PageChecker):
    check(
        title="Senario One",
        path="/",
        should_find=Assertions(
            status_code=200,
            content=["<title>Google</title>"],
            headers={"Content-Type": "text/html; charset=ISO-8859-1"},
            cookies=[Cookie(name="AEC", value_pattern=r".*")],
        ),
        should_not_find=NegativeAssertions(
            status_code=400,
            content=["groot"],
            headers={"nooooo": ""},
            cookies=[Cookie(name="nop", value_pattern="a")],
        ),
    )

Run test

$ pytest --tb=no test  # traceback is disabled because it is not very useful to anayse the functional error
============= test session starts =============
platform linux -- Python 3.8.10, pytest-7.2.0, pluggy-1.0.0
rootdir: /home/xxx/workspace/http_testing
plugins: anyio-3.6.2
collected 1 items

test/test_example.py .                                                                  [100%]

=============  1 passed in 0.22s =============

Debug

In case of error, a temporary file will be generated, as shown in the test summary info. It is a json file concluding response content, status code, headers and cookies.

$ pytest --tb=no test
============= test session starts =============
platform linux -- Python 3.8.10, pytest-7.2.0, pluggy-1.0.0
rootdir: /home/qile/workspace/http_testing
plugins: anyio-3.6.2
collected 1 item

test/test_example.py F                                                                  [100%]

============= short test summary info =============
FAILED test/test_example.py::test_scenario_one - AssertionError: Senario One - 'Content-Typesssssss':'text/html; charset=ISO-8859-1' not found in headers on page 'https://www.google.com/' - please check file '/tmp/tmpx7zb7h16'
============= 1 failed in 0.25s =============

Advanced

Customize the http client configuration

We can create a fixture http_client_config to override the default configuration, like adding headers and cookies to the http client.

@pytest.fixture
def http_client_config():
    return HttpClientConfiguration(
        trust_env=False,
        verify=False,
        cookies={"cookie_1": "cookie_value_1"},
        headers={"header_1": "header_value_1"},
    )

Metadata

Release files for pytest-httptesting 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-httptesting 0.1.2
File Size Uploaded Provenance Actions
pytest_httptesting-0.1.2.tar.gz 8.2 kB Without provenance Details for pytest_httptesting-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pytest-httptesting 0.1.2
File Interpreter ABI Platform Actions
pytest_httptesting-0.1.2-py3-none-any.whl Python 3 none any Details for pytest_httptesting-0.1.2-py3-none-any.whl

Total release size: 19.5 kB

Release files / pytest_httptesting-0.1.2.tar.gz

Download URL pytest_httptesting-0.1.2.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c8cd11745861ea6562c4c3e2cf0a0c032f17179e61a3fced0528605544268b1c
BLAKE2b-256 checksum
How to use checksums
f1362fa98388dd14f74ad0da1d6b72002d3b901155659f02f368df6f9a3d98de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.9.5 Linux/5.4.72-microsoft-standard-WSL2

Release files / pytest_httptesting-0.1.2-py3-none-any.whl

Download URL pytest_httptesting-0.1.2-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
82a38fa043fdda78b98e496f57227b5b43250b6896a61a4ff9e54077039c8307
BLAKE2b-256 checksum
How to use checksums
68e273a2b8e0e6879aa94f291e525357b5a62c58de3cd23ee2e25ff0eb73eed5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.9.5 Linux/5.4.72-microsoft-standard-WSL2

Security for pytest-httptesting 0.1.2

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page