def test_import_collection_nopurge(self): xml = """\ <registry> <record name="test.registry.field"> <value purge="false"> <element>4</element> <element>6</element> </value> </record> </registry> """ self.registry.records['test.registry.field'] = Record(field.Set( title=u"Simple record", value_type=field.Int(title=u"Val")), value=set([1])) 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.Set)) self.assertEquals( u"Simple record", self.registry.records['test.registry.field'].field.title) self.assertEquals(frozenset([1, 4, 6]), self.registry['test.registry.field'])
def test_import_dict_nopurge(self): xml = """\ <registry> <record name="test.registry.field"> <value purge="false"> <element key="x">4</element> <element key="y">6</element> </value> </record> </registry> """ self.registry.records['test.registry.field'] = \ Record(field.Dict(title=u"Simple record", key_type=field.ASCIILine(title=u"Key"), value_type=field.Int(title=u"Val")), value={'a': 1}) 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.Dict)) self.assertEquals( u"Simple record", self.registry.records['test.registry.field'].field.title) self.assertEquals({ 'a': 1, 'x': 4, 'y': 6 }, self.registry['test.registry.field'])
def test_import_interface_and_value(self): xml = """\ <registry> <record interface="plone.app.registry.tests.data.ITestSettingsDisallowed" field="age"> <value>2</value> </record> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} importRegistry(context) self.assertEquals(1, len(self.registry.records)) self.assertEquals( u"Age", self.registry.records[ 'plone.app.registry.tests.data.ITestSettingsDisallowed.age']. field.title # noqa ) self.assertEquals( 2, self.registry[ 'plone.app.registry.tests.data.ITestSettingsDisallowed.age'] # noqa )
def test_import_records_with_values(self): xml = """\ <registry> <records interface="plone.app.registry.tests.data.ITestSettings" prefix="plone.app.registry.tests.data.SomethingElse"> <value key="name">Magic</value> <value key="age">42</value> </records> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} importRegistry(context) self.assertEqual(2, len(self.registry.records)) self.assertIn( 'plone.app.registry.tests.data.SomethingElse.name', self.registry ) self.assertIn( 'plone.app.registry.tests.data.SomethingElse.age', self.registry ) self.assertEqual( self.registry['plone.app.registry.tests.data.SomethingElse.name'], 'Magic' ) self.assertEqual( self.registry['plone.app.registry.tests.data.SomethingElse.age'], 42 )
def test_import_records_remove_with_omit(self): xml = """\ <registry> <records interface="plone.app.registry.tests.data.ITestSettings" /> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} importRegistry(context) self.assertEquals(2, len(self.registry.records)) delete_xml = """\ <registry> <records interface="plone.app.registry.tests.data.ITestSettings" remove="true"> <omit>name</omit> </records> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': delete_xml} importRegistry(context) self.assertEquals(1, len(self.registry.records)) self.failUnless('plone.app.registry.tests.data.ITestSettings.name' in self.registry) self.failIf('plone.app.registry.tests.data.ITestSettings.age' in self.registry)
def test_import_with_comments(self): xml = """\ <registry> <records interface="plone.app.registry.tests.data.ITestSettings" prefix="plone.app.registry.tests.data.SomethingElse"> <!-- set values in this interface --> <value key="name">Magic</value> <value key="age">42</value> </records> <record name="test.registry.field"> <!-- comment on this field or value --> <field type="plone.registry.field.TextLine"> <default>N/A</default> <!-- comment here too --> <title>Simple record</title> </field> </record> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} importRegistry(context) self.assertEquals(3, len(self.registry.records)) self.failUnless(isinstance(self.registry.records['test.registry.field'].field, field.TextLine)) self.assertEquals(u"Simple record", self.registry.records['test.registry.field'].field.title) self.assertEquals(u"value", self.registry.records['test.registry.field'].field.__name__) self.assertEquals(u"N/A", self.registry['test.registry.field']) self.failUnless('plone.app.registry.tests.data.SomethingElse.name' in self.registry) self.failUnless('plone.app.registry.tests.data.SomethingElse.age' in self.registry) self.assertEqual(self.registry['plone.app.registry.tests.data.SomethingElse.name'], 'Magic') self.assertEqual(self.registry['plone.app.registry.tests.data.SomethingElse.age'], 42)
def test_import_collection_field(self): xml = """\ <registry> <record name="test.registry.field"> <field type="plone.registry.field.FrozenSet"> <title>Simple record</title> <default> <element>1</element> <element>3</element> </default> <value_type type="plone.registry.field.Int"> <title>Value</title> </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.FrozenSet)) self.assertEquals(u"Simple record", self.registry.records['test.registry.field'].field.title) self.assertEquals(frozenset([1, 3]), self.registry['test.registry.field'])
def test_import_overwrite_field_with_field(self): xml = """\ <registry> <record name="test.registry.field"> <field type="plone.registry.field.ASCIILine"> <default>Nada</default> <title>Simple record</title> </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.assertEqual(1, len(self.registry.records)) self.assertTrue( isinstance( self.registry.records['test.registry.field'].field, field.ASCIILine) ) self.assertEqual( u"Simple record", self.registry.records['test.registry.field'].field.title ) self.assertEqual( "Nada", self.registry['test.registry.field'] )
def test_import_field_and_interface(self): xml = """\ <registry> <record name="test.registry.field" interface="plone.app.registry.tests.data.ITestSettingsDisallowed" field="age"> <field type="plone.registry.field.ASCIILine"> <default>N/A</default> <title>Simple record</title> </field> </record> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} importRegistry(context) self.assertEqual(1, len(self.registry.records)) self.assertTrue( isinstance( self.registry.records['test.registry.field'].field, field.ASCIILine ) ) self.assertEqual( u"Simple record", self.registry.records['test.registry.field'].field.title ) self.assertEqual( "N/A", self.registry['test.registry.field'] )
def test_import_collection_tuple_append(self): xml = """\ <registry> <record name="test.registry.field"> <value purge="false"> <element>b</element> <element>c</element> </value> </record> </registry> """ self.registry.records['test.registry.field'] = Record( field.Tuple( title=u"Simple record", value_type=field.TextLine(title=u"Val") ), value=(u"a", u"b", ) ) context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} importRegistry(context) self.assertEqual(1, len(self.registry.records)) self.assertEqual( (u"a", u"b", u"c", ), self.registry['test.registry.field'] )
def test_import_field_ref(self): xml = """\ <registry> <record name="test.registry.field.override"> <field ref="test.registry.field" /> <value>Another value</value> </record> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} self.registry.records['test.registry.field'] = Record( field.TextLine(title=u"Simple record", default=u"N/A"), value=u"Sample value") importRegistry(context) self.assertEqual(2, len(self.registry.records)) self.assertTrue( IFieldRef.providedBy( self.registry.records['test.registry.field.override'].field) ) self.assertEqual( u"Simple record", self.registry.records['test.registry.field.override'].field.title ) self.assertEqual( u"value", self.registry.records['test.registry.field.override'].field.__name__ # noqa ) self.assertEqual( u"Another value", self.registry['test.registry.field.override'] )
def test_import_collection_frozenset_append(self): xml = """\ <registry> <record name="test.registry.field"> <value purge="false"> <element>4</element> <element>6</element> </value> </record> </registry> """ self.registry.records['test.registry.field'] = Record( field.FrozenSet( title=u"Simple record", value_type=field.Int(title=u"Val") ), value=frozenset([2, 4]) ) context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} importRegistry(context) self.assertEqual(1, len(self.registry.records)) self.assertEqual( frozenset([2, 4, 6]), self.registry['test.registry.field'] )
def test_import_overwrite_field_with_field(self): xml = """\ <registry> <record name="test.registry.field"> <field type="plone.registry.field.ASCIILine"> <default>Nada</default> <title>Simple record</title> </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.ASCIILine)) self.assertEquals(u"Simple record", self.registry.records['test.registry.field'].field.title) self.assertEquals("Nada", self.registry['test.registry.field'])
def test_import_records_remove_with_value(self): xml = """\ <registry> <records interface="plone.app.registry.tests.data.ITestSettings" /> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} importRegistry(context) self.assertEquals(2, len(self.registry.records)) delete_xml = """\ <registry> <records interface="plone.app.registry.tests.data.ITestSettings" remove="true"> <value key="name">Spam</value> </records> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': delete_xml} self.assertRaises(ValueError, importRegistry, context) self.assertEquals(2, len(self.registry.records))
def test_import_value_only_condition_not_have(self): xml = """\ <registry> <record name="test.export.simple" condition="not-have plone"> <value>Imported value</value> </record> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} self.registry.records['test.export.simple'] = \ Record(field.TextLine(title=u"Simple record", default=u"N/A"), value=u"Sample value") importRegistry(context) self.assertEqual(1, len(self.registry.records)) self.assertEqual( u"Simple record", self.registry.records['test.export.simple'].field.title ) self.assertEqual( u"Sample value", self.registry['test.export.simple'] )
def test_import_records_remove_with_omit(self): xml = """\ <registry> <records interface="plone.app.registry.tests.data.ITestSettings" /> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} importRegistry(context) self.assertEqual(2, len(self.registry.records)) delete_xml = """\ <registry> <records interface="plone.app.registry.tests.data.ITestSettings" remove="true"> <omit>name</omit> </records> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': delete_xml} importRegistry(context) self.assertEqual(1, len(self.registry.records)) self.assertIn( 'plone.app.registry.tests.data.ITestSettings.name', self.registry ) self.assertNotIn( 'plone.app.registry.tests.data.ITestSettings.age', self.registry )
def test_import_records_remove_with_value(self): xml = """\ <registry> <records interface="plone.app.registry.tests.data.ITestSettings" /> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} importRegistry(context) self.assertEqual(2, len(self.registry.records)) delete_xml = """\ <registry> <records interface="plone.app.registry.tests.data.ITestSettings" remove="true"> <value key="name">Spam</value> </records> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': delete_xml} self.assertRaises(ValueError, importRegistry, context) self.assertEqual(2, len(self.registry.records))
def test_import_records_omit(self): xml = """\ <registry> <records interface="plone.app.registry.tests.data.ITestSettingsDisallowed"> <omit>blob</omit> </records> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} self.registry.records['test.export.simple'] = \ Record(field.TextLine(title=u"Simple record", default=u"N/A"), value=u"Sample value") importRegistry(context) self.assertEqual(3, len(self.registry.records)) self.assertIn( 'plone.app.registry.tests.data.ITestSettingsDisallowed.name', self.registry ) self.assertIn( 'plone.app.registry.tests.data.ITestSettingsDisallowed.age', self.registry )
def test_import_collection_nopurge(self): xml = """\ <registry> <record name="test.registry.field"> <value purge="false"> <element>4</element> <element>6</element> </value> </record> </registry> """ self.registry.records['test.registry.field'] = \ Record(field.Set(title=u"Simple record", value_type=field.Int(title=u"Val")), value=set([1])) 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.Set)) self.assertEquals(u"Simple record", self.registry.records['test.registry.field'].field.title) self.assertEquals(frozenset([1, 4, 6]), self.registry['test.registry.field'])
def test_import_dict_field(self): xml = """\ <registry> <record name="test.registry.field"> <field type="plone.registry.field.Dict"> <title>Simple record</title> <default> <element key="a">1</element> <element key="b">3</element> </default> <key_type type="plone.registry.field.ASCIILine"> <title>Key</title> </key_type> <value_type type="plone.registry.field.Int"> <title>Value</title> </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.Dict)) self.assertEquals(u"Simple record", self.registry.records['test.registry.field'].field.title) self.assertEquals({'a': 1, 'b': 3}, self.registry['test.registry.field'])
def test_import_dict_nopurge(self): xml = """\ <registry> <record name="test.registry.field"> <value purge="false"> <element key="x">4</element> <element key="y">6</element> </value> </record> </registry> """ self.registry.records['test.registry.field'] = \ Record(field.Dict(title=u"Simple record", key_type=field.ASCIILine(title=u"Key"), value_type=field.Int(title=u"Val")), value={'a': 1}) 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.Dict)) self.assertEquals(u"Simple record", self.registry.records['test.registry.field'].field.title) self.assertEquals({'a': 1, 'x': 4, 'y': 6}, self.registry['test.registry.field'])
def test_import_choice_field(self): xml = """\ <registry> <record name="test.registry.field"> <field type="plone.registry.field.Choice"> <title>Simple record</title> <values> <element>One</element> <element>Two</element> </values> </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.Choice)) self.assertEquals(u"Simple record", self.registry.records['test.registry.field'].field.title) self.assertEquals([u'One', u'Two'], [t.value for t in self.registry.records['test.registry.field'].field.vocabulary]) self.assertEquals(None, self.registry['test.registry.field'])
def test_import_overwrite_field_with_interface(self): xml = """\ <registry> <record name="test.registry.field" interface="plone.app.registry.tests.data.ITestSettingsDisallowed" field="age" /> </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.assertEqual(1, len(self.registry.records)) self.assertTrue( isinstance( self.registry.records['test.registry.field'].field, field.Int ) ) self.assertEqual( u"Age", self.registry.records['test.registry.field'].field.title ) self.assertEqual( None, self.registry['test.registry.field'] )
def test_import_field_only(self): xml = """\ <registry> <record name="test.registry.field"> <field type="plone.registry.field.TextLine"> <default>N/A</default> <title>Simple record</title> </field> </record> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} importRegistry(context) self.assertEqual(1, len(self.registry.records)) self.assertTrue( isinstance( self.registry.records['test.registry.field'].field, field.TextLine) ) self.assertEqual( u"Simple record", self.registry.records['test.registry.field'].field.title ) self.assertEqual( u"value", self.registry.records['test.registry.field'].field.__name__ ) self.assertEqual( u"N/A", self.registry['test.registry.field'] )
def test_import_with_comments(self): xml = """\ <registry> <records interface="plone.app.registry.tests.data.ITestSettings" prefix="plone.app.registry.tests.data.SomethingElse"> <!-- set values in this interface --> <value key="name">Magic</value> <value key="age">42</value> </records> <record name="test.registry.field"> <!-- comment on this field or value --> <field type="plone.registry.field.TextLine"> <default>N/A</default> <!-- comment here too --> <title>Simple record</title> </field> </record> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} importRegistry(context) self.assertEqual(3, len(self.registry.records)) self.assertTrue( isinstance( self.registry.records['test.registry.field'].field, field.TextLine ) ) self.assertEqual( u"Simple record", self.registry.records['test.registry.field'].field.title ) self.assertEqual( u"value", self.registry.records['test.registry.field'].field.__name__ ) self.assertEqual( u"N/A", self.registry['test.registry.field'] ) self.assertIn( 'plone.app.registry.tests.data.SomethingElse.name', self.registry ) self.assertIn( 'plone.app.registry.tests.data.SomethingElse.age', self.registry ) self.assertEqual( self.registry['plone.app.registry.tests.data.SomethingElse.name'], 'Magic' ) self.assertEqual( self.registry['plone.app.registry.tests.data.SomethingElse.age'], 42 )
def test_import_purge(self): xml = "<registry/>" context = DummyImportContext(self.site, purge=True) context._files = {'registry.xml': xml} self.registry.records['test.export.simple'] = \ Record(field.TextLine(title=u"Simple record", default=u"N/A"), value=u"Sample value") importRegistry(context) self.assertEquals(0, len(self.registry.records))
def test_empty_import_no_purge(self): xml = "<registry/>" context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} self.registry.records['test.export.simple'] = \ Record(field.TextLine(title=u"Simple record", default=u"N/A"), value=u"Sample value") importRegistry(context) self.assertEqual(1, len(self.registry.records))
def test_import_interface_no_value(self): xml = """\ <registry> <record interface="plone.app.registry.tests.data.ITestSettingsDisallowed" field="name" /> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} importRegistry(context) self.assertEquals(1, len(self.registry.records)) self.assertEquals(u"Name", self.registry.records['plone.app.registry.tests.data.ITestSettingsDisallowed.name'].field.title) self.assertEquals(u"Mr. Registry", self.registry['plone.app.registry.tests.data.ITestSettingsDisallowed.name'])
def test_delete_deprecated(self): xml = """\ <registry> <record name="test.export.simple" delete="true" /> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} self.registry.records['test.export.simple'] = \ Record(field.TextLine(title=u"Simple record", default=u"N/A"), value=u"Sample value") importRegistry(context) self.assertEquals(0, len(self.registry.records))
def test_import_records_with_prefix(self): xml = """\ <registry> <records interface="plone.app.registry.tests.data.ITestSettings" prefix="plone.app.registry.tests.data.SomethingElse" /> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} importRegistry(context) self.assertEquals(2, len(self.registry.records)) self.failUnless('plone.app.registry.tests.data.SomethingElse.name' in self.registry) self.failUnless('plone.app.registry.tests.data.SomethingElse.age' in self.registry)
def test_delete_deprecated(self): xml = """\ <registry> <record name="test.export.simple" delete="true" /> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} self.registry.records['test.export.simple'] = \ Record(field.TextLine(title=u"Simple record", default=u"N/A"), value=u"Sample value") importRegistry(context) self.assertEqual(0, len(self.registry.records))
def test_import_interface_with_differnet_name(self): xml = """\ <registry> <record name="plone.registry.oops" interface="plone.app.registry.tests.data.ITestSettingsDisallowed" field="age"> <value>2</value> </record> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} importRegistry(context) self.assertEquals(1, len(self.registry.records)) self.assertEquals(u"Age", self.registry.records['plone.registry.oops'].field.title) self.assertEquals(2, self.registry['plone.registry.oops'])
def test_import_records_with_prefix(self): xml = """\ <registry> <records interface="plone.app.registry.tests.data.ITestSettings" prefix="plone.app.registry.tests.data.SomethingElse" /> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} importRegistry(context) self.assertEquals(2, len(self.registry.records)) self.failUnless('plone.app.registry.tests.data.SomethingElse.name' in self.registry) self.failUnless( 'plone.app.registry.tests.data.SomethingElse.age' in self.registry)
def test_import_dict_field(self): xml = """\ <registry> <record name="test.registry.field"> <field type="plone.registry.field.Dict"> <title>Simple record</title> <default> <element key="a">1</element> <element key="b">3</element> </default> <key_type type="plone.registry.field.ASCIILine"> <title>Key</title> </key_type> <value_type type="plone.registry.field.Int"> <title>Value</title> </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.assertEqual(1, len(self.registry.records)) self.assertTrue( isinstance( self.registry.records['test.registry.field'].field, field.Dict ) ) self.assertEqual( u"Simple record", self.registry.records['test.registry.field'].field.title ) self.assertEqual( {'a': 1, 'b': 3}, self.registry['test.registry.field'] )
def test_import_records(self): xml = """\ <registry> <records interface="plone.app.registry.tests.data.ITestSettings" /> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} self.registry.records['test.export.simple'] = \ Record(field.TextLine(title=u"Simple record", default=u"N/A"), value=u"Sample value") importRegistry(context) self.assertEquals(3, len(self.registry.records)) self.failUnless('plone.app.registry.tests.data.ITestSettings.name' in self.registry) self.failUnless('plone.app.registry.tests.data.ITestSettings.age' in self.registry)
def test_import_interface_with_differnet_name(self): xml = """\ <registry> <record name="plone.registry.oops" interface="plone.app.registry.tests.data.ITestSettingsDisallowed" field="age"> <value>2</value> </record> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} importRegistry(context) self.assertEqual(1, len(self.registry.records)) self.assertEqual( u"Age", self.registry.records['plone.registry.oops'].field.title ) self.assertEqual(2, self.registry['plone.registry.oops'])
def test_import_interface_no_value(self): xml = """\ <registry> <record interface="plone.app.registry.tests.data.ITestSettingsDisallowed" field="name" /> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} importRegistry(context) self.assertEquals(1, len(self.registry.records)) self.assertEquals( u"Name", self.registry.records[ 'plone.app.registry.tests.data.ITestSettingsDisallowed.name']. field.title) self.assertEquals( u"Mr. Registry", self.registry[ 'plone.app.registry.tests.data.ITestSettingsDisallowed.name'])
def test_delete_not_found(self): xml = """\ <registry> <record name="test.export.bogus" remove="true" /> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} self.registry.records['test.export.simple'] = \ Record(field.TextLine(title=u"Simple record", default=u"N/A"), value=u"Sample value") importRegistry(context) self.assertEquals(1, len(self.registry.records)) self.assertEquals( u"Simple record", self.registry.records['test.export.simple'].field.title) self.assertEquals(u"Sample value", self.registry['test.export.simple'])
def test_import_records_disallowed(self): xml = """\ <registry> <records interface="plone.app.registry.tests.data.ITestSettingsDisallowed" /> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} self.registry.records['test.export.simple'] = \ Record(field.TextLine(title=u"Simple record", default=u"N/A"), value=u"Sample value") try: importRegistry(context) except TypeError: pass else: self.fail()
def test_import_choice_field(self): xml = """\ <registry> <record name="test.registry.field"> <field type="plone.registry.field.Choice"> <title>Simple record</title> <values> <element>One</element> <element>Two</element> </values> </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.assertEqual(1, len(self.registry.records)) self.assertTrue( isinstance( self.registry.records['test.registry.field'].field, field.Choice ) ) self.assertEqual( u"Simple record", self.registry.records['test.registry.field']. field.title ) self.assertEqual( [u'One', u'Two'], [t.value for t in self.registry.records['test.registry.field'].field.vocabulary] # noqa ) self.assertEqual( None, self.registry['test.registry.field'] )
def test_import_collection_field(self): xml = """\ <registry> <record name="test.registry.field"> <field type="plone.registry.field.FrozenSet"> <title>Simple record</title> <default> <element>1</element> <element>3</element> </default> <value_type type="plone.registry.field.Int"> <title>Value</title> </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.assertEqual(1, len(self.registry.records)) self.assertTrue( isinstance( self.registry.records['test.registry.field'].field, field.FrozenSet ) ) self.assertEqual( u"Simple record", self.registry.records['test.registry.field'].field.title ) self.assertEqual( frozenset([1, 3]), self.registry['test.registry.field'] )
def test_import_records(self): xml = """\ <registry> <records interface="plone.app.registry.tests.data.ITestSettings" /> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} self.registry.records['test.export.simple'] = \ Record(field.TextLine(title=u"Simple record", default=u"N/A"), value=u"Sample value") importRegistry(context) self.assertEquals(3, len(self.registry.records)) self.failUnless('plone.app.registry.tests.data.ITestSettings.name' in self.registry) self.failUnless( 'plone.app.registry.tests.data.ITestSettings.age' in self.registry)
def test_import_interface_and_value(self): xml = """\ <registry> <record interface="plone.app.registry.tests.data.ITestSettingsDisallowed" field="age"> <value>2</value> </record> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} importRegistry(context) self.assertEqual(1, len(self.registry.records)) self.assertEqual( u"Age", self.registry.records['plone.app.registry.tests.data.ITestSettingsDisallowed.age'].field.title # noqa ) self.assertEqual( 2, self.registry['plone.app.registry.tests.data.ITestSettingsDisallowed.age'] # noqa )
def test_delete_not_found(self): xml = """\ <registry> <record name="test.export.bogus" remove="true" /> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} self.registry.records['test.export.simple'] = \ Record(field.TextLine(title=u"Simple record", default=u"N/A"), value=u"Sample value") importRegistry(context) self.assertEqual(1, len(self.registry.records)) self.assertEqual( u"Simple record", self.registry.records['test.export.simple'].field.title ) self.assertEqual( u"Sample value", self.registry['test.export.simple'] )
def test_import_records_delete_deprecated(self): xml = """\ <registry> <records interface="plone.app.registry.tests.data.ITestSettings" /> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} importRegistry(context) self.assertEqual(2, len(self.registry.records)) delete_xml = """\ <registry> <records interface="plone.app.registry.tests.data.ITestSettings" delete="true"/> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': delete_xml} importRegistry(context) self.assertEqual(0, len(self.registry.records))
def test_import_records_delete_deprecated(self): xml = """\ <registry> <records interface="plone.app.registry.tests.data.ITestSettings" /> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': xml} importRegistry(context) self.assertEquals(2, len(self.registry.records)) delete_xml = """\ <registry> <records interface="plone.app.registry.tests.data.ITestSettings" delete="true"/> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = {'registry.xml': delete_xml} importRegistry(context) self.assertEquals(0, len(self.registry.records))
def test_import_folder(self): xml1 = """\ <registry> <record name="test.registry.foobar1"> <field type="plone.registry.field.TextLine"> <default>N/A</default> <title>Simple record</title> </field> </record> </registry> """ xml2 = """\ <registry> <record name="test.registry.foobar2"> <field type="plone.registry.field.TextLine"> <default>N/A</default> <title>Simple record</title> </field> </record> </registry> """ xml3 = """\ <registry> <record name="test.registry.foobar3"> <field type="plone.registry.field.TextLine"> <default>N/A</default> <title>Simple record</title> </field> </record> </registry> """ context = DummyImportContext(self.site, purge=False) context._files = { 'registry.xml': xml1, 'registry/foo2.xml': xml2, 'registry/foo3.xml': xml3 } context._directories = { 'registry': [ 'foo2.xml', 'foo3.xml', ] } importRegistry(context) self.assertEqual(3, len(self.registry.records)) for idx in range(1, 4): fieldname = 'test.registry.foobar%i' % idx self.assertTrue( isinstance( self.registry.records[fieldname].field, field.TextLine) ) self.assertEqual( u"Simple record", self.registry.records[fieldname].field.title ) self.assertEqual( u"value", self.registry.records[fieldname].field.__name__ ) self.assertEqual( u"N/A", self.registry[fieldname] )