Esempio n. 1
0
    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)
Esempio n. 2
0
 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)
Esempio n. 4
0
    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
Esempio n. 5
0
 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)
Esempio n. 6
0
 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)))
Esempio n. 7
0
 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')
Esempio n. 8
0
 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)
Esempio n. 9
0
 def test_Property_init_dict(self):
     c = Component(self.zp, 'Component', properties=[{"name": "port"}])
     self.assertEqual(c.properties.keys(), ['port'])
Esempio n. 10
0
 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)))
Esempio n. 11
0
 def testComponentLookup(self):
     Component(self.zp, 'Disk')
     self.assertEqual(
         Component.lookup(self.zp, 'a.b.c.Disk').id, 'a.b.c.Disk')
Esempio n. 12
0
 def test_classes_zenpack_outside_namespace(self):
     c = Component(self.zp, 'Component', klasses=['OperatingSystem'])
     self.assertEqual(
         c.klasses, ['Products.ZenModel.OperatingSystem.OperatingSystem'])
Esempio n. 13
0
 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'])
Esempio n. 14
0
 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'])
Esempio n. 15
0
 def test_name_overridden(self):
     c = Component(self.zp, 'Component', names='names')
     self.assertEqual(c.names, 'names')
Esempio n. 16
0
 def test_ComponentCreate(self):
     c = Component(self.zp, 'Component')
     self.assertIsInstance(c, Component)
Esempio n. 17
0
 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)
Esempio n. 18
0
 def test_Property_default(self):
     c = Component(self.zp, 'Component')
     c.addProperty('oids')
     self.assertEqual(c.properties.keys(), ['oids'])
Esempio n. 19
0
 def test_namespace_overridden(self):
     c = Component(self.zp, 'Component', namespace='a.a.a')
     self.assertEqual(c.namespace, 'a.a.a')
Esempio n. 20
0
 def test_namespace_default(self):
     c = Component(self.zp, 'Component')
     self.assertEqual(c.namespace, DEFAULT_NAME)
Esempio n. 21
0
 def test_name_default(self):
     c = Component(self.zp, 'Component')
     self.assertEqual(c.names, 'Components')
Esempio n. 22
0
 def test_ComponentType_init_dict(self):
     c = Component(self.zp, 'Component', componentTypes=[{"name": "Blade"}])
     self.assertEqual(c.components.keys(), ['%s.Blade' % DEFAULT_NAME])
Esempio n. 23
0
 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')
Esempio n. 24
0
 def test_addComponent(self):
     c = Component(self.zp, 'Component')
     c.addComponentType('SubComponent')
     self.assertEqual(
         c.components.keys(), ['%s.SubComponent' % DEFAULT_NAME])
Esempio n. 25
0
 def test_classes_default(self):
     c = Component(self.zp, 'Component')
     self.assertEqual(
         c.klasses, ['Products.ZenModel.DeviceComponent.DeviceComponent',
                     'Products.ZenModel.ManagedEntity.ManagedEntity'])
Esempio n. 26
0
 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')
Esempio n. 27
0
 def test_classes_NonDefault(self):
     c = Component(self.zp, 'Component',
                   klasses=['zenpacks.zenoss.Test.Test'])
     self.assertEqual(c.klasses, ['zenpacks.zenoss.Test.Test'])
Esempio n. 28
0
 def test_klassNames_Default(self):
     c = Component(self.zp, 'Component')
     self.assertEqual(c.klassNames(), ['DeviceComponent', 'ManagedEntity'])