コード例 #1
0
ファイル: test_schemas.py プロジェクト: filc/python-nimoy
def test_document_schema_from_json():
    sample_json = {
        'fields': {
            'name': {'type': 'nimoy.fields.TextField', 'required': False},
            'email': {'type': 'nimoy.fields.TextField', 'required': True}
            },
        'indexes': [('email',)],
    }
    schema = DocumentSchema.from_json(json_string=json.dumps(sample_json))
    assert schema is not None
    assert isinstance(schema, DocumentSchema)
    assert schema._fields['name']['type'] == TextField
コード例 #2
0
ファイル: test_schemas.py プロジェクト: filc/python-nimoy
def test_document_schema_to_dict():
    sample_json2 = json.dumps(ensure_key_order({
        'fields': {'email': {'type': 'nimoy.fields.TextField', 'required': True}},
        'indexes': [['email']],
        'options': {},
    }))
    schema = DocumentSchema.from_json(sample_json2)
    sample_dict = schema.to_dict()
    sample_json = schema.to_json()
    assert sample_dict is not None
    assert sample_dict['fields']['email']['type'] == 'nimoy.fields.TextField'
    assert sample_json == sample_json2