Built py.test cases for convert_markdown_template

This commit is contained in:
Anastasia Gradova
2023-12-26 22:04:06 -07:00
parent 023f57cf1d
commit a5ec03302e
3 changed files with 40 additions and 7 deletions

View File

@@ -24,12 +24,15 @@ from app.utils.csv import get_user_preferred_timezone
from app.utils.time import parse_naive_dt
def convert_markdown_template(mdf):
APP_ROOT = get_root_path('notifications-admin')
file = 'app/content/' + mdf + '.md'
md_file = os.path.join(APP_ROOT, file)
with open(md_file) as f:
content_text = f.read()
def convert_markdown_template(mdf, test=False):
if not test:
APP_ROOT = get_root_path('notifications-admin')
file = 'app/content/' + mdf + '.md'
md_file = os.path.join(APP_ROOT, file)
with open(md_file) as f:
content_text = f.read()
else:
content_text = mdf
md_render = markdown.markdown(content_text)
jn_render = render_template_string(md_render)

View File

@@ -1,8 +1,9 @@
from datetime import datetime
from functools import partial
import pytest
from flask import url_for
from flask import url_for, Flask
from freezegun import freeze_time
from app.formatters import (
@@ -12,6 +13,13 @@ from app.formatters import (
format_notification_status_as_url,
format_number_in_pounds_as_currency,
round_to_significant_figures,
convert_markdown_template
)
from tests.conftest import (
fake_markdown_file,
fake_jinja_template,
notify_admin
)
@@ -166,3 +174,15 @@ def test_email_safe_return_dot_separated_email_domain(service_name, safe_email):
def test_format_delta():
naive_now_utc = datetime.utcnow().isoformat()
assert format_delta(naive_now_utc) == "just now"
@pytest.mark.usefixtures("fake_jinja_template")
def test_jinja_format(fake_jinja_template):
app = Flask("app")
with app.app_context():
assert convert_markdown_template(fake_jinja_template, test=True) == "<p>True</p>"
@pytest.mark.usefixtures("fake_markdown_file")
def test_markdown_format(fake_markdown_file):
app = Flask("app")
with app.app_context():
assert convert_markdown_template(fake_markdown_file, test=True) == "<h1>Test</h1>"

View File

@@ -3594,3 +3594,13 @@ def end_to_end_authenticated_context(browser):
context = browser.new_context(storage_state=auth_state_path)
return context
@pytest.fixture()
def fake_markdown_file():
input = "#Test"
return input
@pytest.fixture()
def fake_jinja_template():
input = "{% if True %}True{% endif %}"
return input