Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add 'notes' to Request #97

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions tests/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,17 @@ def test_probability_request():
metadata=ProbabilityMetadata(probability=0.5),
)
assert request.get_probability() == 0.5
assert request.notes is None

request = ProbabilityRequest(
name="Get with RequestURL object",
url=RequestUrl("https://example.com/test"),
notes={"type": "test request", "id": 782},
)

assert request.url == "https://example.com/test"
assert request.get_probability() is None
assert request.notes == {"type": "test request", "id": 782}


def test_request():
Expand All @@ -154,20 +157,22 @@ def test_request():
Header(name="Content-Type", value="application/x-www-form-urlencoded"),
Header(name="Host", value="foo.example"),
]
Request(
request = Request(
name="Post Test",
url="https://example.com/test",
method="POST",
body="ZmllbGQxPXZhbHVlMSZmaWVsZDI9dmFsdWUy",
headers=headers,
)
assert request.notes is None

request = Request(
name="Get with RequestURL object",
url=RequestUrl("https://example.com/test"),
notes={"type": "test request", "id": 782},
)

assert request.url == "https://example.com/test"
assert request.notes == {"type": "test request", "id": 782}


def test_job_location():
Expand Down
5 changes: 4 additions & 1 deletion zyte_common_items/components/request.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import base64
from typing import List, Optional, Type, TypeVar
from typing import Any, Dict, List, Optional, Type, TypeVar

import attrs

Expand Down Expand Up @@ -42,6 +42,9 @@ class Request(Item):
#: Name of the page being requested.
name: Optional[str] = None

#: Arbitrary list of information about the request.
notes: Optional[Dict[str, Any]] = None

_body_bytes = None

@property
Expand Down