예제 #1
0
def test_prepare_document(db_conn, vases_table):
    schema = vases_schema
    create_test_data_set(db_conn, vases_table)
    data = {
        'id':
        'ZdhhJQ9U9YJaanmfMEpm05qc',
        'name':
        ' celestial ',
        'shape':
        'round',
        'plants': [
            {
                'species': 'zzplant',
                'quantity': 2
            },
            {
                'species': 'rubbertree',
                'quantity': 1
            },
        ],
        'soil': {
            'color': 'black'
        }
    }
    result, errors = util.prepare_document(schema, data, db_conn)
    assert not errors
    result = omit(result, (
        'id',
        'modified',
        'created',
    ))
    assert result == omit(data, ('id', ))
예제 #2
0
파일: topic.py 프로젝트: wincax88/sagefy
def validate_topic(data, db_conn):
    """
    Validate a topic before saving it against the schema.
    """

    schema = topic_schema
    data, errors = prepare_document(schema, data, db_conn)
    return data, errors
예제 #3
0
def insert_follow(data, db_conn):
    """
    Create a new follow (user <-> entity).
    """

    schema = follow_schema
    data, errors = prepare_document(schema, data, db_conn)
    if errors:
        return None, errors
    errors = validate_uniqueness(data, db_conn)
    if errors:
        return None, errors
    errors = is_valid_entity(data, db_conn)
    if errors:
        return None, errors
    return insert_document(schema, data, db_conn)
예제 #4
0
def test_prepare_document(db_conn, vases_table):
    schema = vases_schema
    create_test_data_set(db_conn, vases_table)
    data = {
        'id': 'ZdhhJQ9U9YJaanmfMEpm05qc',
        'name': ' celestial ',
        'shape': 'round',
        'plants': [
            {'species': 'zzplant', 'quantity': 2},
            {'species': 'rubbertree', 'quantity': 1},
        ],
        'soil': {'color': 'black'}
    }
    result, errors = util.prepare_document(schema, data, db_conn)
    assert not errors
    result = omit(result, ('id', 'modified', 'created',))
    assert result == omit(data, ('id',))
예제 #5
0
def validate_post(data, db_conn):
    """
    Validate a post before saving it against the schema.
    """

    schema = get_post_schema(data)
    data, errors = prepare_document(schema, data, db_conn)
    if not errors:
        errors += is_valid_topic_id(data)
    if not errors:
        errors += is_valid_reply(data, db_conn)
    if data['kind'] == 'proposal':
        if not errors:
            errors += is_valid_version(data)
    if data['kind'] == 'vote':
        if not errors:
            errors += is_unique_vote(data, db_conn)
        if not errors:
            errors += is_valid_reply_kind(data, db_conn)
    return data, errors