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'
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
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
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
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
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
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, []
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