def test_imports_with_classes(self): zp = ZenPack('a.b.c') c = Component(zp, 'Componentk', klasses=['Products.ZenModel.OSComponent.OSComponent', 'Products.ZenModel.Linkable.Layer2Linkable' ] ) c2 = Component(zp, 'Componentk2', klasses=['Products.ZenModel.Software.Software', ] ) self.maxDiff = None expected = ['from zope.interface import implements', 'from Products.ZenModel.ZenossSecurity import ZEN_CHANGE_DEVICE', 'from Products.Zuul.decorators import info', 'from Products.Zuul.form import schema', 'from Products.Zuul.infos import ProxyProperty', 'from Products.Zuul.utils import ZuulMessageFactory as _t', 'from Products.ZenModel.OSComponent import OSComponent', 'from Products.ZenModel.Linkable import Layer2Linkable', ] for e in expected: self.assertTrue(e in c.imports) expected = ['from zope.interface import implements', 'from Products.ZenModel.ZenossSecurity import ZEN_CHANGE_DEVICE', 'from Products.Zuul.decorators import info', 'from Products.Zuul.form import schema', 'from Products.Zuul.infos import ProxyProperty', 'from Products.Zuul.utils import ZuulMessageFactory as _t', 'from Products.ZenModel.Software import Software', ] for e in expected: self.assertTrue(e in c2.imports)
def testManytoMany(self): dc = self.zp.addDeviceClass('Device', zPythonClass='a.b.c.d.e.Device') e = dc.addComponentType('a.b.Enclosure') Relationship(self.zp, 'a.b.Enclosure', 'a.b.Disk', type_='M-M', contained=False) d = Component(self.zp, 'a.b.Disk') d.updateImports() e.updateImports() self.assertTrue( 'from Products.ZenRelations.RelSchema import ToMany' in d.imports)
def testOnetoOne(self): dc = self.zp.addDeviceClass('Device', zPythonClass='a.b.c.d.Device') e = dc.addComponentType('a.Enclosure') Relationship(self.zp, 'a.Enclosure', 'a.Disk', Type='1-1', Contained=False) d = Component(self.zp, 'a.Disk') d.updateImports() e.updateImports() self.assertTrue( 'from Products.ZenRelations.RelSchema import ToOne' in d.imports)
def write(self, Component, template): with patch('__builtin__.open', mock_open(read_data=template), create=True) as m: Component.dest_file = 'dummy_dest_file.py' Component.tfile = 'dummy_tfile' Component.source_template = 'dummy_source_template.tmpl' Component.write() # Write File Handle wfh = m.return_value.__enter__.return_value self.results = wfh.write.call_args_list
def test_imports_string(self): c = Component(self.zp, 'Component', imports='from zope.interface import implements') expected = ['from zope.interface import implements', 'from Products.ZenModel.DeviceComponent import DeviceComponent', 'from Products.ZenModel.ManagedEntity import ManagedEntity'] for e in expected: self.assertTrue(e in c.imports)
def test_WriteBasicAgain(self): d = Component(self.zp, 'Component2') name = DEFAULT_NAME version = defaults.get('version') self.write( d, '${zenpack.id}\n${zenpack.version}\n${zenpack.version}\n') self.assertEqual(self.results[-1], call( u'%s\n%s\n%s\n' % (DEFAULT_NAME, version, version)))
def test_meta_type_Overridden(self): c = Component(self.zp, 'Component', meta_type='unique') self.assertNotEqual(c.portal_type, 'Component') self.assertNotEqual(c.meta_type, 'Component') self.assertNotEqual(c.unique_name, 'Component') self.assertEqual(c.portal_type, 'unique') self.assertEqual(c.meta_type, 'unique') self.assertEqual(c.unique_name, 'unique')
def test_imports_default(self): c = Component(self.zp, 'Component') expected = ['from zope.interface import implements', 'from Products.ZenModel.ZenossSecurity import ZEN_CHANGE_DEVICE', 'from Products.Zuul.decorators import info', 'from Products.Zuul.form import schema', 'from Products.Zuul.infos import ProxyProperty', 'from Products.Zuul.utils import ZuulMessageFactory as _t', 'from Products.ZenModel.DeviceComponent import DeviceComponent', 'from Products.ZenModel.ManagedEntity import ManagedEntity'] for e in expected: self.assertTrue(e in c.imports)
def test_Property_init_dict(self): c = Component(self.zp, 'Component', properties=[{"name": "port"}]) self.assertEqual(c.properties.keys(), ['port'])
def test_WriteBasic(self): c = Component(self.zp, 'Component') self.write(c, '${zenpack.id}\n${zenpack.version}\n') version = defaults.get('version') name = DEFAULT_NAME self.assertEqual(self.results[-1], call(u'%s\n%s\n' % (name, version)))
def testComponentLookup(self): Component(self.zp, 'Disk') self.assertEqual( Component.lookup(self.zp, 'a.b.c.Disk').id, 'a.b.c.Disk')
def test_classes_zenpack_outside_namespace(self): c = Component(self.zp, 'Component', klasses=['OperatingSystem']) self.assertEqual( c.klasses, ['Products.ZenModel.OperatingSystem.OperatingSystem'])
def test_classes_zenpack_namespace(self): Component(self.zp, 'Test') c = Component(self.zp, 'Component', klasses=['Test']) self.assertEqual(c.klasses, ['a.b.c.Test'])
def test_classes_shorthand(self): c = Component(self.zp, 'Component', klasses=['DeviceComponent', 'ManagedEntity']) self.assertEqual( c.klasses, ['Products.ZenModel.DeviceComponent.DeviceComponent', 'Products.ZenModel.ManagedEntity.ManagedEntity'])
def test_name_overridden(self): c = Component(self.zp, 'Component', names='names') self.assertEqual(c.names, 'names')
def test_ComponentCreate(self): c = Component(self.zp, 'Component') self.assertIsInstance(c, Component)
def test_Property_extraParams(self): c = Component(self.zp, 'Component') c.addProperty('oids', type_='int', value=2) self.assertEqual(c.properties['oids'].type_, 'int') self.assertEqual(c.properties['oids'].value, 2)
def test_Property_default(self): c = Component(self.zp, 'Component') c.addProperty('oids') self.assertEqual(c.properties.keys(), ['oids'])
def test_namespace_overridden(self): c = Component(self.zp, 'Component', namespace='a.a.a') self.assertEqual(c.namespace, 'a.a.a')
def test_namespace_default(self): c = Component(self.zp, 'Component') self.assertEqual(c.namespace, DEFAULT_NAME)
def test_name_default(self): c = Component(self.zp, 'Component') self.assertEqual(c.names, 'Components')
def test_ComponentType_init_dict(self): c = Component(self.zp, 'Component', componentTypes=[{"name": "Blade"}]) self.assertEqual(c.components.keys(), ['%s.Blade' % DEFAULT_NAME])
def test_uniquename_default(self): c = Component(self.zp, 'Component') self.assertEqual(c.portal_type, 'Component') self.assertEqual(c.meta_type, 'Component') self.assertEqual(c.unique_name, 'Component')
def test_addComponent(self): c = Component(self.zp, 'Component') c.addComponentType('SubComponent') self.assertEqual( c.components.keys(), ['%s.SubComponent' % DEFAULT_NAME])
def test_classes_default(self): c = Component(self.zp, 'Component') self.assertEqual( c.klasses, ['Products.ZenModel.DeviceComponent.DeviceComponent', 'Products.ZenModel.ManagedEntity.ManagedEntity'])
def test_ComponentType_Component(self): c = Component(self.zp, 'Component') self.assertEqual(c.Type(), 'Component') d = Component(self.zp, 'Device', device=True) self.assertEqual(d.Type(), 'Device')
def test_classes_NonDefault(self): c = Component(self.zp, 'Component', klasses=['zenpacks.zenoss.Test.Test']) self.assertEqual(c.klasses, ['zenpacks.zenoss.Test.Test'])
def test_klassNames_Default(self): c = Component(self.zp, 'Component') self.assertEqual(c.klassNames(), ['DeviceComponent', 'ManagedEntity'])