Skip to content

Commit

Permalink
feat: refactored test_crawler with fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
indrajithi committed Aug 5, 2024
1 parent a04323f commit d3d6e88
Show file tree
Hide file tree
Showing 4 changed files with 312 additions and 285 deletions.
27 changes: 26 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ lxml = "^5.2.2"
colorama = "^0.4.6"
requests = "^2.32.3"
aiohttp = "^3.10.0"
types-requests = "^2.32.0.20240712"
types-setuptools = "^71.1.0.20240726"

[tool.poetry.group.dev.dependencies]
responses = "^0.13.4"
Expand Down
31 changes: 31 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# conftest.py
from typing import Callable, Generator
from unittest.mock import MagicMock, patch

import pytest

from tests.utils import setup_mock_response

root_url = "http://example.com"


@pytest.fixture
def mock_urlopen() -> Generator[MagicMock, None, None]:
with patch("urllib.request.urlopen") as mock:
yield mock


@pytest.fixture
def mock_response() -> MagicMock:
response = MagicMock()
response.read.return_value = b""
response.status = 200
return response


@pytest.fixture
def setup_responses() -> Callable[[str, str, int], None]:
def _setup_responses(url: str, body: str, status: int = 200) -> None:
setup_mock_response(url=url, body=body, status=status)

return _setup_responses
Loading

0 comments on commit d3d6e88

Please sign in to comment.