def test_transform_access_error_on_multiple_access(self):
        compound_item = collection.Item()

        compound_item.component_metadata[collection.Metadata.ID] = "123"
        compound_item.component_metadata[collection.Metadata.PATH] = "source"

        compound_item.component_metadata[collection.Metadata.ITEM_NAME] \
            = '00000001'

        collection.Instantiation(category=collection.InstantiationTypes.ACCESS,
                                 parent=compound_item,
                                 files=[
                                     os.path.join("123", "access",
                                                  "123-00000001.jp2"),
                                     os.path.join("123", "access",
                                                  "123-00000001a.jp2")
                                 ])

        collection.Instantiation(
            category=collection.InstantiationTypes.PRESERVATION,
            parent=compound_item,
            files=[
                os.path.join("123", "preservation", "123-00000001.tif"),
                os.path.join("123", "preservation", "123-00000001a.tif"),
            ])
        strategy = packages.hathi_jp2_package.CopyStrategy()

        strategy.convert = Mock()
        with pytest.raises(AssertionError):
            strategy.transform_access_file(compound_item, dest="out")
Beispiel #2
0
    def item(self):
        item = collection.Item()
        item.component_metadata[packager.Metadata.ID] = '99127822912205899'
        item.component_metadata[packager.Metadata.ITEM_NAME] = '001'
        item.component_metadata[packager.Metadata.PATH] = 'somepath'

        access_file = \
            collection.Instantiation(
                parent=item,
                category=packager.InstantiationTypes.ACCESS,
                files=["99127822912205899-001.tif"]
            )
        access_file.component_metadata[packager.Metadata.PATH] = \
            os.path.join("somepath", "access")

        preservation_file = \
            collection.Instantiation(
                parent=item,
                category=packager.InstantiationTypes.PRESERVATION,
                files=["99127822912205899-001.tif"]
            )
        preservation_file.component_metadata[packager.Metadata.PATH] = \
            os.path.join("somepath", "preservation")

        supplementary_data_files = collection.Instantiation(
            parent=item,
            category=packager.InstantiationTypes.SUPPLEMENTARY,
            files=[
                "99127822912205899-001a.txt",
                "99127822912205899-001b.txt",
            ])
        supplementary_data_files.component_metadata[packager.Metadata.PATH] = \
            "somepath"

        return item
    def test_constructor_with_files(self):

        access = collection.Instantiation(
            category=collection.InstantiationTypes.ACCESS,
            files=["somefile.txt"]
        )
        assert isinstance(access, collection.Instantiation)
Beispiel #4
0
    def test_set_title_page(self, delegate):
        combo_box = QtWidgets.QComboBox()
        files = [
            "file1.jp2",
            "file2.jp2",
            "file3.jp2",
        ]
        for file_name in files:
            combo_box.addItem(file_name)

        combo_box.setCurrentText("file2.jp2")
        model = Mock()

        object_record = collection.PackageObject()
        item = collection.Item(object_record)
        instance = collection.Instantiation(parent=item, files=files)

        def get_data(index, role):
            if role == QtCore.Qt.UserRole:
                return object_record

        mock_index = MagicMock()
        model.data = get_data
        delegate.setModelData(combo_box, model, mock_index)
        assert \
            object_record.metadata[collection.Metadata.TITLE_PAGE] == \
            "file2.jp2"
    def build_instance(self, parent, path: str, filename: str, *args,
                       **kwargs) -> None:
        """Build a capture one style instance object."""
        group_id = parent.metadata[Metadata.ID]

        def is_it_an_instance(item: "os.DirEntry[str]") -> bool:
            if not item.is_file():
                return False
            file_name_parts = self.identify_file_name_parts(item.name)
            if file_name_parts is None:
                raise ValueError(
                    f"File does not match expected naming pattern {item.path}")
            item_group = file_name_parts['group']
            item_inst = file_name_parts['part']
            if item_inst != filename:
                return False

            if item_group != group_id:
                return False
            return True

        files = self.locate_tiff_instances(path, is_it_an_instance)

        collection.Instantiation(category=InstantiationTypes.PRESERVATION,
                                 parent=parent,
                                 files=files)
def compound_item():
    new_item = collection.Item()

    new_item.component_metadata[collection.Metadata.ID] = "123"
    new_item.component_metadata[collection.Metadata.PATH] = "source"
    new_item.component_metadata[collection.Metadata.ITEM_NAME] = '00000001'
    collection.Instantiation(
        category=collection.InstantiationTypes.ACCESS,
        parent=new_item,
        files=[os.path.join("123", "access", "123-00000001.jp2")])

    collection.Instantiation(
        category=collection.InstantiationTypes.PRESERVATION,
        parent=new_item,
        files=[os.path.join("123", "preservation", "123-00000001.tif")])
    return new_item
