Ejemplo n.º 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')
Ejemplo n.º 2
0
 def _recursively_delete_group_side_effect(*args, **kwargs):
     """
     Side effect method that creates custom return values for the recursively_delete_group method
     """
     if args[1] == ImageFilenames and args[2]:
         # Create some fake objects that should be removed
         returned_object1 = ImageFilenames()
         returned_object1.id = 1
         returned_object1.filename = '/tmp/test_file_1.jpg'
         returned_object2 = ImageFilenames()
         returned_object2.id = 2
         returned_object2.filename = '/tmp/test_file_2.jpg'
         returned_object3 = ImageFilenames()
         returned_object3.id = 3
         returned_object3.filename = '/tmp/test_file_3.jpg'
         return [returned_object1, returned_object2, returned_object3]
     if args[1] == ImageGroups and args[2]:
         # Change the parent_id that is matched so we don't get into an endless loop
         ImageGroups.parent_id = 0
         # Create a fake group that will be used in the next run
         returned_object1 = ImageGroups()
         returned_object1.id = 1
         return [returned_object1]
     return []
Ejemplo n.º 3
0
 def _recursively_delete_group_side_effect(*args, **kwargs):
     """
     Side effect method that creates custom return values for the recursively_delete_group method
     """
     if args[1] == ImageFilenames and args[2]:
         # Create some fake objects that should be removed
         returned_object1 = ImageFilenames()
         returned_object1.id = 1
         returned_object1.filename = '/tmp/test_file_1.jpg'
         returned_object2 = ImageFilenames()
         returned_object2.id = 2
         returned_object2.filename = '/tmp/test_file_2.jpg'
         returned_object3 = ImageFilenames()
         returned_object3.id = 3
         returned_object3.filename = '/tmp/test_file_3.jpg'
         return [returned_object1, returned_object2, returned_object3]
     if args[1] == ImageGroups and args[2]:
         # Change the parent_id that is matched so we don't get into an endless loop
         ImageGroups.parent_id = 0
         # Create a fake group that will be used in the next run
         returned_object1 = ImageGroups()
         returned_object1.id = 1
         return [returned_object1]
     return []
Ejemplo n.º 4
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))
Ejemplo n.º 5
0
    def test_create_item_from_id(self):
        """
        Test that the create_item_from_id() method returns a valid QTreeWidgetItem with a pre-created ImageFilenames
        """
        # GIVEN: An ImageFilenames that already exists in the database
        image_file = ImageFilenames()
        image_file.id = 1
        image_file.filename = '/tmp/test_file_1.jpg'
        self.media_item.manager = MagicMock()
        self.media_item.manager.get_object_filtered.return_value = image_file
        ImageFilenames.filename = ''

        # WHEN: create_item_from_id() is called
        item = self.media_item.create_item_from_id(1)

        # THEN: A QTreeWidgetItem should be created with the above model object as it's data
        self.assertIsInstance(item, QtWidgets.QTreeWidgetItem)
        self.assertEqual('test_file_1.jpg', item.text(0))
        item_data = item.data(0, QtCore.Qt.UserRole)
        self.assertIsInstance(item_data, ImageFilenames)
        self.assertEqual(1, item_data.id)
        self.assertEqual('/tmp/test_file_1.jpg', item_data.filename)
Ejemplo n.º 6
0
    def create_item_from_id_test(self):
        """
        Test that the create_item_from_id() method returns a valid QTreeWidgetItem with a pre-created ImageFilenames
        """
        # GIVEN: An ImageFilenames that already exists in the database
        image_file = ImageFilenames()
        image_file.id = 1
        image_file.filename = '/tmp/test_file_1.jpg'
        self.media_item.manager = MagicMock()
        self.media_item.manager.get_object_filtered.return_value = image_file
        ImageFilenames.filename = ''

        # WHEN: create_item_from_id() is called
        item = self.media_item.create_item_from_id(1)

        # THEN: A QTreeWidgetItem should be created with the above model object as it's data
        self.assertIsInstance(item, QtGui.QTreeWidgetItem)
        self.assertEqual('test_file_1.jpg', item.text(0))
        item_data = item.data(0, QtCore.Qt.UserRole)
        self.assertIsInstance(item_data, ImageFilenames)
        self.assertEqual(1, item_data.id)
        self.assertEqual('/tmp/test_file_1.jpg', item_data.filename)
Ejemplo n.º 7
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')