コード例 #1
0
def test_get_spring_metadata_wrong_number_files(
    spring_metadata_file: Path, spring_metadata: List[dict]
):
    """Test the method that fetches the SPRING metadata from a file when a file is missing"""
    # GIVEN a SPRING metadata file with missing file
    spring_metadata = spring_metadata[1:]
    with open(spring_metadata_file, "w") as outfile:
        outfile.write(json.dumps(spring_metadata))

    # WHEN fetching the content of the file
    with pytest.raises(ValidationError):
        # THEN assert that a validation error is raised
        get_crunchy_metadata(spring_metadata_file)
コード例 #2
0
def test_get_spring_metadata_malformed_info(
    spring_metadata_file: Path, spring_metadata: List[dict]
):
    """Test the method that fetches the SPRING metadata from a file when file is malformed"""
    # GIVEN a SPRING metadata file with missing information
    spring_metadata[0].pop("path")
    with open(spring_metadata_file, "w") as outfile:
        outfile.write(json.dumps(spring_metadata))

    # WHEN fetching the content of the file
    with pytest.raises(ValidationError):
        # THEN assert that a pydantic validation error is raised
        get_crunchy_metadata(spring_metadata_file)
コード例 #3
0
def test_update_date(spring_metadata_file: Path, crunchy_config_dict: dict):
    """Test to update the date in a spring metadata file"""
    # GIVEN the path to a metadata file without any "updated" information and a crunchy api
    spring_metadata: CrunchyMetadata = get_crunchy_metadata(
        spring_metadata_file)
    for file_info in spring_metadata.files:
        assert file_info.updated is None

    # WHEN running the update date function
    update_metadata_date(spring_metadata_file)

    # THEN assert that the "updated" information has been added
    updated_spring_metadata: CrunchyMetadata = get_crunchy_metadata(
        spring_metadata_file)
    for file_info in updated_spring_metadata.files:
        assert file_info.updated is not None
コード例 #4
0
def test_get_spring_metadata(spring_metadata_file: Path):
    """Test the method that fetches the SPRING metadata from a file"""
    # GIVEN a SPRING path and the path to a populated SPRING metadata file
    assert spring_metadata_file.is_file()
    assert spring_metadata_file.exists()

    # WHEN fetching the content of the file
    parsed_content: CrunchyMetadata = get_crunchy_metadata(spring_metadata_file)

    # THEN assert information about the three files is there
    assert len(parsed_content.files) == 3
    # THEN assert a list with the files is returned
    assert isinstance(parsed_content.files, list)
コード例 #5
0
def test_get_spring_metadata_real_file(real_spring_metadata_path: Path,
                                       crunchy_config_dict: dict):
    """Test to parse the content of a real spring metadata file"""
    # GIVEN the path to a file with spring metadata content
    with open(real_spring_metadata_path, "r") as infile:
        content = json.load(infile)

    # WHEN parsing the content
    crunchy_metadata: CrunchyMetadata = get_crunchy_metadata(
        real_spring_metadata_path)

    # THEN assert the content is the same
    assert len(content) == len(crunchy_metadata.files)