Example #1
0
    def test_files_in_set_and_uncategorized_mixed(self):
        """The CLI should be able to deal with a mixture of files in a set and non-categorized files both at once."""
        test_args = [
            '+', 'set1.jpg', 'file.png', 'otherSet0.gif', 'nextFile.jpg',
            'otherSet1.jpg', '1/2'
        ]
        mock_expand_spot.return_value = (1, 2)
        mock_isfile.return_value = (True)

        def mock_file_in_set_set_one(file):
            if file == 'set1.jpg':
                return (True, 1)
            else:
                return (False, None)

        def mock_file_in_set_set_two(file):
            if file == 'otherSet0.gif':
                return (True, 0)
            elif file == 'otherSet1.jpg':
                return (True, 1)
            else:
                return (False, None)

        other_test_set_one = FileSet(('set', ''), ['set1.jpg'])
        other_test_set_two = FileSet(('otherSet', ''),
                                     ['otherSet0.gif', 'otherSet1.jpg'])
        other_test_set_one.file_in_set = mock_file_in_set_set_one
        other_test_set_two.file_in_set = mock_file_in_set_set_two
        CLI.file_set_cache = [other_test_set_one, other_test_set_two]

        add(self.test_set, test_args)

        assertion_calls = [(mock_add_file_set.assert_any_call,
                            [other_test_set_one, (1, 2), [1]]),
                           (mock_add_file_set.assert_any_call,
                            [other_test_set_two, (2, 3), [0]]),
                           (mock_add_file_set.assert_any_call,
                            [other_test_set_two, (3, 4), [1]])]
        mock_assert_many_msg(
            assertion_calls,
            "The CLI fails to correctly identify and add the files which already belong to another set."
        )
        mock_assert_msg(
            mock_add_files.assert_called_once_with,
            [['file.png', 'nextFile.jpg'], (4, 5)],
            "The CLI fails to correctly identify and add the files which don't belong to any other set."
        )