Exemplo n.º 1
0
def purge_reference_number_mappings(copied_dossier, event):
    """Reset the reference number mapping when copying (or actually pasting)
    dossiers.
    """

    prefix_adapter = IReferenceNumberPrefix(copied_dossier)
    prefix_adapter.purge_mappings()
Exemplo n.º 2
0
def save_reference_number_prefix(obj, event):
    if IDontIssueDossierReferenceNumber.providedBy(obj.REQUEST):
        return

    if IObjectRemovedEvent.providedBy(event):
        return

    parent = aq_parent(aq_inner(obj))
    prefix_adapter = IReferenceNumberPrefix(parent)
    if not prefix_adapter.get_number(obj):
        prefix_adapter.set_number(obj)

    # because we can't control the order of event handlers we have to sync
    # all containing tasks manually
    catalog = api.portal.get_tool('portal_catalog')
    tasks = catalog({
        'path': '/'.join(obj.getPhysicalPath()),
        'object_provides': 'opengever.task.task.ITask',
        'depth': -1
    })
    for task in tasks:
        TaskSqlSyncer(task.getObject(), None).sync()

    # And also proposals
    proposals = catalog({
        'path': '/'.join(obj.getPhysicalPath()),
        'object_provides': 'opengever.meeting.proposal.IProposal',
        'depth': -1
    })
    for proposal in proposals:
        ProposalSqlSyncer(proposal.getObject(), None).sync()

    obj.reindexObject(idxs=['reference'])
Exemplo n.º 3
0
def save_reference_number_prefix(obj, event):
    if IDontIssueDossierReferenceNumber.providedBy(obj.REQUEST):
        return

    if IObjectRemovedEvent.providedBy(event):
        return

    parent = aq_parent(aq_inner(obj))
    prefix_adapter = IReferenceNumberPrefix(parent)
    if not prefix_adapter.get_number(obj):
        prefix_adapter.set_number(obj)

    # because we can't control the order of event handlers we have to sync
    # all containing tasks manually
    catalog = api.portal.get_tool('portal_catalog')
    tasks = catalog({
        'path': '/'.join(obj.getPhysicalPath()),
        'object_provides': 'opengever.task.task.ITask',
        'depth': -1})
    for task in tasks:
        TaskSqlSyncer(task.getObject(), None).sync()

    # And also proposals
    proposals = catalog({
        'path': '/'.join(obj.getPhysicalPath()),
        'object_provides': 'opengever.meeting.proposal.IProposal',
        'depth': -1})
    for proposal in proposals:
        ProposalSqlSyncer(proposal.getObject(), None).sync()

    obj.reindexObject(idxs=['reference'])
Exemplo n.º 4
0
def purge_reference_number_mappings(copied_dossier, event):
    """Reset the reference number mapping when copying (or actually pasting)
    dossiers.
    """

    prefix_adapter = IReferenceNumberPrefix(copied_dossier)
    prefix_adapter.purge_mappings()
    def test_numbering_for_dossiers_starts_always_at_one(self):
        registry = getUtility(IRegistry)
        proxy = registry.forInterface(IReferenceNumberSettings)
        proxy.reference_prefix_starting_point = u'0'

        dossier = create(Builder('dossier').within(self.empty_repofolder))
        adapter = IReferenceNumberPrefix(self.empty_repofolder)

        self.assertEquals(u'1', adapter.get_number(dossier))
    def test_numbering_for_dossiers_starts_always_at_one(self):
        registry = getUtility(IRegistry)
        proxy = registry.forInterface(IReferenceNumberSettings)
        proxy.reference_prefix_starting_point = u'0'

        dossier = create(Builder('dossier').within(self.empty_repofolder))
        adapter = IReferenceNumberPrefix(self.empty_repofolder)

        self.assertEquals(u'1', adapter.get_number(dossier))
Exemplo n.º 7
0
def regenerate_and_reindex_reference_number(obj):
    parent = aq_parent(aq_inner(obj))
    prefix_adapter = IReferenceNumberPrefix(parent)

    prefix_adapter.set_number(obj)

    obj.reindexObject(idxs=['reference'])

    for child in obj.objectValues():
        if IDexterityContent.providedBy(child):
            regenerate_and_reindex_reference_number(child)
Exemplo n.º 8
0
def regenerate_and_reindex_reference_number(obj):
    parent = aq_parent(aq_inner(obj))
    prefix_adapter = IReferenceNumberPrefix(parent)

    prefix_adapter.set_number(obj)

    obj.reindexObject(idxs=['reference'])

    for child in obj.objectValues():
        if IDexterityContent.providedBy(child):
            regenerate_and_reindex_reference_number(child)
    def _put_in_parent_mappings(self, repo_folder):
        changed = False
        parent = aq_parent(aq_inner(repo_folder))
        child = repo_folder
        child_number = IReferenceNumber(child).get_local_number()
        child_intid = self.intids.getId(child)
        ref = IReferenceNumberPrefix(parent)

        is_in_intid_mapping = child_intid in ref.get_prefix_mapping(child)
        if not is_in_intid_mapping:
            ref.set_number(child, number=child_number)
            changed = True

        return changed
Exemplo n.º 10
0
    def test_dossier_returns_reference_prefix_of_the_context(self):
        dossier = create(Builder('dossier'))

        IReferenceNumberPrefix(self.portal).set_number(dossier, number=u'7')

        self.assertEquals(
            u'7', IReferenceNumber(dossier).get_local_number())
Exemplo n.º 11
0
    def _construct_object(self, container, item):
        portal_type = item['_type']
        fti = self._get_fti(portal_type)
        title_args = self._get_title_args(fti, item)

        with NoDossierReferenceNumbersIssued():
            # Create the object without automatically issuing a
            # reference number - we might want to set it explicitly
            obj = createContentInContainer(container, portal_type,
                                           **title_args)

            if IDossierMarker.providedBy(obj):
                prefix_adapter = IReferenceNumberPrefix(container)
                if not prefix_adapter.get_number(obj):
                    # Set the local reference number part for the
                    # dossier if provided in item, otherwise have
                    # the adapter issue the next one
                    local_refnum = item.get('reference_number')
                    if local_refnum is not None:
                        prefix_adapter.set_number(obj, local_refnum)
                    else:
                        prefix_adapter.set_number(obj)

        self._set_guid(obj, item)
        return obj
    def save_new_prefix(self, action):
        data, errors = self.extractData()

        if len(errors) > 0:
            return

        obj = self.context
        parent = aq_parent(aq_inner(obj))

        new_prefix = unicode(data['prefix'])
        old_prefix = IReferenceNumberPrefix(parent).get_number(obj)

        intids = getUtility(IIntIds)
        intid = intids.getId(aq_base(obj))

        prefix_adapter = IReferenceNumberPrefix(parent)

        # Check if prefix already allocated
        prefix_mapping = prefix_adapter.get_prefix_mapping(obj)
        child_mapping = prefix_adapter.get_child_mapping(obj)

        if new_prefix in prefix_mapping.values() or \
        new_prefix in child_mapping.keys():
            raise Exception("This prefix is already allocated!")

        # Save new prefix in both mappings
        prefix_mapping[intid] = new_prefix
        child_mapping[new_prefix] = intid

        # Drop entry for old prefix from child_mapping
        if old_prefix in child_mapping:
            child_mapping.pop(old_prefix)

        if IRepositoryFolder.providedBy(obj):
            # Also change the prefix on the repo folder behavior
            rnp_behavior = IReferenceNumberPrefixBehavior(obj)
            rnp_behavior.reference_number_prefix = new_prefix

        obj.reindexObject()

        IStatusMessage(self.request).addStatusMessage(
            _(u"Reference Number prefix for '%s' "
                "changed to '%s'" % (obj.id, new_prefix)), 'info')

        return self.request.RESPONSE.redirect(self.context.absolute_url())
