From ed9b7f7b09fd075ed1a89f16a7052cfc2fc1249a Mon Sep 17 00:00:00 2001 From: Sina Atalay Date: Sat, 25 May 2024 15:53:12 +0300 Subject: [PATCH] tests: update --- tests/conftest.py | 4 ++ tests/test_cli.py | 38 +++++++++++++---- tests/test_data_models.py | 85 +++++++++++++++++++++++++++++---------- 3 files changed, 98 insertions(+), 29 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 6161bbc..d59e0ed 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -285,6 +285,10 @@ def rendercv_filled_curriculum_vitae_data_model( dm.SocialNetwork(network="Orcid", username="0000-0000-0000-0000"), dm.SocialNetwork(network="Mastodon", username="@johndoe@example"), dm.SocialNetwork(network="Twitter", username="johndoe"), + dm.SocialNetwork(network="StackOverflow", username="12323/johndoe"), + dm.SocialNetwork(network="GitLab", username="johndoe"), + dm.SocialNetwork(network="ResearchGate", username="johndoe"), + dm.SocialNetwork(network="YouTube", username="@johndoe"), ], sections={ "Text Entries": [text_entry, text_entry, text_entry], diff --git a/tests/test_cli.py b/tests/test_cli.py index 4e188fe..f864cdf 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -286,8 +286,8 @@ def test_render_command_with_different_output_path_for_each_file( def test_render_command_with_custom_png_path_multiple_pages(tmp_path): # create a new input file (for a CV with multiple pages) in the temporary directory: os.chdir(tmp_path) - runner.invoke(cli.app, ["new", "John Doe"]) - input_file_path = tmp_path / "John_Doe_CV.yaml" + runner.invoke(cli.app, ["new", "Jahn Doe"]) + input_file_path = tmp_path / "Jahn_Doe_CV.yaml" run_render_command( input_file_path, @@ -370,11 +370,11 @@ def test_render_command_with_invalid_arguments( def test_new_command(tmp_path): # change the current working directory to the temporary directory: os.chdir(tmp_path) - runner.invoke(cli.app, ["new", "John Doe"]) + runner.invoke(cli.app, ["new", "Jahn Doe"]) markdown_source_files_path = tmp_path / "markdown" theme_source_files_path = tmp_path / "classic" - input_file_path = tmp_path / "John_Doe_CV.yaml" + input_file_path = tmp_path / "Jahn_Doe_CV.yaml" assert markdown_source_files_path.exists() assert theme_source_files_path.exists() @@ -385,7 +385,7 @@ def test_new_command_with_invalid_theme(tmp_path): # change the current working directory to the temporary directory: os.chdir(tmp_path) - result = runner.invoke(cli.app, ["new", "John Doe", "--theme", "invalid_theme"]) + result = runner.invoke(cli.app, ["new", "Jahn Doe", "--theme", "invalid_theme"]) assert "The theme should be one of the following" in result.stdout @@ -400,7 +400,7 @@ def test_new_command_with_invalid_theme(tmp_path): def test_new_command_with_dont_create_files(tmp_path, option, folder_name): # change the current working directory to the temporary directory: os.chdir(tmp_path) - runner.invoke(cli.app, ["new", "John Doe", option]) + runner.invoke(cli.app, ["new", "Jahn Doe", option]) source_files_path = tmp_path / folder_name @@ -414,7 +414,7 @@ def test_new_command_with_only_input_file(tmp_path): cli.app, [ "new", - "John Doe", + "Jahn Doe", "--dont-create-markdown-source-files", "--dont-create-theme-source-files", ], @@ -422,13 +422,35 @@ def test_new_command_with_only_input_file(tmp_path): markdown_source_files_path = tmp_path / "markdown" theme_source_files_path = tmp_path / "classic" - input_file_path = tmp_path / "John_Doe_CV.yaml" + input_file_path = tmp_path / "Jahn_Doe_CV.yaml" assert not markdown_source_files_path.exists() assert not theme_source_files_path.exists() assert input_file_path.exists() +@pytest.mark.parametrize( + "file_or_folder_name", + [ + "John_Doe_CV.yaml", + "markdown", + "classic", + ], +) +def test_new_command_with_existing_files(tmp_path, file_or_folder_name): + # change the current working directory to the temporary directory: + os.chdir(tmp_path) + + if file_or_folder_name == "Jahn_Doe_CV.yaml": + (tmp_path / file_or_folder_name).touch() + else: + (tmp_path / file_or_folder_name).mkdir() + + result = runner.invoke(cli.app, ["new", "Jahn Doe"]) + + assert "already exists!" in result.stdout + + @pytest.mark.parametrize( "based_on", dm.available_themes, diff --git a/tests/test_data_models.py b/tests/test_data_models.py index a1708b4..7318128 100644 --- a/tests/test_data_models.py +++ b/tests/test_data_models.py @@ -410,6 +410,10 @@ def test_invalid_doi(publication_entry, doi): ("Mastodon", "invalidmastodon"), ("Mastodon", "@inva@l@id"), ("Mastodon", "@invalid@ne<>twork.com"), + ("StackOverflow", "invalidusername"), + ("StackOverflow", "invalidusername//"), + ("StackOverflow", "invalidusername/invalid"), + ("YouTube", "invalidusername"), ], ) def test_invalid_social_networks(network, username): @@ -431,6 +435,21 @@ def test_invalid_social_networks(network, username): "4567/myusername", "https://stackoverflow.com/users/4567/myusername", ), + ( + "GitLab", + "myusername", + "https://gitlab.com/myusername", + ), + ( + "ResearchGate", + "myusername", + "https://researchgate.net/profile/myusername", + ), + ( + "YouTube", + "@myusername", + "https://youtube.com/@myusername", + ), ], ) def test_social_network_url(network, username, expected_url): @@ -662,26 +681,50 @@ def test_locale_catalog(): assert dm.locale_catalog == data_model.locale_catalog.model_dump() - # reset the locale catalog - dm.locale_catalog = { - "month": "month", - "months": "months", - "year": "year", - "years": "years", - "present": "present", - "to": "to", - "abbreviations_for_months": [ - "Jan.", - "Feb.", - "Mar.", - "Apr.", - "May", - "June", - "July", - "Aug.", - "Sept.", - "Oct.", - "Nov.", - "Dec.", + +def test_if_local_catalog_resets(): + data_model = dm.get_a_sample_data_model("John Doe") + + data_model.locale_catalog = dm.LocaleCatalog( + month="a", + ) + + assert dm.locale_catalog["month"] == "a" + + data_model = dm.get_a_sample_data_model("John Doe") + + assert dm.locale_catalog["month"] == "month" + + +def test_dictionary_to_yaml(): + input_dictionary = { + "test_list": [ + "a", + "b", + "c", ], + "test_dict": { + "a": 1, + "b": 2, + }, } + yaml_string = dm.dictionary_to_yaml(input_dictionary) + + # load the yaml string + yaml_object = ruamel.yaml.YAML() + output_dictionary = yaml_object.load(yaml_string) + + assert input_dictionary == output_dictionary + + +def test_create_a_sample_yaml_input_file(tmp_path): + input_file_path = tmp_path / "input.yaml" + yaml_contents = dm.create_a_sample_yaml_input_file(input_file_path) + + assert input_file_path.exists() + assert yaml_contents == input_file_path.read_text(encoding="utf-8") + + +def test_default_input_file_doesnt_have_local_catalog(): + yaml_contents = dm.create_a_sample_yaml_input_file() + assert "locale_catalog" not in yaml_contents