diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/filters/test_birthday.py | 17 | ||||
-rw-r--r-- | tests/filters/test_clean.py | 12 | ||||
-rw-r--r-- | tests/filters/test_datediff.py | 84 | ||||
-rw-r--r-- | tests/filters/test_dateedit.py | 30 | ||||
-rw-r--r-- | tests/generators/html/test_generate_html.py | 72 | ||||
-rw-r--r-- | tests/generators/pdf/test_generate_pdf.py | 55 | ||||
-rw-r--r-- | tests/utils/json/test_load.py | 52 | ||||
-rw-r--r-- | tests/utils/templates/test_templates.py | 33 |
8 files changed, 355 insertions, 0 deletions
diff --git a/tests/filters/test_birthday.py b/tests/filters/test_birthday.py new file mode 100644 index 0000000..257f8c4 --- /dev/null +++ b/tests/filters/test_birthday.py @@ -0,0 +1,17 @@ +import pytest + +import resumejson_converter.filters as filters + + +def test_birthday_no_parameter(): + with pytest.raises(TypeError): + filters.birthday() + + +def test_birthday_false_date(): + with pytest.raises(ValueError): + filters.birthday("1990-10-25a") + + +def test_birthday(): + assert filters.birthday("1990-10-25") == "25 octobre 1990" diff --git a/tests/filters/test_clean.py b/tests/filters/test_clean.py new file mode 100644 index 0000000..32553b4 --- /dev/null +++ b/tests/filters/test_clean.py @@ -0,0 +1,12 @@ +import pytest + +import resumejson_converter.filters as filters + + +def test_clean_no_parameter(): + with pytest.raises(TypeError): + filters.clean() + + +def test_clean(): + assert filters.clean("0011223344") == "00 11 22 33 44" diff --git a/tests/filters/test_datediff.py b/tests/filters/test_datediff.py new file mode 100644 index 0000000..845330b --- /dev/null +++ b/tests/filters/test_datediff.py @@ -0,0 +1,84 @@ +import pytest + +import resumejson_converter.filters as filters + + +def test_datediff_only_one_parameter(): + with pytest.raises(TypeError): + filters.datediff() + + +def test_datediff_only_one_parameter(): + with pytest.raises(TypeError): + filters.datediff("Hello World") + + +def test_datediff_only_two_parameter(): + with pytest.raises(TypeError): + filters.datediff("Hello World", "2019-01-02") + + +def test_datediff_false_end_date(): + with pytest.raises(ValueError): + filters.datediff("Hello", "2019-01-02", "2019-01-02d") + + +def test_datediff_false_start_date(): + with pytest.raises(ValueError): + filters.datediff("Hello", "2019-01-02a", "2019-01-02") + + +def test_datediff_one_year(): + assert filters.datediff( + "Hello World!", + "2018-01-02", + "2019-01-03" + ) == "Hello World! - 1 an" + + +def test_datediff_two_year(): + assert filters.datediff( + "Hello World!", + "2017-01-02", + "2019-01-03" + ) == "Hello World! - 2 ans" + + +def test_datediff_two_years(): + assert filters.datediff( + "Hello World!", + "2017-01-02", + "2019-01-03" + ) == "Hello World! - 2 ans" + + +def test_datediff_one_month(): + assert filters.datediff( + "Hello World!", + "2019-01-02", + "2019-02-03" + ) == "Hello World! - 1 mois" + + +def test_datediff_one_week(): + assert filters.datediff( + "Hello World!", + "2019-01-01", + "2019-01-09" + ) == "Hello World! - 1 semaine" + + +def test_datediff_two_weeks(): + assert filters.datediff( + "Hello World!", + "2019-01-01", + "2019-01-16" + ) == "Hello World! - 2 semaines" + + +def test_datediff_two_days(): + assert filters.datediff( + "Hello World!", + "2019-01-02", + "2019-01-04" + ) == "Hello World! - 2 jours" diff --git a/tests/filters/test_dateedit.py b/tests/filters/test_dateedit.py new file mode 100644 index 0000000..5191b26 --- /dev/null +++ b/tests/filters/test_dateedit.py @@ -0,0 +1,30 @@ +import pytest + +import resumejson_converter.filters as filters + + +def test_dateedit_only_one_parameter(): + with pytest.raises(TypeError): + filters.dateedit() + + +def test_dateedit_only_one_parameter(): + with pytest.raises(TypeError): + filters.dateedit("2019-01-01") + + +def test_dateedit_false_date(): + with pytest.raises(ValueError): + filters.dateedit("2019-01-01i", "") + + +def test_dateedit_only_start_date(): + assert filters.dateedit("2019-01-01", "") == "2019 - Auj." + + +def test_dateedite_same_year(): + assert filters.dateedit("2019-01-01", "2019-02-02") == "2019" + + +def test_dateedit_start_date_and_end_date_different(): + assert filters.dateedit("2019-01-01", "2017-05-01") == "2019 - 2017" 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") diff --git a/tests/generators/pdf/test_generate_pdf.py b/tests/generators/pdf/test_generate_pdf.py new file mode 100644 index 0000000..738508c --- /dev/null +++ b/tests/generators/pdf/test_generate_pdf.py @@ -0,0 +1,55 @@ +import pytest +import os +from pathlib import Path + +import resumejson_converter + +from jinja2.exceptions import TemplateSyntaxError + +from resumejson_converter.generators.html import generate as generate_html +from resumejson_converter.generators.pdf import generate as generate_pdf +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 + + +@pytest.fixture(scope="session") +def gen_dest_path(tmpdir_factory): + return tmpdir_factory.mktemp("out").join("out.pdf") + + +def test_generate_pdf(): + with pytest.raises(TypeError): + generate_html() + + +def test_generate_pdf_generated( + gen_template_html, + gen_incorrect_template_html): + resume_path = "{}/example/resume.json".format( + os.path.dirname(resumejson_converter.__file__)) + template_path = gen_template_html + resume = ujson.load(resume_path) + html = generate_html(resume, template_path) + generate_pdf(html, gen_incorrect_template_html) + assert Path(gen_incorrect_template_html).is_file diff --git a/tests/utils/json/test_load.py b/tests/utils/json/test_load.py new file mode 100644 index 0000000..d809069 --- /dev/null +++ b/tests/utils/json/test_load.py @@ -0,0 +1,52 @@ +import pytest +import os + +from jsonresume.exceptions import InvalidResumeError + +import resumejson_converter + +from resumejson_converter.utils import json as ujson + + +@pytest.fixture(scope="session") +def prepare_tmp_json(tmpdir_factory): + tmp_file = tmpdir_factory.mktemp( + "resumejson_converter_test" + ).join("resume_not_standard.json") + + with open(tmp_file, "w") as f: + f.write("{'Hello': 'World!'}") + return tmp_file + + +def test_json_load_no_parameter(): + with pytest.raises(TypeError): + ujson.load() + + +def test_json_load(): + resume_path = "{}/example/resume.json".format( + os.path.dirname(resumejson_converter.__file__)) + assert type(ujson.load(resume_path)) is ujson.JsonObject + + +def test_json_load_incorrect_path(): + with pytest.raises(IOError): + resume_json = "/tmp/sd54f5f48ds4f98ds7g48d468s4f68ds4f.json" + ujson.load(resume_json) + + +def test_json_load_resume_dont_respect_standard(): + with pytest.raises(InvalidResumeError): + resume_path = {"Hello": 'World!'} + ujson.load(resume_path) + + +def test_json_load_array(): + with pytest.raises(TypeError): + ujson.load(["o", "f"]) + + +def test_json_load_resume_dont_respect_standard_from_file(prepare_tmp_json): + with pytest.raises(ValueError): + ujson.load(str(prepare_tmp_json)) diff --git a/tests/utils/templates/test_templates.py b/tests/utils/templates/test_templates.py new file mode 100644 index 0000000..66c77f6 --- /dev/null +++ b/tests/utils/templates/test_templates.py @@ -0,0 +1,33 @@ +import pytest +import os + +from datetime import datetime + +import resumejson_converter + +from resumejson_converter.utils import templates + + +def test_td_format_no_argument(): + with pytest.raises(TypeError): + templates.td_format() + + +def test_td_format_classic(): + startDateTime = datetime.strptime( + "2015-02-20 10:15:20", + '%Y-%m-%d %H:%M:%S') + endDateTime = datetime.strptime( + "2019-03-25 11:16:25", + '%Y-%m-%d %H:%M:%S') + diffDate = endDateTime - startDateTime + + assert templates.td_format(diffDate) == "4 ans, 1 mois, 4 jours, 1 heure, 1 minute, 5 secondes" + + +def test_td_format_week(): + startDateTime = datetime.strptime("2019-02-01", '%Y-%m-%d') + endDateTime = datetime.strptime("2019-02-16", '%Y-%m-%d') + diffDate = endDateTime - startDateTime + + assert templates.td_format(diffDate) == "2 semaines, 24 heures" |