Exemplo n.º 1
0
    def test_execute_calls_update_on_storage(self):
        tasks = self._create_tasks(3)
        mock_context = self._create_context(tasks)

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

        command = annotatecommand.AnnotateCommand(mock_context, mock_filter)
        command.message = 'message'
        command.execute()

        mock_context.storage.update.assert_called_once_with([tasks[1]])
Exemplo n.º 2
0
    def test_execute_calls_read_all_on_storage(self):
        tasks = self._create_tasks(3)
        mock_context = self._create_context(tasks)

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

        command = annotatecommand.AnnotateCommand(mock_context, mock_filter)
        command.message = 'message'
        command.execute()

        mock_context.storage.read_all.assert_called_once()
Exemplo n.º 3
0
    def test_execute_adds_annotation_with_date(self):
        tasks = self._create_tasks(3)
        mock_context = self._create_context(tasks)

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

        annotation_created_date = datetime.datetime(2019, 1, 1)
        command = annotatecommand.AnnotateCommand(mock_context, mock_filter)
        command.created = annotation_created_date
        command.message = 'message'
        command.execute()

        self.assertEqual(1, len(tasks[1].annotations))
        self.assertEqual('message', tasks[1].annotations[0].message)
        self.assertEqual(annotation_created_date,
                         tasks[1].annotations[0].created)
Exemplo n.º 4
0
    def test_execute_adds_annotation_without_date(self):
        test_start_time = datetime.datetime.now()
        tasks = self._create_tasks(3)
        mock_context = self._create_context(tasks)

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

        command = annotatecommand.AnnotateCommand(mock_context, mock_filter)
        command.message = 'message'
        command.execute()

        test_end_time = datetime.datetime.now()
        self.assertEqual(1, len(tasks[1].annotations))
        self.assertEqual('message', tasks[1].annotations[0].message)
        self.assertGreaterEqual(tasks[1].annotations[0].created,
                                test_start_time)
        self.assertLessEqual(tasks[1].annotations[0].created, test_end_time)
Exemplo n.º 5
0
 def test_constructor_sets_properties(self):
     mock_context = mock.Mock()
     mock_filter = mock.Mock()
     command = annotatecommand.AnnotateCommand(mock_context, mock_filter)
     self.assertEqual(mock_context, command.context)
     self.assertEqual(mock_filter, command.filter)