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] += "@context3" # act controller.showFilters(file) # assert self.assertEquals(7, len(view.filters)) sortedFilter = sorted(view.filters, key=lambda filter: filter.text) print(sortedFilter) self.assertEquals(1, len(view.selectedFilters)) # Due filters are not sorted filter1_text = sortedFilter[3].text self.assertEqual("context1 (2)", filter1_text) expectedselectedfilter = original_filter0.text self.assertSequenceEqual(expectedselectedfilter, view.selectedFilters[0].text)
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(6, len(view.filters), 'There should be 6 filters (actual: %d)' % len(view.filters)) filter = sortedFilter[0] self.assertIsInstance(filter, DueThisMonthFilter, 'Filter #1 should be instance of DueThisMonthFilter (actual: %s)' % str(type(filter))) self.assertEqual(filter.text, 'This month (2)', 'Filter #1 text should be "This month" (actual: "%s")' % filter.text) filter = sortedFilter[1] self.assertIsInstance(filter, DueThisWeekFilter, 'Filter #2 should be instance of DueThisWeekFilter (actual: %s)' % str(type(filter))) self.assertEqual(filter.text, 'This week (2)', 'Filter #2 text should be "This week" (actual: "%s")' % filter.text) filter = sortedFilter[2] self.assertIsInstance(filter, DueTodayFilter, 'Filter #3 should be instance of DueTodayFilter (actual: %s)' % str(type(filter))) self.assertEqual(filter.text, 'Today (2)', 'Filter #3 text should be "Today" (actual: "%s")' % filter.text) filter = sortedFilter[3] self.assertIsInstance(filter, ContextFilter, 'Filter #4 should be instance of ContextFilter (actual: %s)' % str(type(filter))) self.assertEqual(filter.text, 'context1 (2)', 'Filter #4 text should be "context1" (actual: "%s")' % filter.text) filter = sortedFilter[4] self.assertIsInstance(filter, ContextFilter, 'Filter #5 should be instance of ContextFilter (actual: %s)' % str(type(filter))) self.assertEqual(filter.text, 'context2 (2)', 'Filter #5 text should be "%s" (actual: context2)' % filter.text) filter = sortedFilter[5] self.assertIsInstance(filter, ProjectFilter, 'Filter #6 should be instance of ProjectFilter (actual: %s)' % str(type(filter))) self.assertEqual(filter.text, 'project1 (1)', 'Filter #6 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] = tasklib.Task(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))
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)) self.assertIsInstance(view.selectedFilters[0], IncompleteTasksFilter) self.assertEqual(6, len(view.filters)) filter = sortedFilter[0] self.assertIsInstance(filter, DueThisMonthFilter) self.assertEqual(filter.text, 'This month (2)') filter = sortedFilter[1] self.assertIsInstance(filter, DueThisWeekFilter) self.assertEqual(filter.text, 'This week (2)') filter = sortedFilter[2] self.assertIsInstance(filter, DueTodayFilter) self.assertEqual(filter.text, 'Today (2)') filter = sortedFilter[3] self.assertIsInstance(filter, IncompleteTasksWithContextsFilter) self.assertEqual(filter.text, 'context1 (2)') filter = sortedFilter[4] self.assertIsInstance(filter, IncompleteTasksWithContextsFilter) self.assertEqual(filter.text, 'context2 (2)') filter = sortedFilter[5] self.assertIsInstance(filter, IncompleteTasksWithProjectsFilter) self.assertEqual(filter.text, 'project1 (1)')
def _initFiltersTree(self): controller = self._filters_tree_controller = \ FiltersTreeController(self._view.filters_tree_view) controller.filterSelectionChanged.connect( self._onFilterSelectionChanged)