aboutsummaryrefslogtreecommitdiff
path: root/tests/utils/json/test_load.py
blob: d8090697e767a10f5270def0837a5ae9f738609d (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
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))