Last active
November 16, 2015 03:25
-
-
Save metatoaster/05ee5a65db8aec8215d8 to your computer and use it in GitHub Desktop.
Test can be added to plone.app.registry to show schema validation on broken plone.supermodel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Failure in test test_import_list_choice_field_vocabulary_usage (plone.app.registry.tests.test_exportimport.TestImport) | |
| Traceback (most recent call last): | |
| ... | |
| File ".../plone.app.registry/plone/app/registry/tests/test_exportimport.py", line 1073, in test_import_list_choice_field_vocabulary_usage | |
| self.registry['test.registry.field'] = [u'One', u'Three'] | |
| ... | |
| AssertionError: WrongContainedType not raised |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def test_import_list_choice_field_vocabulary_usage(self): | |
| xml = """\ | |
| <registry> | |
| <record name="test.registry.field"> | |
| <field type="plone.registry.field.List"> | |
| <title>Simple list of choices</title> | |
| <value_type type="plone.registry.field.Choice"> | |
| <values> | |
| <element>Zero</element> | |
| <element>One</element> | |
| </values> | |
| </value_type> | |
| </field> | |
| </record> | |
| </registry> | |
| """ | |
| self.registry.records['test.registry.field'] = \ | |
| Record(field.TextLine(title=u"Simple record", default=u"N/A"), | |
| value=u"Old value") | |
| context = DummyImportContext(self.site, purge=False) | |
| context._files = {'registry.xml': xml} | |
| importRegistry(context) | |
| self.assertEquals(1, len(self.registry.records)) | |
| self.failUnless( | |
| isinstance( | |
| self.registry.records['test.registry.field'].field, | |
| field.List | |
| ) | |
| ) | |
| self.assertEquals( | |
| u"Simple list of choices", | |
| self.registry.records['test.registry.field']. | |
| field.title | |
| ) | |
| self.assertEquals( | |
| None, self.registry['test.registry.field'] | |
| ) | |
| self.registry['test.registry.field'] = [u'One'] | |
| self.assertEquals( | |
| [u'One'], self.registry['test.registry.field'] | |
| ) | |
| # the following exception will only be raised if and only if | |
| # the underlying record field.value_type._init_field is False, | |
| # i.e:: | |
| # self.registry.records['test.registry.field' | |
| # ].field.value_type._init_field = False | |
| with self.assertRaises(WrongContainedType): | |
| self.registry['test.registry.field'] = [u'One', u'Three'] | |
| with self.assertRaises(WrongContainedType): | |
| self.registry['test.registry.field'] = [u'One', object()] | |
| self.assertEquals( | |
| [u'One'], self.registry['test.registry.field'] | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment