I'm trying to learn this great python package. However, I'm currently receiving and error when converting the json file into object. I'm wondering whey the value of rabbit was mapped to RabbitInfo object instead of the "rabbit" field.
Error:
localhost is not an instance of <class 'test_serializer.RabbitInfo'>
I'm trying to learn this great python package. However, I'm currently receiving and error when converting the json file into object. I'm wondering whey the value of rabbit was mapped to RabbitInfo object instead of the "rabbit" field.
Error: localhost is not an instance of <class 'test_serializer.RabbitInfo'>
class SerializerTest(unittest.TestCase): def test_json_to_config(self): original_json = open(JSON_FILE).read().strip() json_dict = from_json(original_json) compose = to_model(Config, json_dict) compose.rabbit.host == "localhost"
@related.immutable() class RabbitInfo(object): host = related.StringField(required=True) user = related.StringField(required=True) password = related.StringField(required=True) vhost = related.StringField(required=True)
@related.immutable() class WebInfo(object): url = related.StringField(required=True) user = related.StringField(required=True) password = related.StringField(required=True) eauth = related.StringField(required=True)
@related.immutable() class Config(object): rabbit = related.MappingField(RabbitInfo, "rabbit") web = related.MappingField(WebInfo, "web")
config.json { "rabbit": { "host": "localhost", "user": "my_user", "password": "my_password", "vhost": "local" }, "web": { "url": "localhost", "user": "my_user", "password": "my_password", "eauth": "local" } }