Core modules: - Laws: CRUD, search, AI-powered QA - Analysis: legal research and case management - Contracts: lifecycle management with templates - Signatures: electronic signature workflow Infrastructure: - FastAPI + SQLite + async SQLAlchemy - Docker deployment support - 54 unit tests passing Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
89 lines
2.9 KiB
Python
89 lines
2.9 KiB
Python
"""Unit tests for Signature service."""
|
|
import pytest
|
|
from datetime import datetime, timedelta
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.models.signature import SignatureStatus
|
|
from app.models.contract import Contract
|
|
from app.services.signature_service import SignatureService
|
|
from app.services.contract_service import ContractService
|
|
|
|
|
|
class TestSignatureService:
|
|
"""Test cases for Signature service."""
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_generate_token(self, db_session: AsyncSession):
|
|
"""Test token generation."""
|
|
service = SignatureService(db_session)
|
|
|
|
token = service.generate_token()
|
|
|
|
assert token is not None
|
|
assert len(token) > 20
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_generate_verification_hash(self, db_session: AsyncSession):
|
|
"""Test verification hash generation."""
|
|
service = SignatureService(db_session)
|
|
|
|
hash1 = service.generate_verification_hash("test content")
|
|
hash2 = service.generate_verification_hash("test content")
|
|
hash3 = service.generate_verification_hash("different content")
|
|
|
|
assert hash1 == hash2
|
|
assert hash1 != hash3
|
|
assert len(hash1) == 64 # SHA-256 hex length
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_create_signature_request(self, db_session: AsyncSession):
|
|
"""Test creating a signature request."""
|
|
# First create a contract
|
|
contract_service = ContractService(db_session)
|
|
contract = await contract_service.create_contract(
|
|
title="测试合同",
|
|
party_a="甲方",
|
|
party_b="乙方",
|
|
content="合同内容",
|
|
created_by=1,
|
|
)
|
|
|
|
service = SignatureService(db_session)
|
|
request = await service.create_signature_request(
|
|
contract_id=contract.id,
|
|
requester_id=1,
|
|
signer_name="张三",
|
|
signer_email="zhangsan@example.com",
|
|
)
|
|
|
|
assert request.id is not None
|
|
assert request.signer_name == "张三"
|
|
assert request.status == SignatureStatus.PENDING
|
|
assert request.token is not None
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_is_request_valid(self, db_session: AsyncSession):
|
|
"""Test checking if request is valid."""
|
|
# Create a contract first
|
|
contract_service = ContractService(db_session)
|
|
contract = await contract_service.create_contract(
|
|
title="测试合同",
|
|
party_a="甲方",
|
|
party_b="乙方",
|
|
content="合同内容",
|
|
created_by=1,
|
|
)
|
|
|
|
service = SignatureService(db_session)
|
|
request = await service.create_signature_request(
|
|
contract_id=contract.id,
|
|
requester_id=1,
|
|
signer_name="张三",
|
|
signer_email="zhangsan@example.com",
|
|
expire_hours=72,
|
|
)
|
|
|
|
is_valid = await service.is_request_valid(request)
|
|
assert is_valid is True
|