Exemplo n.º 13
0
    def setUp(self):
        super(TestReferenceNumberAdapter, self).setUp()

        root = create(Builder('repository_root'))
        repo_2 = create(Builder('repository')
                        .within(root)
                        .having(reference_number_prefix=u'2'))
        repo_2_4 = create(Builder('repository')
                          .within(repo_2)
                          .having(reference_number_prefix=u'4'))
        repo_2_4_7 = create(Builder('repository')
                            .within(repo_2_4)
                            .having(reference_number_prefix=u'7'))
        dossier = create(Builder('dossier').within(repo_2_4_7))
        IReferenceNumberPrefix(repo_2_4_7).set_number(dossier, number=u'8')

        self.subdossier = create(Builder('dossier').within(dossier))
        IReferenceNumberPrefix(dossier).set_number(self.subdossier, number=u'2')
Exemplo n.º 14
0
def save_reference_number_prefix(obj, event):
    if IObjectRemovedEvent.providedBy(event):
        return

    parent = aq_parent(aq_inner(obj))
    prefix_adapter = IReferenceNumberPrefix(parent)
    if not prefix_adapter.get_number(obj):
        prefix_adapter.set_number(obj)

    # because we can't control the order of event handlers we have to sync
    # all containing tasks manually
    catalog = api.portal.get_tool("portal_catalog")
    tasks = catalog(
        {"path": "/".join(obj.getPhysicalPath()), "object_provides": "opengever.task.task.ITask", "depth": -1}
    )
    for task in tasks:
        TaskSqlSyncer(task.getObject(), None).sync()

    obj.reindexObject(idxs=["reference"])
Exemplo n.º 15
0
    def _construct_object(self, container, item):
        portal_type = item['_type']
        fti = self._get_fti(portal_type)
        title_args = self._get_title_args(fti, item)

        with NoDossierReferenceNumbersIssued():
            # Create the object without automatically issuing a
            # reference number - we might want to set it explicitly
            obj = createContentInContainer(
                container, portal_type, **title_args)

            if IDossierMarker.providedBy(obj):
                prefix_adapter = IReferenceNumberPrefix(container)
                if not prefix_adapter.get_number(obj):
                    # Set the local reference number part for the
                    # dossier if provided in item, otherwise have
                    # the adapter issue the next one
                    local_refnum = item.get('reference_number')
                    if local_refnum is not None:
                        prefix_adapter.set_number(obj, local_refnum)
                    else:
                        prefix_adapter.set_number(obj)

        self._set_guid(obj, item)
        return obj
Exemplo n.º 16
0
def set_former_reference_after_moving(obj, event):
    """ Use the (hopefully) stored former reference number
    as the real new former reference number. This has to
    be done after the dossier was moved.

    """
    # make sure obj wasn't just created or deleted
    if not event.oldParent or not event.newParent:
        return

    repr = IDossier(obj)
    former_ref_no = repr.temporary_former_reference_number
    IDossier['former_reference_number'].set(repr, former_ref_no)
    # reset temporary former reference number
    IDossier['temporary_former_reference_number'].set(repr, '')

    # setting the new number
    parent = aq_parent(aq_inner(obj))
    prefix_adapter = IReferenceNumberPrefix(parent)
    prefix_adapter.set_number(obj)

    obj.reindexObject(idxs=['reference'])
Exemplo n.º 17
0
    def test_copying_dossier_purges_child_reference_number_mappings(self):
        self.login(self.dossier_responsible)
        subdossier = create(Builder('dossier').within(self.empty_dossier))

        dossier_copy = api.content.copy(source=self.empty_dossier,
                                        target=self.empty_repofolder)

        # subdossier is copied
        self.assertEqual(1, len(dossier_copy.get_subdossiers()))
        subdossier_copy = dossier_copy.get_subdossiers()[0].getObject()

        # copied dossier contains mappings for copied subdossiers starting at
        # 1, the mapping was purged on copy
        ref = IReferenceNumberPrefix(dossier_copy)
        self.assertItemsEqual([u'1'],
                              ref.get_child_mapping(subdossier_copy).keys())

        # there are no more entries for the previous subdossiers
        intids = getUtility(IIntIds)
        prefixed_intids = ref.get_prefix_mapping(subdossier_copy).keys()
        self.assertNotIn(intids.getId(subdossier), prefixed_intids)
        self.assertIn(intids.getId(subdossier_copy), prefixed_intids)
Exemplo n.º 18
0
def set_former_reference_after_moving(obj, event):
    """ Use the (hopefully) stored former reference number
    as the real new former reference number. This has to
    be done after the dossier was moved.

    """
    # make sure obj wasn't just created or deleted
    if not event.oldParent or not event.newParent:
        return

    repr = IDossier(obj)
    former_ref_no = repr.temporary_former_reference_number
    IDossier["former_reference_number"].set(repr, former_ref_no)
    # reset temporary former reference number
    IDossier["temporary_former_reference_number"].set(repr, "")

    # setting the new number
    parent = aq_parent(aq_inner(obj))
    prefix_adapter = IReferenceNumberPrefix(parent)
    prefix_adapter.set_number(obj)

    obj.reindexObject(idxs=["reference"])
Exemplo n.º 19
0
    def test_copying_dossier_purges_child_reference_number_mappings(self):
        dossier = create(Builder("dossier").within(self.source_repo))
        subdossier_1 = create(Builder("dossier").within(dossier))
        subdossier_2 = create(Builder("dossier").within(dossier))

        dossier_copy = api.content.copy(source=dossier, target=self.target_repo)

        # there are two copied subdossiers
        self.assertEqual(2, len(dossier_copy.listFolderContents()))
        subdossier1_copy = dossier_copy.listFolderContents()[0]

        # copied dossier contains mappings for copied subdossiers starting at
        # 1, the mapping was purged on copy
        ref = IReferenceNumberPrefix(dossier_copy)
        ref.get_child_mapping(subdossier1_copy)
        self.assertItemsEqual([u"1", u"2"], ref.get_child_mapping(subdossier1_copy).keys())

        # there are no more entries for the previous subdossiers
        intids = getUtility(IIntIds)
        prefixed_intids = ref.get_prefix_mapping(subdossier1_copy).keys()
        self.assertNotIn(intids.getId(subdossier_1), prefixed_intids)
        self.assertNotIn(intids.getId(subdossier_2), prefixed_intids)
Exemplo n.º 20
0
    def test_copying_dossier_purges_child_reference_number_mappings(self):
        self.login(self.dossier_responsible)
        subdossier = create(Builder('dossier').within(self.empty_dossier))

        dossier_copy = api.content.copy(
            source=self.empty_dossier, target=self.empty_repofolder)

        # subdossier is copied
        self.assertEqual(1, len(dossier_copy.get_subdossiers()))
        subdossier_copy = dossier_copy.get_subdossiers()[0].getObject()

        # copied dossier contains mappings for copied subdossiers starting at
        # 1, the mapping was purged on copy
        ref = IReferenceNumberPrefix(dossier_copy)
        self.assertItemsEqual(
            [u'1'],
            ref.get_child_mapping(subdossier_copy).keys())

        # there are no more entries for the previous subdossiers
        intids = getUtility(IIntIds)
        prefixed_intids = ref.get_prefix_mapping(subdossier_copy).keys()
        self.assertNotIn(intids.getId(subdossier), prefixed_intids)
        self.assertIn(intids.getId(subdossier_copy), prefixed_intids)
