aboutsummaryrefslogtreecommitdiff
path: root/tests/utils
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/utils
parent532e7042a7b6d0f5725778de950745bc7f227df2 (diff)
downloadresumejson_converter-01b15786a8ae02d364ff79011473bde90eb42e76.tar.xz
resumejson_converter-01b15786a8ae02d364ff79011473bde90eb42e76.zip
Add some tests
Diffstat (limited to '')
-rw-r--r--tests/utils/json/test_load.py52
-rw-r--r--tests/utils/templates/test_templates.py33
2 files changed, 85 insertions, 0 deletions
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"