Commit 32a7deb4 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 as the first class was considered.
parent 0c7a763e
...@@ -34,6 +34,7 @@ from Products.ERP5Type import Permissions ...@@ -34,6 +34,7 @@ from Products.ERP5Type import Permissions
from Products.ERP5Type.ConsistencyMessage import ConsistencyMessage from Products.ERP5Type.ConsistencyMessage import ConsistencyMessage
import zope.interface import zope.interface
import re
from Products.ERP5Type.interfaces.component import IComponent from Products.ERP5Type.interfaces.component import IComponent
class DocumentComponent(ComponentMixin, TextContentHistoryMixin): class DocumentComponent(ComponentMixin, TextContentHistoryMixin):
...@@ -75,19 +76,8 @@ class DocumentComponent(ComponentMixin, TextContentHistoryMixin): ...@@ -75,19 +76,8 @@ class DocumentComponent(ComponentMixin, TextContentHistoryMixin):
error_list = super(DocumentComponent, self).checkConsistency(*args ,**kw) error_list = super(DocumentComponent, self).checkConsistency(*args ,**kw)
reference = self.getReference() reference = self.getReference()
text_content = self.getTextContent() text_content = self.getTextContent()
# Already checked in the parent class if (reference and text_content and # Already checked in the parent class
if reference and text_content: re.search('[^\s]*class\s+%s\s*[(:]' % reference, text_content) is None):
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
error_list.append(ConsistencyMessage( error_list.append(ConsistencyMessage(
self, self,
self.getRelativeUrl(), self.getRelativeUrl(),
......
...@@ -2194,9 +2194,12 @@ class TestZodbDocumentComponent(_TestZodbComponent): ...@@ -2194,9 +2194,12 @@ class TestZodbDocumentComponent(_TestZodbComponent):
def _getValidSourceCode(self, class_name): def _getValidSourceCode(self, class_name):
return '''from Products.ERP5.Document.Person import Person return '''from Products.ERP5.Document.Person import Person
class %sAnything:
pass
class %s(Person): class %s(Person):
pass pass
''' % class_name ''' % (class_name, class_name)
def testAtLeastOneClassNamedAfterReference(self): def testAtLeastOneClassNamedAfterReference(self):
component = self._newComponent( 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