Exemplo n.º 21
0
    def test_copying_dossier_purges_child_reference_number_mappings(self):
        dossier = create(Builder('dossier').within(self.source_repo))
        subdossier_1 = create(Builder('dossier').within(dossier))
        subdossier_2 = create(Builder('dossier').within(dossier))

        dossier_copy = api.content.copy(source=dossier,
                                        target=self.target_repo)

        # there are two copied subdossiers
        self.assertEqual(2, len(dossier_copy.listFolderContents()))
        subdossier1_copy = dossier_copy.listFolderContents()[0]

        # copied dossier contains mappings for copied subdossiers starting at
        # 1, the mapping was purged on copy
        ref = IReferenceNumberPrefix(dossier_copy)
        ref.get_child_mapping(subdossier1_copy)
        self.assertItemsEqual([u'1', u'2'],
                              ref.get_child_mapping(subdossier1_copy).keys())

        # there are no more entries for the previous subdossiers
        intids = getUtility(IIntIds)
        prefixed_intids = ref.get_prefix_mapping(subdossier1_copy).keys()
        self.assertNotIn(intids.getId(subdossier_1), prefixed_intids)
        self.assertNotIn(intids.getId(subdossier_2), prefixed_intids)
class TestReferencePrefixAdapter(IntegrationTestCase):

    def setUp(self):
        super(TestReferencePrefixAdapter, self).setUp()
        self.login(self.regular_user)
        self.adapter = IReferenceNumberPrefix(self.leaf_repofolder)

    def test_numbering_starts_at_one_by_default(self):
        self.assertEquals(u'1', self.adapter.get_next_number())

    def test_numbering_starts_at_configured_value_in_registry(self):
        registry = getUtility(IRegistry)
        proxy = registry.forInterface(IReferenceNumberSettings)
        proxy.reference_prefix_starting_point = u'0'
        self.assertEquals(u'0', self.adapter.get_next_number())

    def test_numbering_for_dossiers_starts_always_at_one(self):
        registry = getUtility(IRegistry)
        proxy = registry.forInterface(IReferenceNumberSettings)
        proxy.reference_prefix_starting_point = u'0'

        dossier = create(Builder('dossier').within(self.empty_repofolder))
        adapter = IReferenceNumberPrefix(self.empty_repofolder)

        self.assertEquals(u'1', adapter.get_number(dossier))

    def test_numbering_continues_after_nine(self):
        self.adapter.set_number(self.leaf_repofolder, 9)
        self.assertEquals(u'10', self.adapter.get_next_number())

    def test_numbering_supports_alphanumeric_numbers(self):
        self.adapter.set_number(self.leaf_repofolder, u'A1A15')
        self.assertEquals(u'A1A16', self.adapter.get_next_number())

    def test_set_number_assigns_a_specific_number_to_an_object(self):
        self.assertEquals(u'42',
                          self.adapter.set_number(self.leaf_repofolder, u'42'))
        self.assertEquals(u'42', self.adapter.get_number(self.leaf_repofolder))

    def test_set_number_recycles_old_numbers(self):
        self.adapter.set_number(self.leaf_repofolder, u'42')

        self.assertEquals(u'42', self.adapter.get_number(self.leaf_repofolder))
        self.assertEquals(u'42', self.adapter.set_number(self.leaf_repofolder))
        self.assertEquals(u'42', self.adapter.get_number(self.leaf_repofolder))

    def test_assigned_numbers_are_invalid(self):
        self.adapter.set_number(self.leaf_repofolder, u'3')

        self.assertTrue(self.adapter.is_valid_number(u'2'))
        self.assertTrue(self.adapter.is_valid_number(u'4'))
        self.assertFalse(self.adapter.is_valid_number(u'3'))

    def test_with_object_the_assigned_number_is_valid(self):
        self.adapter.set_number(self.leaf_repofolder, u'A9')
        self.assertTrue(self.adapter.is_valid_number(u'A9', self.leaf_repofolder))

    def test_with_object_numbers_assigned_to_other_objects_are_not_valid(self):
        self.adapter.set_number(self.leaf_repofolder, u'A9')
        self.assertFalse(self.adapter.is_valid_number(u'A9', self.empty_repofolder))

    def test_repository_and_dossier_use_a_seperate_counter(self):
        self.adapter.set_number(self.leaf_repofolder, u'234')

        repository = create(Builder('repository').within(self.leaf_repofolder))
        dossier = create(Builder('dossier').within(self.leaf_repofolder))

        self.assertEquals(u'235', self.adapter.get_next_number(repository))
        self.assertEquals(u'15', self.adapter.get_next_number(dossier))
    def setUp(self):
        super(TestReferencePrefixAdapter, self).setUp()
        self.grant('Contributor')

        self.repository = create(Builder('repository'))
        self.adapter = IReferenceNumberPrefix(self.repository)
