aboutsummaryrefslogtreecommitdiff
path: root/tests/generators/html
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2019-08-04 11:54:08 +0200
committerneodarz <neodarz@neodarz.net>2019-08-04 11:54:08 +0200
commit01b15786a8ae02d364ff79011473bde90eb42e76 (patch)
treeb8b3b776d10bc56a992e6a5d407554987f4b66c0 /tests/generators/html
parent532e7042a7b6d0f5725778de950745bc7f227df2 (diff)
downloadresumejson_converter-01b15786a8ae02d364ff79011473bde90eb42e76.tar.xz
resumejson_converter-01b15786a8ae02d364ff79011473bde90eb42e76.zip
Add some tests
Diffstat (limited to '')
-rw-r--r--tests/generators/html/test_generate_html.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/generators/html/test_generate_html.py b/tests/generators/html/test_generate_html.py
new file mode 100644
index 0000000..f1ce676
--- /dev/null
+++ b/tests/generators/html/test_generate_html.py
@@ -0,0 +1,72 @@
+import pytest
+import os
+
+import resumejson_converter
+
+from jinja2.exceptions import TemplateSyntaxError
+
+from resumejson_converter.generators.html import generate as generate_html
+from resumejson_converter.utils import json as ujson
+
+
+@pytest.fixture(scope="session")
+def gen_template_html(tmpdir_factory):
+ tmp_file = tmpdir_factory.mktemp(
+ "resumejson_converter_test"
+ ).join("template.html")
+
+ with open(tmp_file, "w") as f:
+ f.write("<p>{{ resume.basics.name }}</p>")
+ return tmp_file
+
+
+@pytest.fixture(scope="session")
+def gen_incorrect_template_html(tmpdir_factory):
+ tmp_file = tmpdir_factory.mktemp(
+ "resumejson_converter_test"
+ ).join("template.html")
+
+ with open(tmp_file, "w") as f:
+ f.write("<p>{{ resume.basics.name }</p>")
+ return tmp_file
+
+
+def test_generate_html():
+ with pytest.raises(TypeError):
+ generate_html()
+
+
+def test_generate_html_one_parameters():
+ with pytest.raises(TypeError):
+ generate_html("resume")
+
+
+def test_generate_html(gen_template_html):
+ resume_path = "{}/example/resume.json".format(
+ os.path.dirname(resumejson_converter.__file__))
+ template_path = gen_template_html
+ resume = ujson.load(resume_path)
+ assert generate_html(resume, template_path) == "<p>John Doe</p>"
+
+
+def test_generate_html_incorect_path():
+ with pytest.raises(IOError):
+ generate_html("resume", "/tmp/template")
+
+
+def test_generate_html_incorrect_template(gen_incorrect_template_html):
+ resume_path = "{}/example/resume.json".format(
+ os.path.dirname(resumejson_converter.__file__))
+ template_path = gen_incorrect_template_html
+ resume = ujson.load(resume_path)
+ with pytest.raises(TemplateSyntaxError):
+ generate_html(resume, template_path)
+
+
+def test_generate_html_out_path_without_right(gen_template_html):
+ resume_path = "{}/example/resume.json".format(
+ os.path.dirname(resumejson_converter.__file__))
+ template_path = gen_template_html
+ resume = ujson.load(resume_path)
+ with pytest.raises(IOError):
+ generate_html(resume, template_path, "/my_cv.html")