def _do_get_component_types(self):
        comp_types = {}
        tmp = None
        try:
            for type_name, clazz in self.remote_object_classes.items():
                comp_id = "%s_%s" % (self.object_id, type_name)
                component = clazz(comp_id, None)
                obj_prop = component.object_property
                component = None

                type = obj_prop.get_property(ObjectProperty.OBJECT_TYPE)
                super_type = obj_prop.get_property(
                    ObjectProperty.OBJECT_SUPER_TYPE)

                connection_types = {}
                connection_types_str = obj_prop.get_property(
                    ObjectProperty.CONNECTION_TYPES)
                conn_type_list = connection_types_str.split(",")
                for type_elem in conn_type_list:
                    type_elem_list = type_elem.split(":")
                    if len(type_elem_list) == 2:
                        connection_types[type_elem_list[0]] = type_elem_list[1]

                description = obj_prop.get_property(ObjectProperty.DESCRIPTION)

                target = ComponentType(type, super_type, connection_types,
                                       description)
                comp_types[type_name] = target.packed_object()

        except Exception, e:
            return Response(Response.StatusCode.INTERNAL_SERVER_ERROR, str(e))
    def _do_get_component_types(self):
        comp_types = {}
        try:
            for type_name, clazz in self.component_classes.items():
                comp_id = "%s_%s" % (self.object_id, type_name)
                component = clazz(comp_id, None)
                obj_prop = component.object_property

                type = obj_prop.get_property(ObjectProperty.OBJECT_TYPE)
                super_type = obj_prop.get_property(ObjectProperty.OBJECT_SUPER_TYPE)

                connection_types = {}
                connection_types_str = obj_prop.get_property(
                    ObjectProperty.CONNECTION_TYPES)
                conn_type_list = connection_types_str.split(",")
                for type_elem in conn_type_list:
                    type_elem_list = type_elem.split(":")
                    if len(type_elem_list) == 2:
                        connection_types[type_elem_list[0]] = type_elem_list[1]

                description = obj_prop.get_property(ObjectProperty.DESCRIPTION)

                target = ComponentType(type, super_type,
                                       connection_types, description)
                comp_types[type_name] = target.packed_object()

        except Exception, e:
            return Response(Response.StatusCode.INTERNAL_SERVER_ERROR,
                            str(e))
Exemple #3
0
 def setUp(self):
     self.target = ComponentType(self._type, self._super_type,
                                 self._connection_types, self._description)
     self.target2 = ComponentType(None, None, None, None)
Exemple #4
0
class ComponentTypeTest(unittest.TestCase):
    _type = "DummyDriver"
    _super_type = "Driver"
    _description = "Description"
    _connection_types = {}

    def setUp(self):
        self.target = ComponentType(self._type, self._super_type,
                                    self._connection_types, self._description)
        self.target2 = ComponentType(None, None, None, None)

    def tearDown(self):
        self.target = None
        self.target2 = None

    def test_constructor(self):
        self.assertEqual(self.target._body[self.target.TYPE], self._type)
        self.assertEqual(self.target._body[self.target.SUPER_TYPE],
                         self._super_type)
        self.assertEqual(self.target._body[self.target.CONNECTION_TYPES],
                         self._connection_types)
        self.assertEqual(self.target._body[self.target.DESCRIPTION],
                         self._description)
        self.assertEqual(self.target2._body[self.target.TYPE], "")
        self.assertEqual(self.target2._body[self.target.SUPER_TYPE], "")
        self.assertEqual(len(self.target2._body[self.target.CONNECTION_TYPES]),
                         0)
        self.assertEqual(self.target2._body[self.target.DESCRIPTION], "")

    def test_type_property(self):
        self.assertEqual(self.target.type, self._type)

    def test_super_type_property(self):
        self.assertEqual(self.target.super_type, self._super_type)

    def test_connection_types_property(self):
        self.assertEqual(self.target.connection_types, self._connection_types)

    def test_description_property(self):
        self.assertEqual(self.target.description, self._description)

    def test_create_from_packed_Version_NotNone_And_packed_object(self):
        self.value = {
            "type": self._type,
            "super_type": self._super_type,
            "connection_types": self._connection_types,
            "description": self._description
        }
        # create_from_packed_test
        self.result = self.target.create_from_packed(self.value)
        self.assertEqual(self.result._body[self.target.TYPE], self._type)
        self.assertEqual(self.result._body[self.target.SUPER_TYPE],
                         self._super_type)
        self.assertEqual(self.result._body[self.target.CONNECTION_TYPES],
                         self._connection_types)
        self.assertEqual(self.result._body[self.target.DESCRIPTION],
                         self._description)

        # packed_object test
        self.result2 = self.result.packed_object()
        self.assertEqual(self.result2[self.target.TYPE], self._type)
        self.assertEqual(self.result2[self.target.SUPER_TYPE],
                         self._super_type)
        self.assertEqual(self.result2[self.target.CONNECTION_TYPES],
                         self._connection_types)
        self.assertEqual(self.result2[self.target.DESCRIPTION],
                         self._description)
 def setUp(self):
     self.target = ComponentType(self._type, self._super_type,
                                 self._connection_types, self._description) 
     self.target2 = ComponentType(None, None, None, None) 
