Esempio n. 1
0
    def test_loading_malformed_non_optional_rezume_data_fails(
            self, sample_rezume):
        del sample_rezume["basics"]["location"]

        rezume = Rezume()
        with pytest.raises(ValidationError):
            rezume.load_data(sample_rezume)
Esempio n. 2
0
 def test_adding_item_to_wrong_section_fails(self):
     rezume = Rezume()
     with pytest.raises(RezumeError):
         item = Education(institution="edX",
                          area="humanity",
                          start_date="2020-07-05")
         rezume.add_item("work", item)
Esempio n. 3
0
    def test_can_load_valid_file(self, filepath):
        rezume = Rezume()
        rezume.load(filepath)

        try:
            assert len(rezume.profiles) == 1
            assert len(rezume["education"]) == 1
        except Exception:
            pytest.fail("Exception not expected")
Esempio n. 4
0
    def test_can_load_wellformed_non_optional_rezume_data(self, sample_rezume):
        try:
            rezume = Rezume()
            assert len(rezume.profiles) == 0
            assert len(rezume["education"]) == 0

            rezume.load_data(sample_rezume)
            assert len(rezume.profiles) == 1
            assert len(rezume["education"]) == 1
        except Exception as ex:
            pytest.fail(f"Exception not expected: {ex}")
Esempio n. 5
0
    def test_can_add_item_to_known_section(self):
        try:
            rezume = Rezume()
            section_name = "education"
            assert len(rezume[section_name]) == 0

            item = Education(institution="edX",
                             area="humanity",
                             startDate="2020-07-05")
            rezume.add_item(section_name, item)
            assert len(rezume[section_name]) == 1
        except Exception:
            pytest.fail("Exception not expected")
Esempio n. 6
0
    def test_can_save_to_non_existing_file(self):
        rezume = Rezume()
        rezume.load("./src/rezume/assets/rezume-template.yml")

        fpath = Path("./tests/fixtures/rezume-saved.yml.log")
        if fpath.exists():
            fpath.unlink()
        assert not fpath.exists()

        rezume.save(fpath)
        assert fpath.exists()

        loaded = Rezume()
        loaded.load(fpath)
        assert len(rezume.profiles) == 1
        assert len(rezume["education"]) == 1
Esempio n. 7
0
    def test_rezume_is_validate_before_dump(self, sample_rezume):
        rezume = Rezume().load_data(sample_rezume)
        section = rezume["education"]

        assert section is not None
        assert len(section) > 0

        entry = list(section)[0]
        section.discard(entry)

        assert len(section) == 0

        # a valid rezume is expected to have at least one entry in the
        # education section in addition to all required basics details
        with pytest.raises(RezumeError):
            rezume.dump_data()
Esempio n. 8
0
def test_render_rezume(sample_rezume, theme_name, has_result):
    """Checks that serve command :func:`render_rezume` function can render a rezume for a
    specified theme if it exists or return None if theme doesn't exist.
    """
    # add path to theme package fixtures to python search path
    path = Path(__file__).parent / "themes"
    sys.path.insert(0, str(path))

    rezume = Rezume().load_data(sample_rezume)
    result = render_rezume(rezume, theme_name)
    assert isinstance(result, str) == has_result
Esempio n. 9
0
def render(rezume: Rezume):
    """Renders the provide Rezume using template/rezume.mst template file.
    """
    base_dir = Path(__file__).absolute().parent
    template = base_dir / "template" / "rezume.mst"

    assert template is not None

    with template.open("r") as tf:
        data = rezume.dump_data()
        html = chevron.render(tf, {"rezume": data})
        return html
Esempio n. 10
0
    def test_personal_details_are_validated_on_dump(self):
        rezume = Rezume()
        rezume.name = "John"
        rezume.email = "john"

        with pytest.raises(ValidationError):
            rezume.dump_data()
Esempio n. 11
0
    def test_can_save_to_exiting_file_with_overwrite(self, rezume_mini):
        rezume = Rezume()
        rezume.load(rezume_mini)

        try:
            rezume.save(rezume_mini, True)
        except Exception as ex:
            pytest.fail(f"Exception not expected: {ex}")
Esempio n. 12
0
def render(rezume: Rezume):
    """Renders the provide Rezume using template/rezume.hbs template file.
    """
    assets_dir = Path(__file__).absolute().parent / "assets"
    template_file = assets_dir / "rezume.hbs"
    style = assets_dir / "style.css"

    assert template_file is not None

    with template_file.open("r") as tf, style.open("r") as sf:
        data = rezume.dump_data()
        css = "".join(sf.readlines())
        hbs = "".join(tf.readlines())

        template = Compiler().compile(hbs)
        html = template({"resume": data, "css": css})
        return html
Esempio n. 13
0
 def test_can_validate_file_via_validate_api(self, rezume_mini):
     try:
         Rezume.validate(rezume_mini)
     except Exception as ex:
         pytest.fail(f"Exception not expected: {ex}")
Esempio n. 14
0
 def test_fails_for_invalid_file(self, filepath):
     rezume = Rezume()
     with pytest.raises(RezumeError):
         rezume.load(filepath)
Esempio n. 15
0
def render(rezume: Rezume):
    """Returns a JSON string as the rendered representation of provided rezume."""
    data = rezume.dump_data()
    return json.dumps(data)
Esempio n. 16
0
    def test_save_fails_without_overwrite_to_existing_file(self, rezume_mini):
        rezume = Rezume()
        rezume.load(rezume_mini)

        with pytest.raises(RezumeError):
            rezume.save(rezume_mini)
Esempio n. 17
0
 def test_load_acts_fluent_by_returning_instance(self, rezume_mini):
     rezume = Rezume().load(rezume_mini)
     assert rezume is not None
Esempio n. 18
0
 def test_removing_item_from_unknown_section_fails(self):
     rezume = Rezume()
     with pytest.raises(RezumeError):
         rezume.discard_item("-work-", Experience.construct())
Esempio n. 19
0
 def test_adding_item_to_unknown_section_fails(self):
     rezume = Rezume()
     with pytest.raises(RezumeError):
         rezume.add_item("-work-", Experience.construct())
Esempio n. 20
0
 def test_can_validate_data_via_is_valid_api(self, sample_rezume):
     assert Rezume.is_valid(sample_rezume) is True
Esempio n. 21
0
 def test_can_validate_file_via_is_valid_api(self, rezume_mini):
     assert Rezume.is_valid(rezume_mini) is True
Esempio n. 22
0
 def test_can_validate_data_via_validate_api(self, sample_rezume):
     try:
         Rezume.validate(sample_rezume)
     except Exception as ex:
         pytest.fail(f"Exception not expected: {ex}")
Esempio n. 23
0
 def test_load_data_acts_fluent_by_returning_instance(self, sample_rezume):
     rezume = Rezume().load_data(sample_rezume)
     assert rezume is not None
Esempio n. 24
0
 def test_instance_is_prepopulated_with_data_sections(self):
     rezume = Rezume()
     assert len(rezume) > 0