Files
cleveragents-core/tests/features/template_renderer_coverage.feature

228 lines
9.5 KiB
Gherkin

Feature: Template Renderer Module Coverage
As a developer
I want to test all functionality in the template renderer module
So that we achieve 90%+ code coverage for the renderer.py file
Background:
Given I have a clean test environment for template renderer
# Test TemplateEngine enum and basic initialization
Scenario: Test TemplateEngine enum values
Given I import the TemplateEngine enum
When I access the enum values
Then I should have SIMPLE, JINJA2, and MUSTACHE engines
# Test _resolve_path function
Scenario: Test _resolve_path with nested dictionary paths
Given I have a context dictionary with nested values
When I resolve a dotted path in the context
Then I should get the correct nested value
Scenario: Test _resolve_path with object attributes
Given I have an object with attributes
When I resolve a dotted path on the object
Then I should get the correct attribute value
Scenario: Test _resolve_path with missing keys
Given I have a context dictionary
When I resolve a path that doesn't exist
Then I should get an empty string
# Test TemplateRenderer initialization
Scenario: Test TemplateRenderer initialization with SIMPLE engine
Given I initialize a TemplateRenderer with SIMPLE engine
Then the engine should be str.format
Scenario: Test TemplateRenderer initialization with JINJA2 engine
Given I initialize a TemplateRenderer with JINJA2 engine
Then the engine should be a Jinja2 Environment
Scenario: Test TemplateRenderer initialization with MUSTACHE engine
Given I initialize a TemplateRenderer with MUSTACHE engine
Then the engine should be a Pystache Renderer
Scenario: Test TemplateRenderer initialization with unsupported engine
When I try to initialize TemplateRenderer with an invalid engine
Then I should get a TemplateError about unsupported engine
# Skip Jinja2/Pystache availability tests for now - they're complex to mock
# Focus on actual functionality testing
# Test _render_simple_with_jinja_like function
Scenario: Test simple Jinja-like rendering with basic placeholders
Given I have a template with simple placeholders
When I render the template with Jinja-like syntax
Then the placeholders should be replaced correctly
Scenario: Test simple Jinja-like rendering with expressions
Given I have a template with expression placeholders
And I have a context dictionary
When I render the template with Jinja-like syntax
Then the expressions should be evaluated correctly
Scenario: Test simple Jinja-like rendering with None values
Given I have a template with placeholders
And I have a context with None values
When I render the template with Jinja-like syntax
Then None values should become empty strings
# Test register_template functionality
Scenario: Test register_template with empty name
Given I have a TemplateRenderer
When I try to register a template with empty name
Then I should get a TemplateError about empty name
Scenario: Test register_template with SIMPLE engine
Given I have a TemplateRenderer with SIMPLE engine
When I register a template with a name and content
Then the template should be stored as a string
Scenario: Test register_template with JINJA2 engine
Given I have a TemplateRenderer with JINJA2 engine
When I register a template with a name and content
Then the template should be compiled and stored
Scenario: Test register_template with invalid Jinja2 template
Given I have a TemplateRenderer with JINJA2 engine
When I try to register an invalid Jinja2 template
Then I should get a TemplateError about registration failure
Scenario: Test register_template with MUSTACHE engine
Given I have a TemplateRenderer with MUSTACHE engine
When I register a template with a name and content
Then the template should be stored as a string
# Test render functionality
Scenario: Test render with nonexistent template
Given I have a TemplateRenderer
When I try to render a template that doesn't exist
Then I should get a TemplateError about template not found
Scenario: Test render with SIMPLE engine and valid template
Given I have a TemplateRenderer with SIMPLE engine
And I have registered a simple template
When I render the template with context data
Then I should get the rendered result
Scenario: Test render with SIMPLE engine and missing variables
Given I have a TemplateRenderer with SIMPLE engine
And I have registered a template with placeholders
When I render the template with incomplete context
Then I should get a TemplateError about missing variables
Scenario: Test render with JINJA2 engine and valid template
Given I have a TemplateRenderer with JINJA2 engine
And I have registered a Jinja2 template
When I render the template with context data
Then I should get the rendered result
Scenario: Test render with JINJA2 engine and invalid template object
Given I have a TemplateRenderer with JINJA2 engine
And I have a template object without render method
When I try to render the template
Then I should get a TemplateError about missing render method
Scenario: Test render with MUSTACHE engine and valid template
Given I have a TemplateRenderer with MUSTACHE engine
And I have registered a Mustache template
When I render the template with context data
Then I should get the rendered result
Scenario: Test render with MUSTACHE engine and invalid renderer
Given I have a TemplateRenderer with MUSTACHE engine
And I have a renderer without render method
When I try to render a template
Then I should get a TemplateError about missing render method
Scenario: Test render with unknown engine type
Given I have a TemplateRenderer with modified engine type
When I try to render a template
Then I should get a TemplateError about unsupported engine
Scenario: Test render with exception during rendering
Given I have a TemplateRenderer
And I have a template that causes rendering exceptions
When I try to render the template
Then I should get a TemplateError about rendering failure
# Test render_string functionality
Scenario: Test render_string with SIMPLE engine
Given I have a TemplateRenderer with SIMPLE engine
When I render a template string with context data
Then I should get the rendered result
Scenario: Test render_string with SIMPLE engine and missing variables
Given I have a TemplateRenderer with SIMPLE engine
When I render a template string with incomplete context
Then I should get a TemplateError about missing variables
# Skip JINJA2 and MUSTACHE render_string tests for now since they may not be available
Scenario: Test render_string with unknown engine type
Given I have a TemplateRenderer with modified engine type
When I try to render a template string
Then I should get a TemplateError about unsupported engine
Scenario: Test render_string with source description
Given I have a TemplateRenderer
When I render a template string with source description and it fails
Then the error should include the source description
Scenario: Test render_string with exception during rendering
Given I have a TemplateRenderer
When I render a template string that causes exceptions
Then I should get a TemplateError about rendering failure
# Test get_template functionality
Scenario: Test get_template with existing template
Given I have a TemplateRenderer
And I have registered a template
When I get the template by name
Then I should receive the template content
Scenario: Test get_template with nonexistent template
Given I have a TemplateRenderer
When I try to get a template that doesn't exist
Then I should get a TemplateError about template not found
# Test list_templates functionality
Scenario: Test list_templates with empty registry
Given I have a TemplateRenderer
When I list all templates from renderer
Then I should get an empty list
Scenario: Test list_templates with multiple templates
Given I have a TemplateRenderer
And I have registered multiple templates
When I list all templates from renderer
Then I should get all template names
# Additional scenarios to reach 90% coverage
Scenario: Test _resolve_path with object attribute access
Given I have an object with nested attributes
When I resolve a path with object attribute access
Then I should get the correct object attribute value
Scenario: Test render with JINJA2 template compilation
Given I have a TemplateRenderer with JINJA2 engine
And I have a valid Jinja2 template content
When I register and render the Jinja2 template
Then the Jinja2 template should render correctly
Scenario: Test render with MUSTACHE template processing
Given I have a TemplateRenderer with MUSTACHE engine
And I have a valid Mustache template content
When I register and render the Mustache template
Then the Mustache template should render correctly
Scenario: Test render_string with JINJA2 engine functionality
Given I have a TemplateRenderer with JINJA2 engine
When I render a Jinja2 template string
Then I should get correct Jinja2 rendered output
Scenario: Test render_string with MUSTACHE engine functionality
Given I have a TemplateRenderer with MUSTACHE engine
When I render a Mustache template string
Then I should get correct Mustache rendered output
# Skip import error tests for now - they're complex to mock correctly