Exemplo n.º 24
0
class TestReferencePrefixAdapter(FunctionalTestCase):
    def setUp(self):
        super(TestReferencePrefixAdapter, self).setUp()

        self.repository = create(Builder('repository').titled(u'Position'))
        self.adapter = IReferenceNumberPrefix(self.repository)

    def test_numbering_starts_at_one_by_default(self):
        self.assertEquals(u'1', self.adapter.get_next_number())

    def test_numbering_starts_at_configured_value_in_registry(self):
        registry = getUtility(IRegistry)
        proxy = registry.forInterface(IReferenceNumberSettings)
        proxy.reference_prefix_starting_point = u'0'
        self.assertEquals(u'0', self.adapter.get_next_number())

    def test_numbering_for_dossiers_starts_always_at_one(self):
        registry = getUtility(IRegistry)
        proxy = registry.forInterface(IReferenceNumberSettings)
        proxy.reference_prefix_starting_point = u'0'

        dossier = create(Builder('dossier').within(self.repository))
        self.assertEquals(u'1', self.adapter.get_number(dossier))

    def test_numbering_continues_after_nine(self):
        self.set_numbering_base(u'9')
        self.assertEquals(u'10', self.adapter.get_next_number())

    def test_numbering_supports_alphanumeric_numbers(self):
        self.set_numbering_base(u'A1A15')
        self.assertEquals(u'A1A16', self.adapter.get_next_number())

    def test_set_number_assigns_a_specific_number_to_an_object(self):
        item = self.create_item()
        self.assertEquals(u'42', self.adapter.set_number(item, u'42'))
        self.assertEquals(u'42', self.adapter.get_number(item))

    def test_set_number_recycles_old_numbers(self):
        item = self.create_item()
        self.assertEquals(u'1', self.adapter.get_number(item))
        self.assertEquals(u'1', self.adapter.set_number(item))
        self.assertEquals(u'1', self.adapter.get_number(item))

    def test_non_assigned_numbers_are_valid(self):
        self.create_numbered_item(u'3')

        self.assertTrue(self.adapter.is_valid_number(u'2'))
        self.assertTrue(self.adapter.is_valid_number(u'4'))

    def test_assigned_numbers_are_invalid(self):
        self.create_numbered_item(u'2')

        self.assertFalse(self.adapter.is_valid_number(u'2'))

    def test_with_object_the_assigned_number_is_valid(self):
        item = self.create_numbered_item(u'A9')

        self.assertTrue(self.adapter.is_valid_number(u'A9', item))

    def test_with_object_numbers_assigned_to_other_objects_are_not_valid(self):
        item = self.create_numbered_item(u'A9')
        self.create_numbered_item(u'A10')

        self.assertFalse(self.adapter.is_valid_number(u'A10', item))

    def test_repository_and_dossier_use_a_seperate_counter(self):
        self.create_numbered_item(5)

        dossier = create(Builder('dossier').within(self.repository))
        repository = create(Builder('repository').within(self.repository))

        self.assertEquals(u'1', self.adapter.get_number(dossier))
        self.assertEquals(u'6', self.adapter.get_number(repository))

    def set_numbering_base(self, base):
        self.create_numbered_item(base)

    def create_numbered_item(self, number):
        item = self.create_item()
        self.adapter.set_number(item, number)
        return item

    def create_item(self):
        return create(Builder('repository').within(self.repository))
Exemplo n.º 25
0
def saveReferenceNumberPrefix(obj, event):
    parent = aq_parent(aq_inner(obj))
    prefix_adapter = IReferenceNumberPrefix(parent)
    if not prefix_adapter.get_number(obj):
        prefix_adapter.set_number(obj)
    obj.reindexObject(idxs=['reference'])
