File: test_example_httpx.py

package info (click to toggle)
pytest-check 2.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 432 kB
  • sloc: python: 1,775; sh: 17; makefile: 6
file content (31 lines) | stat: -rw-r--r-- 772 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""
This example is used in the README.md
To run this example, first `pip install httpx`

This example is NOT tested by the test suite.
"""
import httpx

from pytest_check import check


def test_httpx_get():
    r = httpx.get("https://www.example.org/")
    # bail if bad status code
    assert r.status_code == 200
    # but if we get here
    # no need to stop on any failure
    with check:
        assert r.is_redirect is False
    with check:
        assert r.encoding == "utf-8"
    with check:
        assert "Example Domain" in r.text


def test_httpx_get_with_helpers():
    r = httpx.get("https://www.example.org/")
    assert r.status_code == 200
    check.is_false(r.is_redirect)
    check.equal(r.encoding, "utf-8")
    check.is_in("Example Domain", r.text)