Example #1
0
def test_jujumetadata_file_corrupted(tmp_path):
    """The metadata.yaml file is not valid YAML."""
    metadata_file = tmp_path / "metadata.yaml"
    metadata_file.write_text(" - \n-")
    linter = JujuMetadata()
    result = linter.run(tmp_path)
    assert result == JujuMetadata.Result.errors
    assert linter.text == "The metadata.yaml file is not a valid YAML file."
Example #2
0
def test_jujumetadata_missing_field_multiple(tmp_path):
    """More than one required field is missing in the metadata file."""
    # metadata file with not all fields
    metadata_file = tmp_path / "metadata.yaml"
    metadata_file.write_text("""
        name: foobar
    """)
    linter = JujuMetadata()
    result = linter.run(tmp_path)
    assert result == JujuMetadata.Result.errors
    assert linter.text == (
        "The metadata.yaml file is missing the following attribute(s): "
        "'description' and 'summary'.")
Example #3
0
def test_jujumetadata_missing_field_simple(tmp_path, to_miss):
    """A required field is missing in the metadata file."""
    included_fields = _mandatory_fields.copy()
    missing = included_fields.pop(to_miss)

    # metadata file with not all fields
    metadata_file = tmp_path / "metadata.yaml"
    content = "\n".join(f"{field}: some text" for field in included_fields)
    metadata_file.write_text(content)
    linter = JujuMetadata()
    result = linter.run(tmp_path)
    assert result == JujuMetadata.Result.errors
    assert linter.text == (
        f"The metadata.yaml file is missing the following attribute(s): '{missing}'."
    )
Example #4
0
def test_jujumetadata_missing_field(tmp_path, fields):
    """A required field is missing in the metadata file."""
    # metdata file with not all fields
    metadata_file = tmp_path / "metadata.yaml"
    metadata_file.write_text(fields)
    result = JujuMetadata().run(tmp_path)
    assert result == JujuMetadata.Result.errors
Example #5
0
def test_jujumetadata_missing_name(tmp_path):
    """A required "name" is missing in the metadata file."""
    # metdata file with not all fields
    metadata_file = tmp_path / "metadata.yaml"
    metadata_file.write_text("""
        summary: Small text.
        description: Lot of text.
    """)
    result = JujuMetadata().run(tmp_path)
    assert result == JujuMetadata.Result.errors
Example #6
0
def test_jujumetadata_all_ok(tmp_path):
    """All conditions ok for JujuMetadata to result ok."""
    # metadata file with proper fields
    metadata_file = tmp_path / "metadata.yaml"
    metadata_file.write_text("""
        name: foobar
        summary: Small text.
        description: Lot of text.
    """)
    result = JujuMetadata().run(tmp_path)
    assert result == JujuMetadata.Result.ok
Example #7
0
def test_jujumetadata_missing_file(tmp_path):
    """No metadata.yaml file at all."""
    linter = JujuMetadata()
    result = linter.run(tmp_path)
    assert result == JujuMetadata.Result.errors
    assert linter.text == "Cannot read the metadata.yaml file."
Example #8
0
def test_jujumetadata_missing_file(tmp_path):
    """No metadata.yaml file at all."""
    result = JujuMetadata().run(tmp_path)
    assert result == JujuMetadata.Result.errors