Beispiel #7
0
 def get_data(role):
     if role == QtCore.Qt.UserRole:
         object_record = collection.PackageObject()
         item = collection.Item(object_record)
         instance = collection.Instantiation(parent=item,
                                             files=[
                                                 "file1.jp2",
                                                 "file2.jp2",
                                                 "file3.jp2",
                                             ])
         return object_record
Beispiel #8
0
 def get_data(role):
     if role == QtCore.Qt.UserRole:
         object_record = collection.PackageObject()
         object_record.component_metadata[
             collection.Metadata.TITLE_PAGE] = "file2.jp2"
         item = collection.Item(object_record)
         instance = collection.Instantiation(parent=item,
                                             files=[
                                                 "file1.jp2",
                                                 "file2.jp2",
                                                 "file3.jp2",
                                             ])
         return object_record
def capture_one_item():
    capture_one_tiff = collection.Item()

    capture_one_tiff.component_metadata[collection.Metadata.ID] = "123"
    capture_one_tiff.component_metadata[collection.Metadata.PATH] = "source"
    capture_one_tiff.component_metadata[
        collection.Metadata.ITEM_NAME] = '00000001'

    collection.Instantiation(
        category=collection.InstantiationTypes.PRESERVATION,
        parent=capture_one_tiff,
        files=[os.path.join("123", "123_00000001.tif")])
    return capture_one_tiff
Beispiel #10
0
    def build_instance(self,
                       parent: collection.Item,
                       path: str,
                       filename: str,
                       *args: None,
                       **kwargs: None) -> None:

        new_instance = collection.Instantiation(
            parent=parent,
            category=collection.InstantiationTypes.ACCESS,
            files=[filename]
        )

        new_instance.component_metadata[Metadata.PATH] = path
    def digital_library_object(self):

        new_object = collection.PackageObject()
        new_object.component_metadata[collection.Metadata.ID] = "123"

        new_object.component_metadata[collection.Metadata.PACKAGE_TYPE] = \
            common.PackageTypes.DIGITAL_LIBRARY_COMPOUND

        new_item = collection.Item(parent=new_object)

        new_item.component_metadata[collection.Metadata.ID] = "123"
        new_item.component_metadata[collection.Metadata.PATH] = "source"
        new_item.component_metadata[collection.Metadata.ITEM_NAME] = '00000001'

        collection.Instantiation(
            category=collection.InstantiationTypes.ACCESS,
            parent=new_item,
            files=[os.path.join("123", "access", "123-00000001.jp2")])

        collection.Instantiation(
            category=collection.InstantiationTypes.PRESERVATION,
            parent=new_item,
            files=[os.path.join("123", "preservation", "123-00000001.tif")])
        return new_object
Beispiel #12
0
def test_zip_error(monkeypatch):
    item = collection.Item()
    item.component_metadata[Metadata.PATH] = "somepath.zip"
    instance = collection.Instantiation(parent=item)
    instance._files = [
        "somefile.txt"
    ]
    from zipfile import ZipFile
    import io
    with monkeypatch.context() as mp:
        mp.setattr(ZipFile, "extract", Mock(side_effect=KeyError))
        mp.setattr(ZipFile, "_RealGetContents", Mock())
        mp.setattr(io, "open", MagicMock())

        with pytest.raises(errors.ZipFileException) as error:
            next(instance.get_files())

        assert error.value.src_zip_file == item.metadata[Metadata.PATH] and \
               "somefile.txt" in error.value.problem_files[0]
    def test_transform_access_error_on_multiple_access(self):
        capture_one_tiff = collection.Item()

        capture_one_tiff.component_metadata[collection.Metadata.ID] = "123"

        capture_one_tiff.component_metadata[collection.Metadata.PATH] \
            = "source"

        capture_one_tiff.component_metadata[
            collection.Metadata.ITEM_NAME] = '00000001'

        collection.Instantiation(
            category=collection.InstantiationTypes.PRESERVATION,
            parent=capture_one_tiff,
            files=[
                os.path.join("123", "123_00000001.tif"),
                os.path.join("123", "123_00000001b.tif")
            ])
        strategy = packages.hathi_jp2_package.ConvertStrategy(
            instance_source=collection.InstantiationTypes.PRESERVATION)

        strategy.convert = Mock()
        with pytest.raises(AssertionError):
            strategy.transform_access_file(capture_one_tiff, dest="out")
Beispiel #14
0
 def test_normal_constructor(self):
     access = collection.Instantiation(
         category=collection.InstantiationTypes.ACCESS
     )
     assert access is not None