Пример #1
0
    def test_item_is_not_nth_in_project_returns_False(self):
        t = MagicMock()
        i = MockItem(item_order=2, project_id=1234)
        t.get_items_by_project.return_value = [
            MockItem(item_order=0), MockItem(item_order=1), i
        ]

        ic = ItemIsNthInProjectCriterion(t, 1)

        self.assertFalse(ic.applies_to(i))
        t.get_items_by_project.assert_called_with(1234)
Пример #2
0
    def test_null_action_does_nothing(self):
        item = MockItem()
        original = item.__dict__

        action = NullAction()
        action.apply_to(item)

        self.assertEqual(original, item.__dict__)
Пример #3
0
    def test_label_added_to_item(self):
        item = MockItem()
        label = MockLabel()

        action = AddLabelToItemAction(label)
        action.apply_to(item)

        self.assertIn(label['id'], item['labels'])
Пример #4
0
    def test_label_not_added_to_item_if_it_is_already_present(self):
        label = MockLabel()
        item = MockItem(labels=[label['id']])

        action = AddLabelToItemAction(label)
        action.apply_to(item)

        self.assertIn(label['id'], item['labels'])
        self.assertEquals(1, len(item['labels']))
Пример #5
0
    def test_given_labels_correctly_resolves_them(self):
        self.todoist.get_label_by_id = MagicMock(side_effect=self.mockLabels)

        criterion = LabelsOfItemCriterion(self.todoist, self.mockCriteria)

        self.assertTrue(criterion.applies_to(MockItem(labels=[1, 2])))
        self.assertEquals(
            self.todoist.get_label_by_id.mock_calls,
            [call.get_label_by_id(1), call.get_label_by_id(2)]
        )
        self.assertEquals(self.mockCriteria.applies_to.mock_calls, [call.applies_to(self.mockLabels)])
Пример #6
0
    def test_label_does_not_exist_is_not_passed_to_the_inner_criterion(self):
        self.mockLabels.append(None)
        self.todoist.get_label_by_id = MagicMock(side_effect=self.mockLabels)

        criterion = LabelsOfItemCriterion(self.todoist, self.mockCriteria)

        self.assertTrue(criterion.applies_to(MockItem(labels=[1, 3, 2])))
        self.assertEquals(
            self.todoist.get_label_by_id.mock_calls,
            [call.get_label_by_id(1), call.get_label_by_id(3), call.get_label_by_id(2)]
        )
        self.assertEquals(self.mockCriteria.applies_to.mock_calls, [call.applies_to(self.mockLabels[:2])])
Пример #7
0
    def test_item_has_no_due_date_returns_False(self):
        i = MockItem()

        ic = ItemHasDueDateCriterion()

        self.assertFalse(ic.applies_to(i))
Пример #8
0
 def setUp(self):
     self.todoist = MagicMock()
     self.project_id = 1234
     self.mockItem = MockItem(project_id=self.project_id)
Пример #9
0
    def test_item_has_due_date_returns_True(self):
        i = MockItem(due_date='2016-01-01')

        ic = ItemHasDueDateCriterion()

        self.assertTrue(ic.applies_to(i))
Пример #10
0
 def test_is_False_if_inner_is_True(self):
     tc = TrueCriterion()
     nc = NotCriterion(tc)
     self.assertFalse(nc.applies_to(MockItem('Anything')))
Пример #11
0
 def test_is_True(self):
     tc = TrueCriterion()
     self.assertTrue(tc.applies_to(MockItem('Anything')))
Пример #12
0
 def test_is_True_if_anything_is_True(self):
     fc = FalseCriterion()
     tc = TrueCriterion()
     ac = AnyCriterion([tc, fc])
     self.assertTrue(ac.applies_to(MockItem('Anything')))
Пример #13
0
 def test_is_False_if_everything_is_False(self):
     fc = FalseCriterion()
     fc2 = FalseCriterion()
     ac = AnyCriterion([fc, fc2])
     self.assertFalse(ac.applies_to(MockItem('Anything')))
Пример #14
0
 def test_is_True_if_everything_is_True(self):
     tc = TrueCriterion()
     tc2 = TrueCriterion()
     ac = AllCriterion([tc, tc2])
     self.assertTrue(ac.applies_to(MockItem('Anything')))
Пример #15
0
 def test_is_False_if_anything_is_False(self):
     fc = FalseCriterion()
     tc = TrueCriterion()
     ac = AllCriterion([fc, tc])
     self.assertFalse(ac.applies_to(MockItem('Anything')))
Пример #16
0
 def test_is_False(self):
     fc = FalseCriterion()
     self.assertFalse(fc.applies_to(MockItem('Anything')))