Skip to content

Commit

Permalink
Fix Unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mshivashankar committed Oct 16, 2023
1 parent c598289 commit 742fdd3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions test/test_failsafe_mechanism.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,40 +47,40 @@ def strip_html_tags(self, html_text):

def test_render_html_template(self):
# Test rendering of an HTML template
output, subject = self.Loop.run_until_complete(self.orchestrator._render_template("/Templates/Email/sample.html", {}, ["[email protected]"]))
output, subject = self.Loop.run_until_complete(self.orchestrator._render_template("/Templates/Email/sample.html", {}))
self.assertEqual(output, "Mocked Jinja Output")

def test_render_jinja_exception(self):
# Test handling of Jinja2 exceptions
self.MockJinjaService.format.side_effect = jinja2.exceptions.TemplateError("Mocked Jinja Error")
output, subject = self.Loop.run_until_complete(self.orchestrator._render_template("/Templates/Email/sample.html", {}, ["[email protected]"]))
output, subject = self.Loop.run_until_complete(self.orchestrator._render_template("/Templates/Email/sample.html", {}))
self.assertIn("Error Details:", output)

def test_render_md_template(self):
# Test rendering of a Markdown template
self.MockMarkdownToHtmlService.format.return_value = "Mocked Jinja Output"
output, subject = self.Loop.run_until_complete(
self.orchestrator._render_template("/Templates/Email/sample.md", {}, ["[email protected]"]))
self.orchestrator._render_template("/Templates/Email/sample.md", {}))
self.assertEqual(self.strip_html_tags(output), "Mocked Jinja Output") # Removed the "\n" from the expected value

def test_jinja_template_not_found(self):
self.MockJinjaService.format.side_effect = jinja2.TemplateNotFound
error_message, _ = self.Loop.run_until_complete(self.orchestrator._render_template("/Templates/Email/sample.html", {}, ["[email protected]"]))
error_message, _ = self.Loop.run_until_complete(self.orchestrator._render_template("/Templates/Email/sample.html", {}))
self.assertIn("Error Details:", error_message)

def test_jinja_template_syntax_error(self):
self.MockJinjaService.format.side_effect = jinja2.TemplateSyntaxError
error_message, _ = self.Loop.run_until_complete(self.orchestrator._render_template("/Templates/Email/sample.html", {}, ["[email protected]"]))
error_message, _ = self.Loop.run_until_complete(self.orchestrator._render_template("/Templates/Email/sample.html", {}))
self.assertIn("Error Details:", error_message)

def test_jinja_undefined_error(self):
self.MockJinjaService.format.side_effect = jinja2.UndefinedError
error_message, _ = self.Loop.run_until_complete(self.orchestrator._render_template("/Templates/Email/sample.html", {}, ["[email protected]"]))
error_message, _ = self.Loop.run_until_complete(self.orchestrator._render_template("/Templates/Email/sample.html", {}))
self.assertIn("Error Details:", error_message)

def test_general_exception(self):
self.MockJinjaService.format.side_effect = Exception("General Exception")
error_message, _ = self.Loop.run_until_complete(self.orchestrator._render_template("/Templates/Email/sample.html", {}, ["[email protected]"]))
error_message, _ = self.Loop.run_until_complete(self.orchestrator._render_template("/Templates/Email/sample.html", {}))
self.assertIn("Error Details:", error_message)


Expand Down

0 comments on commit 742fdd3

Please sign in to comment.