def test_update_event(self, update_event_mock, get_event_mock): """Test update of event.""" with factories.single_commit(): person = factories.PersonFactory() event = factories.CalendarEventFactory( due_date=date(2015, 1, 15), attendee_id=person.id, description="new description", title="summary", external_event_id="eventId") with freeze_time("2015-01-1 12:00:00"): self.sync._update_event(event) get_event_mock.assert_called_with( calendar_id="primary", event_id="eventId", ) update_event_mock.assert_called_with( event_id="eventId", calendar_id="primary", description="new description", summary="summary", start="2015-01-15", end="2015-01-16", timezone="UTC", attendees=[person.email], ) self.assertEquals(event.last_synced_at.date(), date(2015, 1, 1))
def test_delete_not_synced_event(self, delete_event_mock): """Test delete of unsynced event.""" with factories.single_commit(): person = factories.PersonFactory() event = factories.CalendarEventFactory(due_date=date(2015, 1, 15), attendee_id=person.id, description="description", title="summary") with freeze_time("2015-01-1 12:00:00"): self.sync.sync_cycle_tasks_events() db_event = self.get_event(person.id, event.due_date) self.assertIsNone(db_event) self.assertEqual(delete_event_mock.call_count, 0)
def setup_person_task_event(end_date): """Setup task with person and event.""" with factories.single_commit(): person = factories.PersonFactory() task = wf_factories.CycleTaskGroupObjectTaskFactory( end_date=end_date, ) event = factories.CalendarEventFactory( due_date=end_date, attendee_id=person.id, ) # pylint: disable=protected-access for acl in task._access_control_list: factories.AccessControlPersonFactory(ac_list=acl, person=person) factories.RelationshipFactory(source=task, destination=event) return person, task, event
def test_generate_events_for_task_with_event_no_rel(self): """Test generating events for tasks with event but without relation.""" with factories.single_commit(): person = factories.PersonFactory() task = wf_factories.CycleTaskGroupObjectTaskFactory(end_date=date( 2015, 1, 5), ) factories.CalendarEventFactory( due_date=date(2015, 1, 5), attendee_id=person.id, ) task.add_person_with_role_name(person, u"Task Secondary Assignees") with freeze_time("2015-01-1 12:00:00"): self.builder._preload_data() self.builder._generate_events() db.session.commit() event = self.get_event(person.id, task.end_date) self.assertIsNotNone(event) relationship = self.get_relationship(task.id, event.id) self.assertIsNotNone(relationship)
def test_generate_description_for_event(self): """Test generating description for Calendar Event.""" with factories.single_commit(): person = factories.PersonFactory() event = factories.CalendarEventFactory( due_date=date(2015, 1, 10), attendee_id=person.id, ) first_task = wf_factories.CycleTaskGroupObjectTaskFactory( title=u"unicode ascii title", end_date=date(2015, 1, 10), ) second_task = wf_factories.CycleTaskGroupObjectTaskFactory( title=u"Â тест", end_date=date(2015, 1, 10), ) third_task = wf_factories.CycleTaskGroupObjectTaskFactory( title="some ordinary title", end_date=date(2015, 1, 10), ) factories.RelationshipFactory(source=first_task, destination=event) factories.RelationshipFactory(source=event, destination=second_task) factories.RelationshipFactory(source=event, destination=third_task) task_ids = [first_task.id, second_task.id, third_task.id] self.builder._preload_data() self.builder._generate_description_for_event(event, task_ids) link_not_encoded = ( u'(("Task Status" IN ("Finished","Declined") and ' u'"Needs Verification"="Yes") ' u'or ("Task Status" IN ("Assigned","In Progress"))' u') and "Task Due Date"=01/10/2015' ) expected_description = ( u"You have following tasks due today:\n" u"- Â тест\n" u"- some ordinary title\n" u"- unicode ascii title\n" u"Please click on the link below to review and take action " u"on your task(s) due today:\n" u"<a href='http://localhost/dashboard#!task&query={link}'>Link</a>" ).format(link=urllib.quote(link_not_encoded.encode('utf-8'))) self.assertEquals(event.description, expected_description)
def test_generate_events_for_task_with_event(self): """Test remove relationship to event for overdue task.""" with factories.single_commit(): person = factories.PersonFactory() task = wf_factories.CycleTaskGroupObjectTaskFactory(end_date=date( 2015, 1, 1), ) task.add_person_with_role_name(person, u"Task Assignees") event = factories.CalendarEventFactory( due_date=date(2015, 1, 1), attendee_id=person.id, ) factories.RelationshipFactory(source=task, destination=event) with freeze_time("2015-01-5 12:00:00"): self.builder._preload_data() self.builder._generate_events() db.session.commit() event = self.get_event(person.id, task.end_date) self.assertIsNotNone(event) relationship = self.get_relationship(task.id, event.id) self.assertIsNone(relationship)
def test_delete_event_on_update(self, get_event_mock): """Test update of event.""" with factories.single_commit(): person = factories.PersonFactory() event = factories.CalendarEventFactory( due_date=date(2015, 1, 15), attendee_id=person.id, description="new description", title="summary", external_event_id="eventId") event_id = event.id with freeze_time("2015-01-1 12:00:00"): self.sync._update_event(event) db.session.commit() get_event_mock.assert_called_with( calendar_id="primary", external_event_id="eventId", event_id=event_id, ) db_event = self.get_event(person.id, event.due_date) self.assertIsNone(db_event)