예제 #1
0
    def test_execute_calls_read_all_on_storage(self):
        mock_context = self._create_context()

        template_task = self._create_tasks(1)[0]
        template_task.name = 'new name'

        mock_filter = mock.MagicMock()
        mock_filter.is_match = mock.MagicMock(return_value=True)

        command = modifycommand.ModifyCommand(mock_context, mock_filter)
        command.template_task = template_task
        command.execute()

        mock_context.storage.read_all.assert_called_once()
예제 #2
0
    def test_execute_calls_update_on_storage(self):
        tasks = self._create_tasks(3)
        mock_context = self._create_context(tasks)

        template_task = self._create_tasks(1)[0]
        template_task.name = 'new name'

        mock_filter = mock.MagicMock()
        mock_filter.filter_items = mock.MagicMock(return_value=[tasks[1]])

        command = modifycommand.ModifyCommand(mock_context, mock_filter)
        command.template_task = template_task
        command.execute()

        mock_context.storage.update.assert_called_once_with([tasks[1]])
예제 #3
0
    def test_execute_sets_task_name(self):
        tasks = self._create_tasks(3)

        template_task = self._create_tasks(1)[0]
        template_task.name = 'new name'

        mock_context = self._create_context(tasks)

        mock_filter = mock.MagicMock()
        mock_filter.filter_items = mock.MagicMock(return_value=[tasks[1]])

        command = modifycommand.ModifyCommand(mock_context, mock_filter)
        command.template_task = template_task
        command.execute()

        self.assertEqual('new name', tasks[1].name)
예제 #4
0
    def test_execute_does_not_alter_name_when_not_specified(self):
        tasks = self._create_tasks(3)
        tasks[1].name = 'original name'

        template_task = self._create_tasks(1)[0]
        template_task.name = ''

        mock_context = self._create_context(tasks)

        mock_filter = mock.MagicMock()
        mock_filter.filter_items = mock.MagicMock(return_value=[tasks[1]])

        command = modifycommand.ModifyCommand(mock_context, mock_filter)
        command.template_task = template_task
        command.execute()

        self.assertEqual('original name', tasks[1].name)
예제 #5
0
    def test_execute_adds_new_attributes(self):
        attribute_name = 'project'
        attribute_value = 'test'
        tasks = self._create_tasks(3)

        template_task = self._create_tasks(1)[0]
        template_task.name = ''
        template_task.attributes[attribute_name] = attribute_value

        mock_context = self._create_context(tasks)

        mock_filter = mock.MagicMock()
        mock_filter.filter_items = mock.MagicMock(return_value=[tasks[1]])

        command = modifycommand.ModifyCommand(mock_context, mock_filter)
        command.template_task = template_task
        command.execute()

        self.assertEqual(1, len(tasks[1].attributes))
        self.assertTrue(attribute_name in tasks[1].attributes)
        self.assertEqual(attribute_value, tasks[1].attributes[attribute_name])
예제 #6
0
 def test_constructor_sets_properties(self):
     mock_context = mock.Mock()
     mock_filter = mock.Mock()
     command = modifycommand.ModifyCommand(mock_context, mock_filter)
     self.assertEqual(mock_context, command.context)
     self.assertEqual(mock_filter, command.filter)