def test_showFilters(self):
        # arrange
        view = FakeTreeView()
        controller = FiltersTreeController(view)
        file = self._createMockFile()
        
        # act
        controller.showFilters(file)
        
        # assert
        self.assertEqual(1, len(view.selectedFilters),
            'There should be only 1 selected filter (actual: %s)' % view.selectedFilters)
        self.assertIsInstance(view.selectedFilters[0], IncompleteTasksFilter,
            'selected filter #1 should be instance of IncompleteTasksFilter (actual: %s)' % view.selectedFilters[0])
        
        self.assertEqual(3, len(view.filters),
            'There should be 3 filters (actual: %d)' % len(view.filters))
        filter = view.filters[0]
        self.assertIsInstance(filter, ContextFilter,
            'Filter #1 should be instance of ContextFilter (actual: %s)' % str(type(filter)))
        self.assertEqual(filter.text, 'context1',
            'Filter #1 text should be "%s" (actual: context1)' % filter.text)

        filter = view.filters[1]
        self.assertIsInstance(filter, ContextFilter,
            'Filter #2 should be instance of ContextFilter (actual: %s)' % str(type(filter)))
        self.assertEqual(filter.text, 'context2',
            'Filter #2 text should be "%s" (actual: context2)' % filter.text)
        
        filter = view.filters[2]
        self.assertIsInstance(filter, ProjectFilter,
            'Filter #2 should be instance of ProjectFilter (actual: %s)' % str(type(filter)))
        self.assertEqual(filter.text, 'project1',
            'Filter #2 text should be "%s" (actual: project1)' % filter.text)
Esempio n. 2
0
    def test_showFilters(self):
        # arrange
        view = FakeTreeView()
        controller = FiltersTreeController(view)
        file = self._createMockFile()

        # act
        controller.showFilters(file)

        sortedFilter = sorted(view.filters, key=lambda filter: filter.text)

        # assert
        self.assertEqual(
            1, len(view.selectedFilters),
            'There should be only 1 selected filter (actual: %s)' %
            view.selectedFilters)
        self.assertIsInstance(
            view.selectedFilters[0], IncompleteTasksFilter,
            'selected filter #1 should be instance of IncompleteTasksFilter (actual: %s)'
            % view.selectedFilters[0])

        self.assertEqual(
            3, len(view.filters),
            'There should be 3 filters (actual: %d)' % len(view.filters))
        filter = sortedFilter[0]
        self.assertIsInstance(
            filter, ContextFilter,
            'Filter #1 should be instance of ContextFilter (actual: %s)' %
            str(type(filter)))
        self.assertEqual(
            filter.text, 'context1 (2)',
            'Filter #1 text should be "context1" (actual: "%s")' % filter.text)

        filter = sortedFilter[1]
        self.assertIsInstance(
            filter, ContextFilter,
            'Filter #2 should be instance of ContextFilter (actual: %s)' %
            str(type(filter)))
        self.assertEqual(
            filter.text, 'context2 (2)',
            'Filter #2 text should be "%s" (actual: context2)' % filter.text)

        filter = sortedFilter[2]
        self.assertIsInstance(
            filter, ProjectFilter,
            'Filter #2 should be instance of ProjectFilter (actual: %s)' %
            str(type(filter)))
        self.assertEqual(
            filter.text, 'project1 (1)',
            'Filter #2 text should be "%s" (actual: project1)' % filter.text)
    def test_showFilters_afterAddingNewContext(self):
        # arrange
        view = FakeTreeView()
        controller = FiltersTreeController(view)
        file = self._createMockFile()
        controller.showFilters(file)
        original_filter0 = view.filters[0]
        view.clearSelection()
        view.selectFilter(view.filters[0])
        file.tasks[2].text += " @context3"
        
        # act
        controller.showFilters(file)
        
        # assert
        self.assertNotEqual(view.filters[0], original_filter0,
                            'A new filter was not created (expected: %s, actual: %s)' %
                            (view.filters[0], original_filter0))

        # self.assertNotEqual(view.selectedFilters[0], original_filter0, 
        #    'The old selected filter is still selected (expected: %s, actual: %s)' % 
        #        (view.selectedFilters[0], original_filter0))
        
        self.assertEquals(
            4, len(view.filters),
            'There should be 4 filters (actual: %s)' % view.selectedFilters)

        sortedFilter = sorted(view.filters, key=lambda filter: filter.text)

        filter1_text = sortedFilter[0].text
        self.assertEqual("context1 (2)", filter1_text,
                         'Filter #1 context should be "context1 (2)" (actual: "%s")' % filter1_text)

        self.assertEquals(
            1, len(view.selectedFilters),
            'There should be 1 selected filters (actual: %s)' % view.selectedFilters)
        
        expectedSelectedFilters = [sortedFilter[1]]
        self.assertSequenceEqual(
            expectedSelectedFilters,
            view.selectedFilters,
            'Wrong selected filters (expected: %s, actual: %s)' % 
            (str(expectedSelectedFilters), view.selectedFilters))
    def test_showFilters_afterAddingNewContext(self):
        # arrange
        view = FakeTreeView()
        controller = FiltersTreeController(view)
        file = self._createMockFile()
        controller.showFilters(file)
        original_filter0 = view.filters[0]
        view.clearSelection()
        view.selectFilter(view.filters[0])
        file.tasks[2].text += " @context3"

        # act
        controller.showFilters(file)

        # assert
        self.assertEquals(
            4, len(view.filters),
            'There should be 4 filters (actual: %s)' % view.selectedFilters)

        sortedFilter = sorted(view.filters, key=lambda filter: filter.text)
        print(sortedFilter)

        self.assertEquals(
            1, len(view.selectedFilters),
            'There should be 1 selected filters (actual: %s)' % view.selectedFilters)

        filter1_text = sortedFilter[0].text
        self.assertEqual("context1 (2)", filter1_text,
                         'Filter #1 context should be "context1 (2)" (actual: "%s")' % filter1_text)

        expectedselectedfilter = original_filter0.text
        self.assertSequenceEqual(
            expectedselectedfilter,
            view.selectedFilters[0].text,
            'Wrong selected filters (expected: %s, actual: %s)' %
            (expectedselectedfilter, view.selectedFilters))
