"""Contract tests for dashboard routes""" import pytest import os import yaml import io from unittest.mock import Mock, patch from app.models.user import User @pytest.fixture def test_product(app): """Create a test product with feedback""" with app.app_context(): # Create test product directory and config product_dir = os.path.join(app.config['DATA_DIR'], 'products', 'test-product') os.makedirs(product_dir, exist_ok=True) # Create product config config_file = os.path.join(product_dir, 'config.yaml') config_data = { 'product_id': 'test-product', 'name': 'Test Product', 'submission_url_slug': 'test-product', 'owner_language': 'en', 'assigned_owner_ids': ['usr_owner1'], 'status': 'active' } with open(config_file, 'w') as f: yaml.dump(config_data, f) # Create feedback directory feedback_dir = os.path.join(product_dir, 'feedback') os.makedirs(feedback_dir, exist_ok=True) # Create test feedback feedback_id = 'test-feedback-001' feedback_path = os.path.join(feedback_dir, feedback_id) os.makedirs(feedback_path, exist_ok=True) # Create feedback metadata metadata = { 'feedback_id': feedback_id, 'product_id': 'test-product', 'status': 'new', 'submitted_at': '2025-10-16T10:00:00Z', 'has_attachments': True, 'attachment_count': 1, 'category': 'bug', 'original_language': 'en' } with open(os.path.join(feedback_path, 'metadata.yaml'), 'w') as f: yaml.dump(metadata, f) # Create feedback content with open(os.path.join(feedback_path, 'content.txt'), 'w') as f: f.write('Test feedback content') # Create attachments directory and file attachments_dir = os.path.join(feedback_path, 'attachments') os.makedirs(attachments_dir, exist_ok=True) with open(os.path.join(attachments_dir, 'test.txt'), 'w') as f: f.write('test attachment content') yield { 'product_id': 'test-product', 'feedback_id': feedback_id } @pytest.fixture def test_users(app): """Create test users (admin and product owner)""" users_file = os.path.join(app.config['DATA_DIR'], 'users.yaml') # User model expects format: {'users': {user_id: user_data}} users_data = { 'users': { 'usr_admin': { 'user_id': 'usr_admin', 'username': 'admin', 'email': 'admin@example.com', 'password_hash': User.hash_password('admin123'), 'role': 'administrator', 'product_ids': [], 'is_active': True }, 'usr_owner1': { 'user_id': 'usr_owner1', 'username': 'owner1', 'email': 'owner1@example.com', 'password_hash': User.hash_password('owner123'), 'role': 'product_owner', 'product_ids': ['test-product'], 'is_active': True }, 'usr_owner2': { 'user_id': 'usr_owner2', 'username': 'owner2', 'email': 'owner2@example.com', 'password_hash': User.hash_password('owner456'), 'role': 'product_owner', 'product_ids': ['other-product'], 'is_active': True } } } with open(users_file, 'w') as f: yaml.dump(users_data, f) yield users_data @pytest.mark.contract def test_get_login(client): """T093: Contract test for GET /login Expected: 200 OK with HTML login form """ response = client.get('/login') assert response.status_code == 200 assert b'