SHA256
forked from course-team/tjhlp-gitea
82 lines
2.2 KiB
Python
82 lines
2.2 KiB
Python
"""测试公共 fixtures"""
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
import pytest
|
|
from pydantic import HttpUrl, SecretStr
|
|
|
|
from tjhlp.config import GiteaConfig, LabelDef, SmtpConfig
|
|
from tjhlp.models import CredentialRecord, MemberRecord, MemberRole
|
|
|
|
|
|
@pytest.fixture()
|
|
def sample_labels() -> list[LabelDef]:
|
|
return [
|
|
LabelDef(name="duplicate", color="#cfd3d7", description="重复问题"),
|
|
LabelDef(name="resolved", color="#0e8a16", description="已解决"),
|
|
]
|
|
|
|
|
|
@pytest.fixture()
|
|
def gitea_config(sample_labels: list[LabelDef]) -> GiteaConfig:
|
|
return GiteaConfig(
|
|
url=HttpUrl("http://localhost:3000"),
|
|
token=SecretStr("test-token-12345"),
|
|
email_domain="tongji.edu.cn",
|
|
default_org="tjhlp-test",
|
|
password_length=12,
|
|
labels=sample_labels,
|
|
)
|
|
|
|
|
|
@pytest.fixture()
|
|
def smtp_config() -> SmtpConfig:
|
|
return SmtpConfig(
|
|
host="smtp.test.com",
|
|
port=465,
|
|
user="[email protected]",
|
|
password=SecretStr("smtp-pass"),
|
|
from_addr="Test <[email protected]>",
|
|
)
|
|
|
|
|
|
@pytest.fixture()
|
|
def sample_members() -> list[MemberRecord]:
|
|
return [
|
|
MemberRecord(id="2659999", name="赵一伤", role=MemberRole.STUDENT),
|
|
MemberRecord(id="2659876", name="钱二败", role=MemberRole.STUDENT),
|
|
MemberRecord(id="10001", name="李四催", role=MemberRole.TA),
|
|
]
|
|
|
|
|
|
@pytest.fixture()
|
|
def sample_credentials() -> list[CredentialRecord]:
|
|
return [
|
|
CredentialRecord(
|
|
id="2659999",
|
|
name="赵一伤",
|
|
role=MemberRole.STUDENT,
|
|
username="2659999",
|
|
password="xK9#mP2$vL4w",
|
|
email="[email protected]",
|
|
),
|
|
CredentialRecord(
|
|
id="10001",
|
|
name="李四催",
|
|
role=MemberRole.TA,
|
|
username="10001",
|
|
password="aB3$cD5&eF7h",
|
|
email="[email protected]",
|
|
),
|
|
]
|
|
|
|
|
|
@pytest.fixture()
|
|
def mock_gitea_client() -> MagicMock:
|
|
"""创建一个 mock GiteaClient, 可在各命令测试中复用"""
|
|
client = MagicMock()
|
|
client.__enter__ = MagicMock(return_value=client)
|
|
client.__exit__ = MagicMock(return_value=False)
|
|
client.get_version.return_value = "1.25.5"
|
|
return client
|