roughly working again, now dev docker exists
This commit is contained in:
parent
a77a0c0393
commit
155ab39368
26 changed files with 1976 additions and 235 deletions
|
|
@ -5,7 +5,12 @@ from handlers.degewo_handler import DegewoHandler
|
|||
from handlers.gesobau_handler import GesobauHandler
|
||||
from handlers.stadtundland_handler import StadtUndLandHandler
|
||||
from handlers.wbm_handler import WBMHandler
|
||||
from unittest.mock import AsyncMock
|
||||
from handlers.base_handler import BaseHandler
|
||||
from unittest.mock import AsyncMock, MagicMock
|
||||
|
||||
class MockBaseHandler(BaseHandler):
|
||||
async def apply(self, listing: dict, result: dict) -> dict:
|
||||
return result
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_howoge_handler():
|
||||
|
|
@ -59,4 +64,76 @@ async def test_wbm_handler():
|
|||
listing = {"link": "https://www.wbm.de/example"}
|
||||
result = {"success": False}
|
||||
await handler.apply(listing, result)
|
||||
assert "success" in result
|
||||
assert "success" in result
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_handle_cookies():
|
||||
"""Test the handle_cookies method in BaseHandler."""
|
||||
context = AsyncMock()
|
||||
handler = MockBaseHandler(context)
|
||||
mock_page = AsyncMock()
|
||||
mock_cookie_btn = AsyncMock()
|
||||
mock_cookie_btn.is_visible = AsyncMock(return_value=True)
|
||||
mock_cookie_btn.click = AsyncMock()
|
||||
mock_page.query_selector = AsyncMock(return_value=mock_cookie_btn)
|
||||
|
||||
await handler.handle_cookies(mock_page)
|
||||
mock_cookie_btn.click.assert_called_once()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_handle_consent():
|
||||
"""Test the handle_consent method in BaseHandler."""
|
||||
context = AsyncMock()
|
||||
handler = MockBaseHandler(context)
|
||||
mock_page = AsyncMock()
|
||||
mock_consent_btn = AsyncMock()
|
||||
mock_consent_btn.is_visible = AsyncMock(return_value=True)
|
||||
mock_consent_btn.click = AsyncMock()
|
||||
mock_page.query_selector = AsyncMock(return_value=mock_consent_btn)
|
||||
|
||||
await handler.handle_consent(mock_page)
|
||||
mock_consent_btn.click.assert_called_once()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_login():
|
||||
"""Test the login method in BaseHandler."""
|
||||
context = AsyncMock()
|
||||
handler = MockBaseHandler(context, email="test@example.com", password="password123")
|
||||
mock_page = AsyncMock()
|
||||
|
||||
# Mock the page interactions
|
||||
mock_page.goto = AsyncMock()
|
||||
mock_page.fill = AsyncMock()
|
||||
mock_page.click = AsyncMock()
|
||||
mock_page.wait_for_load_state = AsyncMock()
|
||||
mock_page.url = "https://www.inberlinwohnen.de/mein-bereich"
|
||||
mock_page.query_selector = AsyncMock(return_value=AsyncMock(is_visible=AsyncMock(return_value=True)))
|
||||
|
||||
result = await handler.login(mock_page)
|
||||
|
||||
# Assertions
|
||||
mock_page.goto.assert_called_once_with("https://www.inberlinwohnen.de/login", wait_until="networkidle")
|
||||
mock_page.fill.assert_any_call('input[name="email"], input[type="email"]', "test@example.com")
|
||||
mock_page.fill.assert_any_call('input[name="password"], input[type="password"]', "password123")
|
||||
mock_page.click.assert_called_once_with('button[type="submit"], input[type="submit"]')
|
||||
mock_page.wait_for_load_state.assert_called_once_with("networkidle")
|
||||
assert result is True
|
||||
|
||||
# Test for fetch_listings method in BaseHandler
|
||||
@pytest.mark.asyncio
|
||||
async def test_fetch_listings():
|
||||
context = AsyncMock()
|
||||
handler = MockBaseHandler(context)
|
||||
|
||||
# Mock the fetch_listings method
|
||||
handler.fetch_listings = AsyncMock(return_value=[
|
||||
{"id": "1", "title": "Listing 1", "price": 1000},
|
||||
{"id": "2", "title": "Listing 2", "price": 1200}
|
||||
])
|
||||
|
||||
listings = await handler.fetch_listings()
|
||||
|
||||
# Assertions
|
||||
assert len(listings) == 2
|
||||
assert listings[0]["id"] == "1"
|
||||
assert listings[1]["title"] == "Listing 2"
|
||||
Loading…
Add table
Add a link
Reference in a new issue