def test_remote_task_globalindex(self): obj = GlobalindexTask(1231, 'client1') obj.assigned_client = 'client2' obj.is_subtask = False self.replay() self.assertEquals(get_css_class(obj), 'icon-task-remote-task')
def test_forwarding_globalindex(self): obj = GlobalindexTask(1232, 'client1') obj.task_type = 'forwarding_task_type' obj.is_subtask = False self.replay() self.assertEquals(get_css_class(obj), 'contenttype-opengever-inbox-forwarding')
def test_task_globalindex(self): obj = GlobalindexTask(1231, 'client1') obj.assigned_client = 'client1' obj.is_subtask = False self.replay() self.assertEquals(get_css_class(obj), 'contenttype-opengever-task-task')
def test_predecessor_successor_relation(self): task1 = Task(1, 'm1') task2 = Task(2, 'm1') self.layer.session.add(task1) self.layer.session.add(task2) task2.predecessor = task1 self.assertEquals([task2, ], task1.successors)
def check_is_update_to_date(task, sql_task): incorrect_attributes = [] copy = Task(sql_task.int_id, sql_task.admin_unit_id) copy.sync_with(task) for attr in TASK_ATTRIBUTES: if getattr(copy, attr) != getattr(sql_task, attr): incorrect_attributes.append(attr) return incorrect_attributes
def test_remote_subtask_globalindex__responsible(self): # Tests task which is both, remote and subtask, from the # perspective of the responsible (on responsible's client). obj = GlobalindexTask(1231, 'client2') obj.assigned_client = 'client1' obj.is_subtask = True # current-client: client1 self.replay() self.assertEquals(get_css_class(obj), 'icon-task-remote-task')
def test_predecessor_successor_relation(self): task1 = Task(1, 'm1') task2 = Task(2, 'm1') self.layer.session.add(task1) self.layer.session.add(task2) task2.predecessor = task1 self.assertEquals([ task2, ], task1.successors)
def add_task(self, intid, clientid='client1', **kwargs): task = Task(intid, clientid) if kwargs.get('responsible'): task.responsible = kwargs.get('responsible') if kwargs.get('issuer'): task.issuer = kwargs.get('issuer') if kwargs.get('physical_path'): task.physical_path = kwargs.get('physical_path') self.layer.session.add(task) return task
def test_mulitple_successors(self): task1 = Task(1, 'm1') task2 = Task(2, 'm1') task3 = Task(3, 'm1') self.layer.session.add(task1) self.layer.session.add(task2) self.layer.session.add(task3) task2.predecessor = task1 task3.predecessor = task1 self.assertEquals([task2, task3], task1.successors)
def test_successor_is_not_inherited_when_chain_linking(self): task1 = Task(1, 'm1') task2 = Task(2, 'm1') task3 = Task(3, 'm1') self.layer.session.add(task1) self.layer.session.add(task2) self.layer.session.add(task3) task2.predecessor = task1 task3.predecessor = task2 self.assertEquals([task2], task1.successors) self.assertEquals([task3], task2.successors)
def test_unique_id(self): task1 = Task(1, 'm1') self.layer.session.add(task1) with self.assertRaises(IntegrityError) as cm: copy_task1 = Task(1, 'm1') self.layer.session.add(copy_task1) transaction.commit() self.assertIn( '(IntegrityError) columns client_id, int_id are not unique', str(cm.exception)) transaction.abort()
def test_get_type(self): """ Test for get_type method """ # None item_none = [] # Dict item_dict = {'dict': 'dict'} # SQLalchemy object item_sql = Task('id', 'id') # Task-Object item_task = self.create_dummy() directlyProvides(item_task, ITask) # Others item_obj = self.create_dummy() self.replay() view = Overview(self.mock_context, self.mock_request) self.assertEqual(view.get_type(item_none), None) self.assertEqual(view.get_type(item_dict), 'dict') self.assertEqual(view.get_type(item_sql), 'task') self.assertEqual(view.get_type(item_task), 'task') self.assertEqual(view.get_type(item_obj), 'obj')
def test_task_state_wrapper(self): """ Wrap the state-class arount a text """ # SQLalchemy object item_sql = Task('id', 'id') mock_item_sql = self.mocker.proxy(item_sql, spec=False) self.expect(mock_item_sql.review_state).result('state-sql') # Task-Object item_task = self.create_dummy() directlyProvides(item_task, ITask) # Others item_obj = self.create_dummy() mock_wftool = self.mocker.mock() self.mock_tool(mock_wftool, 'portal_workflow') self.expect(mock_wftool.getInfoFor(ANY, ANY)).result('state-task') self.replay() view = Overview(self.mock_context, self.mock_request) sql = view._task_state_wrapper(mock_item_sql, 'wraptext') task = view._task_state_wrapper(item_task, 'wraptext') obj = view._task_state_wrapper(item_obj, 'wraptext') self.assertEqual(obj, '') self.assertEqual(sql, '<span class="wf-state-sql">wraptext</span>') self.assertEqual(task, '<span class="wf-state-task">wraptext</span>')
def task(self, intid, current_admin_unit, sequence_number=1, **kw): arguments = {'issuing_org_unit': 'rr', 'assigned_org_unit': 'bd'} arguments.update(kw) task = Task(intid, current_admin_unit, sequence_number=sequence_number, **arguments) self.session.add(task) return task
def get_sql_task(self): admin_unit_id = get_current_admin_unit().id() current_org_unit_id = get_current_org_unit().id() sequence_number = self.obj.get_sequence_number() assigned_org_unit = self.obj.responsible_client task = Session.query(Task).filter_by( admin_unit_id=admin_unit_id, int_id=self.obj_id).first() if task is None: task = Task(self.obj_id, admin_unit_id, issuing_org_unit=current_org_unit_id, assigned_org_unit=assigned_org_unit, sequence_number=sequence_number, created=self.obj.created().asdatetime()) Session.add(task) return task
def test_accept_forwarding_with_successor_with_dossier(self): create_client('plone') set_current_client_id(self.portal, 'plone') # create fake predecessor predecessor = Task(FAKE_INTID, 'client2') predecessor.physical_path = 'eingangskorb/forwarding-1' predecessor.issuer = 'testuser2' predecessor.responsible_client = 'plone' predecessor.responsible = TEST_USER_ID predecessor.deadline = datetime.now() remote_request = self.mocker.replace('opengever.ogds.base.utils.remote_request') self.expect(remote_request( 'client2', '@@transporter-extract-object-json', path='eingangskorb/forwarding-1', data={}, headers={})).result(FakeResponse(FORWARDING_EXTRACTION)) self.expect(remote_request( 'client2', '@@task-documents-extract', path='eingangskorb/forwarding-1', data={'documents': 'null'}, headers={})).result(FakeResponse(DOCUMENT_EXTRACTION)) # TODO replace any with the realy expected data self.expect(remote_request( 'client2', '@@task-responses-extract', path='eingangskorb/forwarding-1', data=ANY)).result(FakeResponse('[]')) self.expect(remote_request( 'client2', '@@store_forwarding_in_yearfolder', path='eingangskorb/forwarding-1', # data={'response_text': 'This is a message', # 'successor_oguid': u'plone:1231066935', # 'transition': 'forwarding-transition-accept'} data=ANY, )).result(FakeResponse('OK')) self.replay() wft = getToolByName(self.portal, 'portal_workflow') intids = getUtility(IIntIds) session = Session() session.add(predecessor) accept_forwarding_with_successor( self.portal, 'client2:%s' % FAKE_INTID, u'This is a message', dossier=self.dossier) # CHECKS # --------------------- # yearfolder: current_year = datetime.now().year yearfolder = self.inbox.get(str(current_year), None) self.assertTrue(yearfolder) self.assertEquals(yearfolder.title, u'Closed %s' % current_year) # forwarding ... # is stored in the yearfolder forwarding = yearfolder.get('forwarding-1', None) self.assertTrue(forwarding) # and closed self.assertEquals(wft.getInfoFor(forwarding, 'review_state'), 'forwarding-state-closed') # attributes are correctly moved self.assertEquals(forwarding.responsible, u'inbox:plone') # the issuer should be changed to the local inbox group self.assertEquals(forwarding.issuer, u'inbox:plone') # also the response is correctly added response = IResponseContainer(forwarding)[0] self.assertEquals(response.transition, 'forwarding-transition-accept') # task (succesor of the forwarding) task = self.dossier.get('task-1') self.assertTrue(task) self.assertEquals( ISuccessorTaskController(forwarding).get_successors()[0].int_id, intids.getId(task)) # the succesor link is also in the response correctly self.assertEquals( response.successor_oguid, ISuccessorTaskController(task).get_oguid())
def test_task_representation(self): task1 = Task(1, 'm1') self.layer.session.add(task1) self.assertEquals('<Task 1@m1>', repr(task1))
def index_task(obj, event): """Index the given task in opengever.globalindex. """ # Skip this handler when trying to remove a Plone site. Otherwise the # component registry is already gone and we'll run into trouble. if IObjectRemovedEvent.providedBy(event) \ and IPloneSiteRoot.providedBy(event.object): return None parent = aq_parent(aq_inner(obj)) client_id = get_client_id() intids = getUtility(IIntIds) try: int_id = intids.getId(obj) except KeyError: try: # In some case (remote task updating etc) # only the base_object provides an intid. int_id = intids.getId(aq_base(obj)) except KeyError: # The intid event handler didn' create a intid for this object # yet. The event will be fired again after creating the id. return session = Session() try: task = session.query(Task).filter(Task.client_id == client_id).filter( Task.int_id == int_id).one() except NoResultFound: task = Task(int_id, client_id) session.add(task) # title maximum_title_length = Task.title.property.columns[0].type.length title = obj.title if not isinstance(title, unicode): title = title.decode('utf-8') title = title[:maximum_title_length] task.title = title # Generate and store the breadcrumb tooltip breadcrumb_titles = [] breadcrumbs_view = getMultiAdapter((obj, obj.REQUEST), name='breadcrumbs_view') for elem in breadcrumbs_view.breadcrumbs(): if isinstance(elem.get('Title'), unicode): breadcrumb_titles.append(elem.get('Title')) else: breadcrumb_titles.append(elem.get('Title').decode('utf-8')) # we prevent to raise database-error, if we have a too long string # Shorten the breadcrumb_title to: mandant1 > repo1 > ... join_value = ' > ' end_value = '...' maximum_length = Task.breadcrumb_title.property.columns[0].type.length maximum_length -= len(end_value) breadcrumb_title = breadcrumb_titles actual_length = 0 for i, breadcrumb in enumerate(breadcrumb_titles): add_length = len(breadcrumb) + len(join_value) + len(end_value) if (actual_length + add_length) > maximum_length: breadcrumb_title = breadcrumb_titles[:i] breadcrumb_title.append(end_value) break actual_length += len(breadcrumb) + len(join_value) task.breadcrumb_title = join_value.join(breadcrumb_title) url_tool = obj.unrestrictedTraverse('@@plone_tools').url() task.physical_path = '/'.join(url_tool.getRelativeContentPath(obj)) wftool = getToolByName(obj, 'portal_workflow') task.review_state = wftool.getInfoFor(obj, 'review_state') task.icon = obj.getIcon() task.responsible = obj.responsible task.issuer = obj.issuer # we need to have python datetime objects for make it work with sqlite etc. task.deadline = obj.deadline task.completed = obj.date_of_completion task.modified = obj.modified().asdatetime().replace(tzinfo=None) task.task_type = obj.task_type task.is_subtask = parent.portal_type == 'opengever.task.task' task.sequence_number = getUtility(ISequenceNumber).get_number(obj) task.reference_number = IReferenceNumber(obj).get_number() #get the containing_dossier value directly with the indexer catalog = getToolByName(obj, 'portal_catalog') task.containing_dossier = getMultiAdapter( (obj, catalog), IIndexer, name='containing_dossier')() # the dossier_sequence_number index is required for generating lists # of tasks as PDFs (LaTeX) as defined by the customer. task.dossier_sequence_number = get_dossier_sequence_number(obj) task.assigned_client = obj.responsible_client # index the predecessor if obj.predecessor: pred_client_id, pred_init_id = obj.predecessor.split(':', 1) try: predecessor = session.query(Task).filter_by( client_id=pred_client_id, int_id=pred_init_id).one() except NoResultFound: # For some reason the referenced predecessor doesn't exist predecessor = None else: predecessor = None task.predecessor = predecessor # index the principal which have View permission. This is according to the # allowedRolesAndUsers index but it does not car of global roles. allowed_roles = rolesForPermissionOn(View, obj) principals = [] for principal, roles in _mergedLocalRoles(obj).items(): for role in roles: if role in allowed_roles: principals.append(principal.decode('utf-8')) break task.principals = principals
def test_get_type_task(self): self.assertEqual('globalindex_task', self.view.get_type(Task(123, 'foo')))