Esempio n. 5
0
    def test_showFilters_afterAddingNewContext(self):
        # arrange
        view = FakeTreeView()
        controller = FiltersTreeController(view)
        file = self._createMockFile()
        controller.showFilters(file)
        original_filter0 = view.filters[0]
        view.clearSelection()
        view.selectFilter(view.filters[0])
        file.tasks[2].text += " @context3"

        # act
        controller.showFilters(file)

        # assert
        self.assertNotEqual(
            view.filters[0], original_filter0,
            'A new filter was not created (expected: %s, actual: %s)' %
            (view.filters[0], original_filter0))

        # self.assertNotEqual(view.selectedFilters[0], original_filter0,
        #    'The old selected filter is still selected (expected: %s, actual: %s)' %
        #        (view.selectedFilters[0], original_filter0))

        self.assertEquals(
            4, len(view.filters),
            'There should be 4 filters (actual: %s)' % view.selectedFilters)

        sortedFilter = sorted(view.filters, key=lambda filter: filter.text)

        filter1_text = sortedFilter[0].text
        self.assertEqual(
            "context1 (2)", filter1_text,
            'Filter #1 context should be "context1 (2)" (actual: "%s")' %
            filter1_text)

        self.assertEquals(
            1, len(view.selectedFilters),
            'There should be 1 selected filters (actual: %s)' %
            view.selectedFilters)

        expectedSelectedFilters = [sortedFilter[1]]
        self.assertSequenceEqual(
            expectedSelectedFilters, view.selectedFilters,
            'Wrong selected filters (expected: %s, actual: %s)' %
            (str(expectedSelectedFilters), view.selectedFilters))
Esempio n. 6
0
    def test_showFilters_afterAddingNewContext(self):
        # arrange
        view = FakeTreeView()
        controller = FiltersTreeController(view)
        file = self._createMockFile()
        controller.showFilters(file)
        original_filter0 = view.filters[0]
        view.clearSelection()
        view.selectFilter(view.filters[0])
        file.tasks[2].text += " @context3"

        # act
        controller.showFilters(file)

        # assert
        self.assertEquals(
            7, len(view.filters),
            'There should be 7 filters (actual: %s)' % view.selectedFilters)

        sortedFilter = sorted(view.filters, key=lambda filter: filter.text)
        print(sortedFilter)

        self.assertEquals(
            1, len(view.selectedFilters),
            'There should be 1 selected filters (actual: %s)' %
            view.selectedFilters)

        # Due filters are not sorted
        filter1_text = sortedFilter[3].text
        self.assertEqual(
            "context1 (2)", filter1_text,
            'Filter #1 context should be "context1 (2)" (actual: "%s")' %
            filter1_text)

        expectedselectedfilter = original_filter0.text
        self.assertSequenceEqual(
            expectedselectedfilter, view.selectedFilters[0].text,
            'Wrong selected filters (expected: %s, actual: %s)' %
            (expectedselectedfilter, view.selectedFilters))