From 54c2a369fbd43d59f3a3d76650dc371651fded94 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sat, 31 Jan 2026 01:38:06 +0000 Subject: [PATCH] Add test files --- app/tests/test_template.py | 63 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 app/tests/test_template.py diff --git a/app/tests/test_template.py b/app/tests/test_template.py new file mode 100644 index 0000000..15ae6c7 --- /dev/null +++ b/app/tests/test_template.py @@ -0,0 +1,63 @@ +"""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