class ComponentTypeTest(unittest.TestCase):
    _type = "DummyDriver"
    _super_type = "Driver"
    _description = "Description"
    _connection_types = {}

    def setUp(self):
        self.target = ComponentType(self._type, self._super_type,
                                    self._connection_types, self._description) 
        self.target2 = ComponentType(None, None, None, None) 

    def tearDown(self):
        self.target = None
        self.target2 = None

    def test_constructor(self):
        self.assertEqual(self.target._body[self.target.TYPE],
                         self._type)
        self.assertEqual(self.target._body[self.target.SUPER_TYPE],
                         self._super_type)
        self.assertEqual(self.target._body[self.target.CONNECTION_TYPES],
                         self._connection_types)
        self.assertEqual(self.target._body[self.target.DESCRIPTION],
                         self._description)
        self.assertEqual(self.target2._body[self.target.TYPE], "")
        self.assertEqual(self.target2._body[self.target.SUPER_TYPE], "")
        self.assertEqual(len(self.target2._body[self.target.CONNECTION_TYPES]), 0)
        self.assertEqual(self.target2._body[self.target.DESCRIPTION], "")

    def test_type_property(self):
        self.assertEqual(self.target.type, self._type)

    def test_super_type_property(self):
        self.assertEqual(self.target.super_type, self._super_type)

    def test_connection_types_property(self):
        self.assertEqual(self.target.connection_types, self._connection_types)

    def test_description_property(self):
        self.assertEqual(self.target.description, self._description)

    def test_create_from_packed_Version_NotNone_And_packed_object(self):
        self.value = {"type": self._type,
                      "super_type": self._super_type, 
                      "connection_types": self._connection_types, 
                      "description": self._description
                      }
        # create_from_packed_test
        self.result = self.target.create_from_packed(self.value)
        self.assertEqual(self.result._body[self.target.TYPE],
                         self._type)
        self.assertEqual(self.result._body[self.target.SUPER_TYPE],
                         self._super_type)
        self.assertEqual(self.result._body[self.target.CONNECTION_TYPES],
                         self._connection_types)
        self.assertEqual(self.result._body[self.target.DESCRIPTION],
                         self._description)

        # packed_object test
        self.result2 = self.result.packed_object()
        self.assertEqual(self.result2[self.target.TYPE],
                         self._type)
        self.assertEqual(self.result2[self.target.SUPER_TYPE],
                         self._super_type)
        self.assertEqual(self.result2[self.target.CONNECTION_TYPES],
                         self._connection_types)
        self.assertEqual(self.result2[self.target.DESCRIPTION],
                         self._description)