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."
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'.")
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}'." )
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
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
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
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."
def test_jujumetadata_missing_file(tmp_path): """No metadata.yaml file at all.""" result = JujuMetadata().run(tmp_path) assert result == JujuMetadata.Result.errors