def setUp(self):
     self.nsmapper = namespaces.DocNamespaceHelper()
     self.dc = descriptorcontainers.AbstractDescriptorContainer(nsmapper=self.nsmapper,
                                                                nodeName='MyDescriptor',
                                                                handle='123',
                                                                parentHandle='456')
     self.dc.DescriptorVersion = 42
    def test_AbstractDescriptorContainer(self):
        dc = descriptorcontainers.AbstractDescriptorContainer(
            nsmapper=self.nsmapper,
            nodeName='MyDescriptor',
            handle='123',
            parentHandle='456',
        )

        self.assertEqual(dc.DescriptorVersion, 0)
        self.assertEqual(dc.SafetyClassification, 'Inf')
        self.assertEqual(dc.getActualValue('SafetyClassification'), None)
        self.assertEqual(dc.Type, None)

        #test creation from node
        node = dc.mkNode()
        dc2 = descriptorcontainers.AbstractDescriptorContainer.fromNode(
            nsmapper=self.nsmapper, node=node, parentHandle='467')
        self.assertEqual(dc2.DescriptorVersion, 0)
        self.assertEqual(dc2.SafetyClassification, 'Inf')
        self.assertEqual(dc.Type, None)
        self.assertEqual(dc.ext_Extension, None)

        #test update from node
        dc.DescriptorVersion = 42
        dc.SafetyClassification = 'MedA'
        dc.Type = pmtypes.CodedValue('abc', 'def')

        dc.ext_Extension = etree_.Element(namespaces.extTag('Extension'))
        etree_.SubElement(dc.ext_Extension,
                          'foo',
                          attrib={'someattr': 'somevalue'})
        etree_.SubElement(dc.ext_Extension,
                          'bar',
                          attrib={'anotherattr': 'differentvalue'})
        node = dc.mkNode()
        dc2.updateDescrFromNode(node)

        self.assertEqual(dc2.DescriptorVersion, 42)
        self.assertEqual(dc2.SafetyClassification, 'MedA')
        self.assertEqual(dc2.Type, dc.Type)
        self.assertEqual(dc.codeId, 'abc')
        self.assertEqual(dc.codingSystem, 'def')
        self.assertEqual(dc2.ext_Extension.tag, namespaces.extTag('Extension'))
        self.assertEqual(len(dc2.ext_Extension), 2)