def test_serialize(self):
        bm = BaseModel(self.name, self.path)

        serialized = bm.serialize()
        self.assertEqual(len(serialized), 2)

        validate_set = [(bm.JSON_FIELD_NAME, self.name),
                        (bm.JSON_FIELD_PATH, self.path)]
        self.assertInDict(validate_set, serialized)
 def deserialize(cls, data):
     base = BaseModel.deserialize(data)
     return cls(
         base.name,
         base.path,
         data[cls.JSON_FIELD_SUBGROUPS],
         data[cls.JSON_FIELD_SUBOBJECTS]
     )
    def test_deserialize(self):
        serialized = {
            BaseModel.JSON_FIELD_NAME: self.name,
            BaseModel.JSON_FIELD_PATH: self.path
        }

        deserialized = BaseModel.deserialize(serialized)
        self.assertIsInstance(deserialized, BaseModel)
        self.assertEqual(deserialized.name, self.name)
        self.assertEqual(deserialized.path, self.path)
Example #4
0
    def deserialize(cls, data):
        def getValue(dataSet, fieldName, defaultValue):
            if fieldName in dataSet:
                return dataSet[fieldName]
            else:
                return defaultValue

        base = BaseModel.deserialize(data)
        return cls(base.name, base.path, data[cls.JSON_FIELD_GROUP_NAME],
                   data[cls.JSON_FIELD_OBJECT_NAME], data[cls.JSON_FIELD_TYPE],
                   data[cls.JSON_FIELD_CURRENT_VALUE],
                   getValue(data, cls.JSON_FIELD_MAXIMUM_VALUE, None),
                   getValue(data, cls.JSON_FIELD_MINIMUM_VALUE, None),
                   getValue(data, cls.JSON_FIELD_READONLY, False))
 def test_validate_object_name(self, object_name, is_valid):
     if is_valid:
         BaseModel.validate_object_name(object_name)
     else:
         with self.assertRaises(errors.InvalidObjectName):
             BaseModel.validate_object_name(object_name)
 def test_validate_group_name(self, group_name, is_valid):
     if is_valid:
         BaseModel.validate_group_name(group_name)
     else:
         with self.assertRaises(errors.InvalidGroupName):
             BaseModel.validate_group_name(group_name)
 def test_invalid_name(self, name, path, error):
     with self.assertRaises(error):
         BaseModel(name, path)
 def test_instantiation(self):
     bm = BaseModel(self.name, self.path)
     self.assertEqual(bm.name, self.name)
     self.assertEqual(bm.path, self.path)
 def deserialize(cls, data):
     base = BaseModel.deserialize(data)
     return cls(base.name, base.path, data[cls.JSON_FIELD_GROUP_NAME],
                data[cls.JSON_FIELD_SUBPROPERTIES])