def test_add_sections(self): sections = [asana_mailer.Section('One'), asana_mailer.Section('Two')] self.project.add_sections(sections) self.assertEquals(self.project.sections, sections) self.project.sections = [] list_with_non_sections = [1, 2, 3] list_with_non_sections.extend(sections) self.project.add_sections(list_with_non_sections) self.assertEquals(self.project.sections, sections)
def test_filter_tasks(self): current_time_utc = datetime.datetime.now(dateutil.tz.tzutc()) now = current_time_utc.isoformat() no_tasks = asana_mailer.Section('No Tasks') section_with_tasks = asana_mailer.Section('Some Tasks') incomplete_task_with_tags = asana_mailer.Task( u'Do Work With Tags', u'test_user', False, dateutil.parser.parse(now), u'test_description', dateutil.parser.parse(now), [u'Tag #{}'.format(i) for i in xrange(5)], [ {u'text': u'blah', u'type': u'comment'}, {u'text': u'blah2', u'type': u'not_a_comment'} ] ) incomplete_task = asana_mailer.Task( u'More Work', None, False, None, u'more_test_description', None, [], [ {u'text': u'blah', u'type': 'comment'}, {u'text': u'blah3', u'type': 'comment'} ] ) section_with_tasks.add_task(incomplete_task) self.project.sections = [no_tasks, section_with_tasks] self.project.filter_tasks(current_time_utc) self.assertEquals(len(self.project.sections), 1) self.assertEquals(len(self.project.sections[0].tasks), 1) # Section Filters section_filters = ('None of these tasks:',) self.project.filter_tasks( current_time_utc, section_filters=section_filters) self.assertEquals(len(self.project.sections), 0) # Task Filters task_filters = frozenset((u'Tag #1',)) section_with_tasks.add_task(incomplete_task_with_tags) self.project.sections = [no_tasks, section_with_tasks] self.project.filter_tasks(current_time_utc, task_filters=task_filters) self.assertEquals(len(self.project.sections), 1) self.assertEquals(len(self.project.sections[0].tasks), 1)
def test_init(self): self.assertEqual(self.section.name, 'Test Section') self.assertEqual(self.section.tasks, []) self.section = asana_mailer.Section('Test Section', [1, 2, 3]) self.assertEqual(self.section.name, 'Test Section') self.assertEqual(self.section.tasks, [1, 2, 3])
def setUp(self): self.section = asana_mailer.Section('Test Section')
def test_add_section(self): self.project.add_section('test') self.assertNotIn('test', self.project.sections) new_section = asana_mailer.Section('New Section') self.project.add_section(new_section) self.assertIn(new_section, self.project.sections)
def test_create_project(self, mock_create_sections, mock_filter_tasks): mock_asana = mock.MagicMock() current_time_utc = datetime.datetime.now(dateutil.tz.tzutc()) now = current_time_utc.isoformat() project_json = { u'name': 'My Project', u'notes': 'My Project Description' } project_tasks_json = [ { 'id': u'123', u'name': u'Test Section:', u'assignee': None, u'completed': False, u'notes': u'test_description', u'due_on': None, u'tags': [] }, { u'id': u'456', u'name': u'More Work', u'assignee': None, u'completed': False, u'notes': u'more_test_description', u'due_on': None, u'tags': [] }, ] task_comments_json = ( ( {u'text': u'blah', u'type': u'comment'}, {u'text': u'blah2', u'type': u'not_a_comment'} ), ( {u'text': u'blah', u'type': 'comment'}, {u'text': u'blah3', u'type': 'comment'} ) ) all_calls = [project_json, project_tasks_json] all_calls.extend(task_comments_json) mock_asana.get.side_effect = all_calls new_section = asana_mailer.Section(u'Test Section:') new_tasks = ( asana_mailer.Task( u'Do Work', u'test_user', True, dateutil.parser.parse(now), u'test_description', dateutil.parser.parse(now), [u'Tag #{}'.format(i) for i in xrange(5)], [ {u'text': u'blah', u'type': u'comment'}, {u'text': u'blah2', u'type': u'not_a_comment'} ] ), asana_mailer.Task( u'More Work', None, False, None, u'more_test_description', None, [], [ {u'text': u'blah', u'type': 'comment'}, {u'text': u'blah3', u'type': 'comment'} ] ) ) task_comments = { u'123': [ {u'text': u'blah', u'type': u'comment'}, ], u'456': [ {u'text': u'blah', u'type': 'comment'}, {u'text': u'blah3', u'type': 'comment'} ] } new_section.add_tasks(new_tasks) new_sections = [new_section] mock_create_sections.return_value = new_sections # No Filters new_project = asana_mailer.Project.create_project( mock_asana, u'123', current_time_utc) self.assertEquals(new_project.sections, new_sections) mock_create_sections.assert_called_once_with( project_tasks_json, task_comments) mock_filter_tasks.assert_called_once_with( current_time_utc, section_filters=None, task_filters=None) # Completed Lookback mock_create_sections.return_value = new_sections mock_asana.get.side_effect = all_calls lookback_hours = 10 new_project = asana_mailer.Project.create_project( mock_asana, u'123', current_time_utc, completed_lookback_hours=lookback_hours) completed_since = (current_time_utc - datetime.timedelta( hours=lookback_hours)).replace(microsecond=0).isoformat() mock_asana.get.assert_any_call( 'project_tasks', {'project_id': u'123'}, expand='.', params={'completed_since': completed_since}) # Section Filters section_filters = (u'Other Section:',) mock_filter_tasks.reset_mock() mock_create_sections.reset_mock() mock_asana.get.side_effect = all_calls new_project = asana_mailer.Project.create_project( mock_asana, u'123', current_time_utc, section_filters=section_filters) self.assertEquals(new_project.sections, new_sections) mock_create_sections.assert_called_once_with( project_tasks_json, {}) mock_filter_tasks.assert_called_once_with( current_time_utc, section_filters=section_filters, task_filters=None) # Task Filters mock_filter_tasks.reset_mock() mock_create_sections.reset_mock() mock_asana.get.side_effect = all_calls task_filters = [u'Tag #1'] new_project = asana_mailer.Project.create_project( mock_asana, u'123', current_time_utc, task_filters=task_filters) self.assertEquals(new_project.sections, new_sections) mock_create_sections.assert_called_once_with( project_tasks_json, {}) mock_filter_tasks.assert_called_once_with( current_time_utc, section_filters=None, task_filters=task_filters) all_calls[-1] = ( {u'text': u'blah', u'type': 'not_a_comment'}, {u'text': u'blah3', u'type': 'not_a_comment'} ) # Task with no comments mock_filter_tasks.reset_mock() mock_create_sections.reset_mock() mock_asana.get.side_effect = all_calls new_project = asana_mailer.Project.create_project( mock_asana, u'123', current_time_utc) self.assertEquals(new_project.sections, new_sections) remove_not_comments = dict(task_comments) del remove_not_comments[u'456'] mock_create_sections.assert_called_once_with( project_tasks_json, remove_not_comments) mock_filter_tasks.assert_called_once_with( current_time_utc, section_filters=None, task_filters=None)