File: conftest.py

package info (click to toggle)
python-web-poet 0.23.2-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 908 kB
  • sloc: python: 6,112; makefile: 19
file content (45 lines) | stat: -rw-r--r-- 991 bytes parent folder | download | duplicates (3)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from __future__ import annotations

from pathlib import Path

import pytest

from web_poet.page_inputs import HttpResponse, HttpResponseBody

pytest_plugins = ["pytester"]


def read_fixture(path: str) -> str:
    return (Path(__file__).parent / path).read_text(encoding="utf-8")


@pytest.fixture
def book_list_html():
    return read_fixture("fixtures/book_list.html")


@pytest.fixture
def some_json_response():
    body = """
    {
      "description": "paragraph",
      "website": {
        "url": "http://www.scrapy.org",
        "name": "homepage"
      },
      "logo": "/images/logo.png"
    }
    """
    return HttpResponse(
        url="http://books.toscrape.com/result.json",
        body=body.encode("utf-8"),
        encoding="utf-8",
    )


@pytest.fixture
def book_list_html_response(book_list_html):
    body = HttpResponseBody(bytes(book_list_html, "utf-8"))
    return HttpResponse(
        url="http://books.toscrape.com/index.html", body=body, encoding="utf-8"
    )