Ticket #5560 (closed Bug: fixed)

Opened 8 years ago

Last modified 5 years ago

isIDAutoGenerated fails if you have content types with underscores in the name

Reported by: mt Owned by: alecm
Priority: minor Milestone: 2.5.1
Component: General Version:
Keywords: Cc:

Description

this patch when applied to CMFPlone/tests/testCheckId.py

--- testCheckId.py.orig 2006-06-08 15:01:10.000000000 +0100
+++ testCheckId.py      2006-06-08 15:01:31.000000000 +0100
@@ -19,6 +19,10 @@
     def testAutoGeneratedId(self):
         r = self.portal.plone_utils.isIDAutoGenerated('document.2004-11-09.0123456789')
         self.assertEqual(r, True)
+
+    def testAutoGeneratedIdWithUnderScores(self):
+        r = self.portal.plone_utils.isIDAutoGenerated('my_document.2004-11-09.0123456789')
+        self.assertEqual(r, True)

     def testEmptyId(self):
         r = self.portal.plone_utils.isIDAutoGenerated('')

causes a failure when you run

bin/zopectl test --dir Products/CMFPlone --test-file-pattern testCheckId

from your zopeinstance directory (Plone 2.5-RC1)

this patch applied to CMFPlone/utils.py

--- utils.py.orig       2006-06-08 15:02:55.000000000 +0100
+++ utils.py    2006-06-08 15:13:35.000000000 +0100
@@ -117,7 +117,7 @@
         obj_type, date_created, random_number = id.split('.')
         type = ' '.join(obj_type.split('_'))
         # New autogenerated ids may have a lower case portal type
-        if (type in portaltypes and
+        if ((type in portaltypes or obj_type in portaltypes) and
             DateTime(date_created) and
             float(random_number)):
             return True

fixes the problem in practice (but not in the test case as there is no my_document portal_type) This is a problem if you create content types with underscores, specifically if you want _at_rename_after_creation to work

Change History

comment:1 Changed 8 years ago by mt

Correction, the first testcase failed because the my_document portal type didn't exist in portal_types, this test shows isIDAutoGenerated failing because of underscores

--- testCheckId.py.orig 2006-06-08 15:01:10.000000000 +0100
+++ testCheckId.py      2006-06-08 15:42:35.000000000 +0100
@@ -19,6 +19,13 @@
     def testAutoGeneratedId(self):
         r = self.portal.plone_utils.isIDAutoGenerated('document.2004-11-09.0123456789')
         self.assertEqual(r, True)
+
+    def testAutoGeneratedIdWithUnderScores(self):
+        self.portal.portal_types.manage_addTypeInformation('Factory-based Type Information',
+                                             id='my_document',
+                                             typeinfo_name='CMFCore: Portal Folder')
+        r = self.portal.plone_utils.isIDAutoGenerated('my_document.2004-11-09.0123456789')
+        self.assertEqual(r, True)

     def testEmptyId(self):
         r = self.portal.plone_utils.isIDAutoGenerated('')

comment:2 Changed 8 years ago by wichert

  • Milestone changed from 2.5 to 2.5.x

comment:3 Changed 8 years ago by wichert

  • Status changed from new to closed
  • Resolution set to fixed

(In [10256]) Improve test for autogenerated ids to handle content types with an underscore in their id. fixes #5560

comment:4 Changed 8 years ago by hannosch

  • Milestone changed from 2.5.x to 2.5.1

comment:5 Changed 5 years ago by hannosch

  • Component changed from Content Types to Infrastructure

comment:6 Changed 22 months ago by davisagli

  • Component changed from Infrastructure to General
Note: See TracTickets for help on using tickets.