Exemple #1
0
def test_language(db_conn, units_table):
    """
    Expect a unit to require a language.
    """

    unit, errors = Unit.insert({
        'name': 'Learn this',
        'body': 'Learn how to do this',
    })
    assert len(errors) == 0
    assert unit['language'] == 'en'
Exemple #2
0
def test_body(db_conn, units_table):
    """
    Expect a unit to require a body.
    """

    unit, errors = Unit.insert({
        'name': 'Learn this',
    })
    assert len(errors) == 1
    unit['body'] = 'Learn how to do this'
    unit, errors = unit.save()
    assert len(errors) == 0
Exemple #3
0
def test_tags(db_conn, units_table):
    """
    Expect a unit to allow tags.
    """

    unit, errors = Unit.insert({
        'name': 'Learn this',
        'body': 'Learn how to do this',
    })
    assert len(errors) == 0
    unit['tags'] = ['A', 'B']
    unit, errors = unit.save()
    assert len(errors) == 0
Exemple #4
0
def test_entity_id(db_conn, units_table):
    """
    Expect a unit to require an entity_id.
    """

    unit, errors = Unit.insert({
        'name': 'Learn this',
        'body': 'Learn how to do this',
    })
    assert len(errors) == 0
    unit['entity_id'] = 'JFKLD1234'
    unit, errors = unit.save()
    assert len(errors) == 0
Exemple #5
0
def test_previous(db_conn, units_table):
    """
    Expect a version previous_id to be a string or None.
    """

    unit, errors = Unit.insert({
        'name': 'Learn this',
        'body': 'Learn how to do this',
    })
    assert len(errors) == 0
    unit['previous_id'] = 'AFJkl345'
    unit, errors = unit.save()
    assert len(errors) == 0
Exemple #6
0
def test_status(db_conn, units_table):
    """
    Expect a unit status to be a string.
    """

    unit, errors = Unit.insert({
        'name': 'Learn this',
        'body': 'Learn how to do this',
    })
    assert len(errors) == 0
    assert unit['status'] == 'pending'
    unit['status'] = 'accepted'
    unit, errors = unit.save()
    assert len(errors) == 0
Exemple #7
0
def create_entity(data):
    """
    Given a kind and some json, call insert on that kind
    and return the results.
    """

    if 'card' in data:
        return Card.insert(data['card'])
        # TODO-1 This needs to also get the right card kind...
    elif 'unit' in data:
        return Unit.insert(data['unit'])
    elif 'set' in data:
        return Set.insert(data['set'])

    return None, []
Exemple #8
0
def create_entity(data):
    """
    Given a kind and some json, call insert on that kind
    and return the results.
    """

    if 'card' in data:
        return Card.insert(data['card'])
        # TODO-1 This needs to also get the right card kind...
    elif 'unit' in data:
        return Unit.insert(data['unit'])
    elif 'set' in data:
        return Set.insert(data['set'])

    return None, []
Exemple #9
0
def test_requires(db_conn, units_table):
    """
    Expect a unit to allow requires ids.
    """

    units_table.insert({
        'entity_id': 'A',
        'status': 'accepted',
        'created': r.now(),
    }).run(db_conn)
    unit, errors = Unit.insert(db_conn, {
        'name': 'Learn this',
        'body': 'Learn how to do this',
    })
    assert len(errors) == 0
    unit['require_ids'] = ['A']
    unit, errors = unit.save(db_conn)
    assert len(errors) == 0