test: reorganized unit/integration tests (#398)

This commit is contained in:
1cu
2025-02-03 17:05:14 +01:00
committed by GitHub
parent 100f2fd8c5
commit 76b0901166
9 changed files with 260 additions and 30 deletions

View File

@@ -1,14 +0,0 @@
"""
SPDX-FileCopyrightText: © Sebastian Thomschke and contributors
SPDX-License-Identifier: AGPL-3.0-or-later
SPDX-ArtifactOfProjectHomePage: https://github.com/Second-Hand-Friends/kleinanzeigen-bot/
"""
import logging
from typing import Final
from kleinanzeigen_bot import utils
utils.configure_console_logging()
LOG:Final[logging.Logger] = logging.getLogger("kleinanzeigen_bot")
LOG.setLevel(logging.DEBUG)

63
tests/conftest.py Normal file
View File

@@ -0,0 +1,63 @@
"""
SPDX-FileCopyrightText: © Sebastian Thomschke and contributors
SPDX-License-Identifier: AGPL-3.0-or-later
SPDX-ArtifactOfProjectHomePage: https://github.com/Second-Hand-Friends/kleinanzeigen-bot/
"""
import logging
from typing import Any, Final
import pytest
from kleinanzeigen_bot import utils
from kleinanzeigen_bot.i18n import get_translating_logger
utils.configure_console_logging()
LOG:Final[logging.Logger] = get_translating_logger("kleinanzeigen_bot")
LOG.setLevel(logging.DEBUG)
@pytest.fixture
def sample_config() -> dict[str, Any]:
return {
"login": {
"username": "test_user",
"password": "test_password"
},
"browser": {
"arguments": [],
"binary_location": None,
"extensions": [],
"use_private_window": True,
"user_data_dir": None,
"profile_name": None
},
"ad_defaults": {
"description": {
"prefix": "",
"suffix": ""
}
},
"ad_files": ["ads/*.yaml"]
}
@pytest.fixture
def sample_ad_config() -> dict[str, Any]:
return {
"title": "Test Item",
"description": "Test Description",
"price": "100",
"price_type": "FIXED",
"shipping_type": "PICKUP",
"active": True,
"contact": {
"name": "Test User",
"zipcode": "12345"
},
"images": [],
"id": None,
"created_on": None,
"updated_on": None,
"republication_interval": 30
}

33
tests/unit/test_bot.py Normal file
View File

@@ -0,0 +1,33 @@
"""
SPDX-FileCopyrightText: © Sebastian Thomschke and contributors
SPDX-License-Identifier: AGPL-3.0-or-later
SPDX-ArtifactOfProjectHomePage: https://github.com/Second-Hand-Friends/kleinanzeigen-bot/
"""
import pytest
from kleinanzeigen_bot import KleinanzeigenBot
class TestKleinanzeigenBot:
@pytest.fixture
def bot(self) -> KleinanzeigenBot:
return KleinanzeigenBot()
def test_parse_args_help(self, bot: KleinanzeigenBot) -> None:
"""Test parsing of help command"""
bot.parse_args(["app", "help"])
assert bot.command == "help"
assert bot.ads_selector == "due"
assert not bot.keep_old_ads
def test_parse_args_publish(self, bot: KleinanzeigenBot) -> None:
"""Test parsing of publish command with options"""
bot.parse_args(["app", "publish", "--ads=all", "--keep-old"])
assert bot.command == "publish"
assert bot.ads_selector == "all"
assert bot.keep_old_ads
def test_get_version(self, bot: KleinanzeigenBot) -> None:
"""Test version retrieval"""
version = bot.get_version()
assert isinstance(version, str)
assert len(version) > 0