tests: add base tests
This commit is contained in:
parent
4c534de47b
commit
9893d36be3
23 changed files with 353 additions and 206 deletions
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
56
tests/conftest.py
Normal file
56
tests/conftest.py
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from caribou.migrate import Database as CaribouDatabase
|
||||
from caribou.migrate import load_migrations
|
||||
|
||||
from src.huesoporro.infra.db import Database
|
||||
from src.huesoporro.models import ChatbotSettings, TwitchAuth, User
|
||||
from src.huesoporro.settings import Settings
|
||||
from src.huesoporro.svc.is_mod import IsModSvc
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user() -> User:
|
||||
return User(
|
||||
user="huesoporro",
|
||||
expires_at=1671234567.0,
|
||||
twitch_auth=TwitchAuth(
|
||||
access_token="test_access_token", refresh_token="test_refresh_token"
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def s(tmp_path: Path, user: User) -> Settings:
|
||||
return Settings(
|
||||
static_files_path=tmp_path / "static_files",
|
||||
db_filepath=tmp_path / "huesoporro.db",
|
||||
twitch_client_id="test_client_id",
|
||||
twitch_client_secret="test_client_secret", # type: ignore[arg-type]
|
||||
jwt_secret="test_jwt_secret", # type: ignore[arg-type]
|
||||
allowed_users=[user.user],
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def db(s) -> Database:
|
||||
cdb = CaribouDatabase(
|
||||
db_url=s.db_filepath,
|
||||
)
|
||||
cdb.initialize_version_control()
|
||||
migrations = load_migrations(Path(__file__).parents[1] / "migrations")
|
||||
cdb.upgrade(migrations)
|
||||
return Database(s=s)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def is_mod_svc(db) -> IsModSvc:
|
||||
return IsModSvc(db=db)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def chatbot_settings(db: Database, user) -> ChatbotSettings:
|
||||
cbs = ChatbotSettings(mods=[user.user, "allowed_user"])
|
||||
await db.save_chatbot_settings(user=user, chatbot_settings=cbs)
|
||||
return cbs
|
||||
35
tests/test_svc.py
Normal file
35
tests/test_svc.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import pytest
|
||||
|
||||
from src.huesoporro.models import ChatbotSettings, User
|
||||
from src.huesoporro.svc.is_mod import IsModSvc
|
||||
|
||||
|
||||
async def test_is_mod_svc_returns_true_for_channel(is_mod_svc: IsModSvc, user: User):
|
||||
is_mod = await is_mod_svc.run(user=user, username="TestUser", channel="TestUser")
|
||||
assert is_mod
|
||||
|
||||
|
||||
async def test_is_mod_svc_returns_true_for_user_in_modlist(
|
||||
is_mod_svc: IsModSvc,
|
||||
user: User,
|
||||
chatbot_settings: ChatbotSettings,
|
||||
):
|
||||
is_mod = await is_mod_svc.run(
|
||||
user=user, username=chatbot_settings.mods[1], channel=user.user
|
||||
)
|
||||
assert is_mod
|
||||
|
||||
|
||||
async def test_is_mod_svc_returns_false_for_settingless_user(
|
||||
is_mod_svc: IsModSvc, user: User
|
||||
):
|
||||
is_mod = await is_mod_svc.run(user=user, username="TestUser", channel="TestUser2")
|
||||
assert not is_mod
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("chatbot_settings")
|
||||
async def test_is_mod_svc_returns_false_for_user_not_in_modlist(
|
||||
is_mod_svc: IsModSvc, user: User
|
||||
):
|
||||
is_mod = await is_mod_svc.run(user=user, username="TestUser2", channel=user.user)
|
||||
assert not is_mod
|
||||
Loading…
Add table
Add a link
Reference in a new issue