class TestReferencePrefixAdapter(IntegrationTestCase):

    def setUp(self):
        super(TestReferencePrefixAdapter, self).setUp()
        self.login(self.regular_user)
        self.adapter = IReferenceNumberPrefix(self.leaf_repofolder)

    def test_numbering_starts_at_one_by_default(self):
        self.assertEquals(u'1', self.adapter.get_next_number())

    def test_numbering_starts_at_configured_value_in_registry(self):
        registry = getUtility(IRegistry)
        proxy = registry.forInterface(IReferenceNumberSettings)
        proxy.reference_prefix_starting_point = u'0'
        self.assertEquals(u'0', self.adapter.get_next_number())

    def test_numbering_for_dossiers_starts_always_at_one(self):
        registry = getUtility(IRegistry)
        proxy = registry.forInterface(IReferenceNumberSettings)
        proxy.reference_prefix_starting_point = u'0'

        dossier = create(Builder('dossier').within(self.empty_repofolder))
        adapter = IReferenceNumberPrefix(self.empty_repofolder)

        self.assertEquals(u'1', adapter.get_number(dossier))

    def test_numbering_continues_after_nine(self):
        self.adapter.set_number(self.leaf_repofolder, 9)
        self.assertEquals(u'10', self.adapter.get_next_number())

    def test_numbering_supports_alphanumeric_numbers(self):
        self.adapter.set_number(self.leaf_repofolder, u'A1A15')
        self.assertEquals(u'A1A16', self.adapter.get_next_number())

    def test_set_number_assigns_a_specific_number_to_an_object(self):
        self.assertEquals(u'42',
                          self.adapter.set_number(self.leaf_repofolder, u'42'))
        self.assertEquals(u'42', self.adapter.get_number(self.leaf_repofolder))

    def test_set_number_recycles_old_numbers(self):
        self.adapter.set_number(self.leaf_repofolder, u'42')

        self.assertEquals(u'42', self.adapter.get_number(self.leaf_repofolder))
        self.assertEquals(u'42', self.adapter.set_number(self.leaf_repofolder))
        self.assertEquals(u'42', self.adapter.get_number(self.leaf_repofolder))

    def test_assigned_numbers_are_invalid(self):
        self.adapter.set_number(self.leaf_repofolder, u'3')

        self.assertTrue(self.adapter.is_valid_number(u'2'))
        self.assertTrue(self.adapter.is_valid_number(u'4'))
        self.assertFalse(self.adapter.is_valid_number(u'3'))

    def test_with_object_the_assigned_number_is_valid(self):
        self.adapter.set_number(self.leaf_repofolder, u'A9')
        self.assertTrue(self.adapter.is_valid_number(u'A9', self.leaf_repofolder))

    def test_with_object_numbers_assigned_to_other_objects_are_not_valid(self):
        self.adapter.set_number(self.leaf_repofolder, u'A9')
        self.assertFalse(self.adapter.is_valid_number(u'A9', self.empty_repofolder))

    def test_repository_and_dossier_use_a_seperate_counter(self):
        self.adapter.set_number(self.leaf_repofolder, u'234')

        repository = create(Builder('repository').within(self.leaf_repofolder))
        dossier = create(Builder('dossier').within(self.leaf_repofolder))

        self.assertEquals(u'235', self.adapter.get_next_number(repository))
        self.assertEquals(u'14', self.adapter.get_next_number(dossier))
 def setUp(self):
     super(TestReferencePrefixAdapter, self).setUp()
     self.login(self.regular_user)
     self.adapter = IReferenceNumberPrefix(self.leaf_repofolder)
    def setUp(self):
        super(TestReferencePrefixAdapter, self).setUp()

        self.repository = create(Builder('repository').titled(u'Position'))
        self.adapter = IReferenceNumberPrefix(self.repository)
Exemplo n.º 29
0
    def get_local_number(self):
        parent = aq_parent(aq_inner(self.context))
        prefix = IReferenceNumberPrefix(parent).get_number(self.context)

        return prefix or ''
    def setUp(self):
        super(TestReferencePrefixAdapter, self).setUp()
        self.grant('Contributor')

        self.repository = create(Builder('repository'))
        self.adapter = IReferenceNumberPrefix(self.repository)
