Пример #1
0
    def on_delete_click_test(self, mocked_check_item_selected,
                             mocked_delete_file):
        """
        Test that on_delete_click() works
        """
        # GIVEN: An ImageGroups object and mocked functions
        mocked_check_item_selected.return_value = True
        test_image = ImageFilenames()
        test_image.id = 1
        test_image.group_id = 1
        test_image.filename = 'imagefile.png'
        self.media_item.manager = MagicMock()
        self.media_item.service_path = ''
        self.media_item.list_view = MagicMock()
        mocked_row_item = MagicMock()
        mocked_row_item.data.return_value = test_image
        mocked_row_item.text.return_value = ''
        self.media_item.list_view.selectedItems.return_value = [
            mocked_row_item
        ]

        # WHEN: Calling on_delete_click
        self.media_item.on_delete_click()

        # THEN: delete_file should have been called twice
        self.assertEquals(mocked_delete_file.call_count, 2,
                          'delete_file() should have been called twice')
Пример #2
0
    def save_new_images_list(self, images_list, group_id=0, reload_list=True):
        """
        Convert a list of image filenames to ImageFilenames objects and save them in the database.

        :param images_list: A List of strings containing image filenames
        :param group_id: The ID of the group to save the images in
        :param reload_list: This boolean is set to True when the list in the interface should be reloaded after saving
        the new images
        """
        for filename in images_list:
            if not isinstance(filename, str):
                continue
            log.debug('Adding new image: %s', filename)
            image_file = ImageFilenames()
            image_file.group_id = group_id
            image_file.filename = str(filename)
            self.manager.save_object(image_file)
            self.main_window.increment_progress_bar()
        if reload_list and images_list:
            self.load_full_list(self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename))
Пример #3
0
    def save_new_images_list(self, image_paths, group_id=0, reload_list=True):
        """
        Convert a list of image filenames to ImageFilenames objects and save them in the database.

        :param list[Path] image_paths: A List of file paths to image
        :param group_id: The ID of the group to save the images in
        :param reload_list: This boolean is set to True when the list in the interface should be reloaded after saving
            the new images
        """
        for image_path in image_paths:
            if not isinstance(image_path, Path):
                continue
            log.debug('Adding new image: {name}'.format(name=image_path))
            image_file = ImageFilenames()
            image_file.group_id = group_id
            image_file.file_path = image_path
            self.manager.save_object(image_file)
            self.main_window.increment_progress_bar()
        if reload_list and image_paths:
            self.load_full_list(
                self.manager.get_all_objects(
                    ImageFilenames, order_by_ref=ImageFilenames.file_path))
Пример #4
0
    def test_on_delete_click(self, mocked_check_item_selected, mocked_delete_file):
        """
        Test that on_delete_click() works
        """
        # GIVEN: An ImageGroups object and mocked functions
        mocked_check_item_selected.return_value = True
        test_image = ImageFilenames()
        test_image.id = 1
        test_image.group_id = 1
        test_image.filename = 'imagefile.png'
        self.media_item.manager = MagicMock()
        self.media_item.service_path = ''
        self.media_item.list_view = MagicMock()
        mocked_row_item = MagicMock()
        mocked_row_item.data.return_value = test_image
        mocked_row_item.text.return_value = ''
        self.media_item.list_view.selectedItems.return_value = [mocked_row_item]

        # WHEN: Calling on_delete_click
        self.media_item.on_delete_click()

        # THEN: delete_file should have been called twice
        self.assertEquals(mocked_delete_file.call_count, 2, 'delete_file() should have been called twice')