tests: update

This commit is contained in:
Sina Atalay 2024-05-25 15:53:12 +03:00
parent 321e634679
commit ed9b7f7b09
3 changed files with 98 additions and 29 deletions

View File

@ -285,6 +285,10 @@ def rendercv_filled_curriculum_vitae_data_model(
dm.SocialNetwork(network="Orcid", username="0000-0000-0000-0000"), dm.SocialNetwork(network="Orcid", username="0000-0000-0000-0000"),
dm.SocialNetwork(network="Mastodon", username="@johndoe@example"), dm.SocialNetwork(network="Mastodon", username="@johndoe@example"),
dm.SocialNetwork(network="Twitter", username="johndoe"), 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={ sections={
"Text Entries": [text_entry, text_entry, text_entry], "Text Entries": [text_entry, text_entry, text_entry],

View File

@ -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): 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: # create a new input file (for a CV with multiple pages) in the temporary directory:
os.chdir(tmp_path) os.chdir(tmp_path)
runner.invoke(cli.app, ["new", "John Doe"]) runner.invoke(cli.app, ["new", "Jahn Doe"])
input_file_path = tmp_path / "John_Doe_CV.yaml" input_file_path = tmp_path / "Jahn_Doe_CV.yaml"
run_render_command( run_render_command(
input_file_path, input_file_path,
@ -370,11 +370,11 @@ def test_render_command_with_invalid_arguments(
def test_new_command(tmp_path): def test_new_command(tmp_path):
# change the current working directory to the temporary directory: # change the current working directory to the temporary directory:
os.chdir(tmp_path) 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" markdown_source_files_path = tmp_path / "markdown"
theme_source_files_path = tmp_path / "classic" 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 markdown_source_files_path.exists()
assert theme_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: # change the current working directory to the temporary directory:
os.chdir(tmp_path) 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 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): def test_new_command_with_dont_create_files(tmp_path, option, folder_name):
# change the current working directory to the temporary directory: # change the current working directory to the temporary directory:
os.chdir(tmp_path) 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 source_files_path = tmp_path / folder_name
@ -414,7 +414,7 @@ def test_new_command_with_only_input_file(tmp_path):
cli.app, cli.app,
[ [
"new", "new",
"John Doe", "Jahn Doe",
"--dont-create-markdown-source-files", "--dont-create-markdown-source-files",
"--dont-create-theme-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" markdown_source_files_path = tmp_path / "markdown"
theme_source_files_path = tmp_path / "classic" 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 markdown_source_files_path.exists()
assert not theme_source_files_path.exists() assert not theme_source_files_path.exists()
assert input_file_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( @pytest.mark.parametrize(
"based_on", "based_on",
dm.available_themes, dm.available_themes,

View File

@ -410,6 +410,10 @@ def test_invalid_doi(publication_entry, doi):
("Mastodon", "invalidmastodon"), ("Mastodon", "invalidmastodon"),
("Mastodon", "@inva@l@id"), ("Mastodon", "@inva@l@id"),
("Mastodon", "@invalid@ne<>twork.com"), ("Mastodon", "@invalid@ne<>twork.com"),
("StackOverflow", "invalidusername"),
("StackOverflow", "invalidusername//"),
("StackOverflow", "invalidusername/invalid"),
("YouTube", "invalidusername"),
], ],
) )
def test_invalid_social_networks(network, username): def test_invalid_social_networks(network, username):
@ -431,6 +435,21 @@ def test_invalid_social_networks(network, username):
"4567/myusername", "4567/myusername",
"https://stackoverflow.com/users/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): 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() assert dm.locale_catalog == data_model.locale_catalog.model_dump()
# reset the locale catalog
dm.locale_catalog = { def test_if_local_catalog_resets():
"month": "month", data_model = dm.get_a_sample_data_model("John Doe")
"months": "months",
"year": "year", data_model.locale_catalog = dm.LocaleCatalog(
"years": "years", month="a",
"present": "present", )
"to": "to",
"abbreviations_for_months": [ assert dm.locale_catalog["month"] == "a"
"Jan.",
"Feb.", data_model = dm.get_a_sample_data_model("John Doe")
"Mar.",
"Apr.", assert dm.locale_catalog["month"] == "month"
"May",
"June",
"July", def test_dictionary_to_yaml():
"Aug.", input_dictionary = {
"Sept.", "test_list": [
"Oct.", "a",
"Nov.", "b",
"Dec.", "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