class TestReferencePrefixAdapter(FunctionalTestCase):

    def setUp(self):
        super(TestReferencePrefixAdapter, self).setUp()

        self.repository = create(Builder('repository').titled(u'Position'))
        self.adapter = IReferenceNumberPrefix(self.repository)

    def test_numbering_starts_at_one_by_default(self):
        self.assertEquals(u'1', self.adapter.get_next_number())

    def test_numbering_starts_at_configured_value_in_registry(self):
        registry = getUtility(IRegistry)
        proxy = registry.forInterface(IReferenceNumberSettings)
        proxy.reference_prefix_starting_point = u'0'
        self.assertEquals(u'0', self.adapter.get_next_number())

    def test_numbering_for_dossiers_starts_always_at_one(self):
        registry = getUtility(IRegistry)
        proxy = registry.forInterface(IReferenceNumberSettings)
        proxy.reference_prefix_starting_point = u'0'

        dossier = create(Builder('dossier').within(self.repository))
        self.assertEquals(
            u'1',
            self.adapter.get_number(dossier))

    def test_numbering_continues_after_nine(self):
        self.set_numbering_base(u'9')
        self.assertEquals(u'10', self.adapter.get_next_number())

    def test_numbering_supports_alphanumeric_numbers(self):
        self.set_numbering_base(u'A1A15')
        self.assertEquals(u'A1A16', self.adapter.get_next_number())

    def test_set_number_assigns_a_specific_number_to_an_object(self):
        item = self.create_item()
        self.assertEquals(u'42', self.adapter.set_number(item, u'42'))
        self.assertEquals(u'42', self.adapter.get_number(item))

    def test_set_number_recycles_old_numbers(self):
        item = self.create_item()
        self.assertEquals(u'1', self.adapter.get_number(item))
        self.assertEquals(u'1', self.adapter.set_number(item))
        self.assertEquals(u'1', self.adapter.get_number(item))

    def test_non_assigned_numbers_are_valid(self):
        self.create_numbered_item(u'3')

        self.assertTrue(self.adapter.is_valid_number(u'2'))
        self.assertTrue(self.adapter.is_valid_number(u'4'))

    def test_assigned_numbers_are_invalid(self):
        self.create_numbered_item(u'2')

        self.assertFalse(self.adapter.is_valid_number(u'2'))

    def test_with_object_the_assigned_number_is_valid(self):
        item = self.create_numbered_item(u'A9')

        self.assertTrue(self.adapter.is_valid_number(u'A9', item))

    def test_with_object_numbers_assigned_to_other_objects_are_not_valid(self):
        item = self.create_numbered_item(u'A9')
        self.create_numbered_item(u'A10')

        self.assertFalse(self.adapter.is_valid_number(u'A10', item))

    def test_repository_and_dossier_use_a_seperate_counter(self):
        self.create_numbered_item(5)

        dossier = create(Builder('dossier').within(self.repository))
        repository = create(Builder('repository').within(self.repository))

        self.assertEquals(u'1', self.adapter.get_number(dossier))
        self.assertEquals(u'6', self.adapter.get_number(repository))

    def set_numbering_base(self, base):
        self.create_numbered_item(base)

    def create_numbered_item(self, number):
        item = self.create_item()
        self.adapter.set_number(item, number)
        return item

    def create_item(self):
        return create(Builder('repository').within(self.repository))
Exemplo n.º 32
0
    def setUp(self):
        super(TestReferencePrefixAdapter, self).setUp()

        self.repository = create(Builder('repository').titled(u'Position'))
        self.adapter = IReferenceNumberPrefix(self.repository)
 def setUp(self):
     super(TestReferencePrefixAdapter, self).setUp()
     self.login(self.regular_user)
     self.adapter = IReferenceNumberPrefix(self.leaf_repofolder)