Exemplo n.º 1
0
 def test_2ObjWithOutMetaData_Unicode(self):
     json = """{"type":"TestClass","id":"ID","val":{"type":"string","value":"i am unicode","metadata":{"python":{"type":"dataType","value":"unicode"}}}}"""
     tc = TestClass()
     tc.val = str(" ")
     ObjectFiwareConverter.fiware2Obj(json, tc, useMetaData=False)
     self.assertEqual(type(tc.val), str)
     self.assertEqual(tc.val, "i am unicode")  # Not unicode
Exemplo n.º 2
0
    def test_2Fiware2Obj_WithOut_ID_Value(self):
        json = ObjectFiwareConverter.obj2Fiware(TestClass(), showIdValue=False)

        tc = TestClass()
        tc.val = 42
        ObjectFiwareConverter.fiware2Obj(json, tc)

        self.assertEqual(tc.val, 1)
Exemplo n.º 3
0
    def test_2Fiware2Obj(self):
        json = ObjectFiwareConverter.obj2Fiware(TestClass())

        tc = TestClass()
        tc.val = 42
        ObjectFiwareConverter.fiware2Obj(json, tc)

        self.assertEqual(tc.val, 1)
Exemplo n.º 4
0
    def test_IntegerType(self):  ### TODO Accept Integers and other primitives?
        json = """{"id":"Task1","type":"Task","task":{"type":"Integer","value":0}}"""
        tc = TestClass()
        tc.val = 1  # set Number/Integer

        ObjectFiwareConverter.fiware2Obj(json, tc, setAttr=True)

        self.assertEqual(getattr(tc, 'task'), 0)
        self.assertEqual(getattr(tc, 'id'), 'Task1')
        self.assertEqual(getattr(tc, 'type'), 'Task')
        self.assertEqual(tc.val, 1)
Exemplo n.º 5
0
 def test_2ObjWithOutMetaData_Complex(self):
     json = """{"type": "TestClass","id": "ID","val": 
              {"type": "array","value": 
                 [{"type": "number","value": 0.0,"metadata": {"python": {"type": "dataType","value": "float"}}},
                  {"type": "number","value": 2.1,"metadata": {"python": {"type": "dataType","value": "float"}}}]
             ,"metadata": {"python": {"type": "dataType","value": "complex"}}}}"""
     tc = TestClass()
     tc.val = list()
     ObjectFiwareConverter.fiware2Obj(json, tc, useMetaData=False)
     self.assertEqual(type(tc.val), list)
     self.assertEqual(tc.val, [0, 2.1])  # Not unicode
Exemplo n.º 6
0
 def test_2Obj(self):
     json = """{"type": "TestClass", "id": "TestClass1", "val": {"type": "number", "value": 1, "metadata": {} } }"""
     tc = TestClass()
     tc.val = 123456789123456789123456789  # Evaluates automatically to Long for Python 2
     ObjectFiwareConverter.fiware2Obj(json, tc)
     self.assertEqual(tc.val, 1)
Exemplo n.º 7
0
 def test_2Fiware(self):
     ObjectFiwareConverter.obj2Fiware(TestClass(), ind=4)