aboutsummaryrefslogtreecommitdiff
path: root/tests/generators/html/test_generate_html.py
blob: f1ce676d42adb893774dd600f4ff690d2258b7b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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")