Commit eec92fe0 authored by Arnaud Fontaine's avatar Arnaud Fontaine

ZODB Components: Use regex to check whether a class of the same name as the...

ZODB Components: Use regex to check whether a class of the same name as the Component reference is defined.

Until now, there was a very basic string check which didn't handle such cases:
  class DocumentReferenceAnything():
    pass
  class DocumentReference():
    pass

=> _message_reference_class_not_defined was incorrectly raised.
parent 58d4ab8e
......@@ -34,6 +34,7 @@ from Products.ERP5Type import Permissions
from Products.ERP5Type.ConsistencyMessage import ConsistencyMessage
import zope.interface
import re
from Products.ERP5Type.interfaces.component import IComponent
class DocumentComponent(ComponentMixin, TextContentHistoryMixin):
......@@ -75,19 +76,8 @@ class DocumentComponent(ComponentMixin, TextContentHistoryMixin):
error_list = super(DocumentComponent, self).checkConsistency(*args ,**kw)
reference = self.getReference()
text_content = self.getTextContent()
# Already checked in the parent class
if reference and text_content:
class_definition_str = 'class %s' % reference
try:
sep = text_content[text_content.index(class_definition_str) +
len(class_definition_str)]
except (ValueError, IndexError):
pass
else:
if (sep == ':' or # old-style class
sep == '('): # new-style class
return error_list
if (reference and text_content and # Already checked in the parent class
re.search('[^\s]*class\s+%s\s*[(:]' % reference, text_content) is None):
error_list.append(ConsistencyMessage(
self,
self.getRelativeUrl(),
......
......@@ -2194,9 +2194,12 @@ class TestZodbDocumentComponent(_TestZodbComponent):
def _getValidSourceCode(self, class_name):
return '''from Products.ERP5.Document.Person import Person
class %sAnything:
pass
class %s(Person):
pass
''' % class_name
''' % (class_name, class_name)
def testAtLeastOneClassNamedAfterReference(self):
component = self._newComponent(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment