Files
arnes/tests/unit/test_profile.py
rikrdo 3ff9b70e4c refactor: complete bootstrap of ARNES agent harness framework
- Add complete agent harness structure with 8 roles (leader, triager, architect, implementer, reviewer, security, qa, documenter)
- Implement strict workflow with 9 stages and mandatory gates
- Add comprehensive verification script and runtime status tracking
- Create artifact-based evidence system with contracts and schemas
- Add agent policy matrix with permissions and anti-cheat rules
- Include test suite (44 tests passing) and CI-ready structure
- Add documentation: README, HOWTO, CHECKPOINTS, templates
- Configure model routing policies and token-aware task assignment
- Add BDD/SDD specification guides and feature templates
- Include starter pack for quick project onboarding

All verification checks pass. Framework ready for production use.
2026-05-17 23:25:35 +02:00

131 lines
5.3 KiB
Python

"""Unit tests for profile service using unittest."""
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
import unittest
from src.models.profile import Profile, UpdateProfileRequest
from src.services.profile_service import ProfileService
class TestProfileModel(unittest.TestCase):
"""Tests for Profile model."""
def test_profile_creation(self):
"""Test creating a profile."""
profile = Profile(id="user-1", name="Juan Pérez", language="es")
self.assertEqual(profile.id, "user-1")
self.assertEqual(profile.name, "Juan Pérez")
self.assertEqual(profile.language, "es")
def test_profile_name_validation_letters(self):
"""Test valid name with letters only."""
profile = Profile(id="user-1", name="José García")
self.assertEqual(profile.name, "José García")
def test_profile_name_validation_invalid_chars(self):
"""Test invalid name with special characters."""
with self.assertRaises(ValueError) as ctx:
Profile(id="user-1", name="Juan@123!")
self.assertIn("Nombre inválido", str(ctx.exception))
def test_profile_avatar_url_valid(self):
"""Test valid avatar URL."""
profile = Profile(id="user-1", name="Test", avatar_url="https://cdn.example.com/img.jpg")
self.assertEqual(profile.avatar_url, "https://cdn.example.com/img.jpg")
def test_profile_avatar_url_invalid_protocol(self):
"""Test invalid avatar URL protocol."""
with self.assertRaises(ValueError) as ctx:
Profile(id="user-1", name="Test", avatar_url="ftp://malicious.com/file.jpg")
self.assertIn("Solo se permiten", str(ctx.exception))
def test_profile_language_values(self):
"""Test valid language values."""
for lang in ["en", "es", "fr", "de"]:
profile = Profile(id="user-1", name="Test", language=lang)
self.assertEqual(profile.language, lang)
class TestUpdateProfileRequest(unittest.TestCase):
"""Tests for UpdateProfileRequest model."""
def test_partial_update_name_only(self):
"""Test updating only name."""
request = UpdateProfileRequest(name="Pedro")
self.assertEqual(request.name, "Pedro")
self.assertIsNone(request.avatar_url)
self.assertIsNone(request.language)
def test_partial_update_all_fields(self):
"""Test updating all fields."""
request = UpdateProfileRequest(
name="Pedro",
avatar_url="https://cdn.example.com/new.jpg",
language="en"
)
self.assertEqual(request.name, "Pedro")
self.assertEqual(request.avatar_url, "https://cdn.example.com/new.jpg")
self.assertEqual(request.language, "en")
class TestProfileService(unittest.TestCase):
"""Tests for ProfileService."""
def setUp(self):
"""Create a fresh service instance."""
self.service = ProfileService()
def test_get_existing_profile(self):
"""Test getting an existing profile."""
profile, status, error = self.service.get_profile("user-123")
self.assertEqual(status, 200)
self.assertIsNotNone(profile)
self.assertEqual(profile.id, "user-123")
self.assertIsNone(error)
def test_get_nonexistent_profile(self):
"""Test getting a nonexistent profile."""
profile, status, error = self.service.get_profile("nonexistent")
self.assertEqual(status, 404)
self.assertIsNone(profile)
self.assertEqual(error, "Usuario no encontrado")
def test_update_profile_name(self):
"""Test updating profile name."""
request = UpdateProfileRequest(name="Pedro")
profile, status, error = self.service.update_profile("user-123", request)
self.assertEqual(status, 200)
self.assertEqual(profile.name, "Pedro")
def test_update_profile_avatar(self):
"""Test updating profile avatar."""
request = UpdateProfileRequest(avatar_url="https://cdn.example.com/new.jpg")
profile, status, error = self.service.update_profile("user-123", request)
self.assertEqual(status, 200)
self.assertEqual(profile.avatar_url, "https://cdn.example.com/new.jpg")
def test_update_profile_language(self):
"""Test updating profile language."""
request = UpdateProfileRequest(language="fr")
profile, status, error = self.service.update_profile("user-123", request)
self.assertEqual(status, 200)
self.assertEqual(profile.language, "fr")
def test_update_nonexistent_profile(self):
"""Test updating a nonexistent profile."""
request = UpdateProfileRequest(name="Test")
profile, status, error = self.service.update_profile("nonexistent", request)
self.assertEqual(status, 404)
self.assertEqual(error, "Usuario no encontrado")
def test_create_profile(self):
"""Test creating a new profile."""
profile = self.service.create_profile("user-new", "New User", "https://cdn.com/img.jpg", "es")
self.assertEqual(profile.id, "user-new")
self.assertEqual(profile.name, "New User")
self.assertEqual(profile.language, "es")
if __name__ == "__main__":
unittest.main()