"""Tests for template module.""" import pytest from pathlib import Path class TestTemplateManager: """Test cases for template management.""" def test_list_builtin_templates(self): """Test listing built-in templates.""" from env_pro.core.template import TemplateManager manager = TemplateManager() templates = manager.list_templates() template_names = [t["name"] for t in templates] assert "fastapi" in template_names assert "django" in template_names assert "nodejs" in template_names def test_get_builtin_template(self): """Test getting a built-in template.""" from env_pro.core.template import TemplateManager manager = TemplateManager() template = manager.get_template("fastapi") assert template is not None assert "variables" in template assert "APP_NAME" in template["variables"] def test_apply_template(self): """Test applying a template.""" from env_pro.core.template import TemplateManager manager = TemplateManager() content = manager.apply_template("minimal", {"ENVIRONMENT": "production", "DEBUG": "false"}) assert "ENVIRONMENT=production" in content assert "DEBUG=false" in content assert "# Generated by env-pro" in content def test_apply_template_with_output(self, temp_dir): """Test applying template to a file.""" from env_pro.core.template import TemplateManager manager = TemplateManager() output_file = temp_dir / ".env" manager.apply_template("minimal", {"ENVIRONMENT": "test"}, output_file=output_file) assert output_file.exists() content = output_file.read_text() assert "ENVIRONMENT=test" in content def test_get_nonexistent_template(self): """Test getting a template that doesn't exist.""" from env_pro.core.template import TemplateManager manager = TemplateManager() template = manager.get_template("nonexistent") assert template is None