示例#1
0
def test_create_creator_with_roles(use_test_db, test_creator_dict):
    test_work_id = testing_utils.create_fake_work()['id']
    test_creator_dict['roles'] = {'illustrator': [test_work_id]}
    new_test_creator = logic.create_creator(test_creator_dict)
    with session_scope() as session:
        created_role_id = session.query(Role)\
            .filter_by(work_id=test_work_id, creator_id=new_test_creator['id'])\
            .first().id
    assert new_test_creator['roles'] == [created_role_id]
示例#2
0
def test_update_creator_with_roles(use_test_db, test_creator_dict):
    test_creator_id = testing_utils.create_fake_creator()['id']
    test_work_id = testing_utils.create_fake_work()['id']
    test_creator_dict['roles'] = {'illustrator': [test_work_id], 'author': [test_work_id]}
    test_creator_dict['related_creators'] = [test_creator_id]
    new_test_creator = logic.create_creator(test_creator_dict)

    test_creator_dict['aliases'].pop()
    test_creator_dict['roles'].pop('illustrator')
    updated_test_creator = logic.update_creator(new_test_creator['id'], test_creator_dict)
    with session_scope() as session:
        created_role = session.query(Role)\
            .filter_by(work_id=test_work_id, creator_id=new_test_creator['id'])\
            .first().to_dict()
        test_work = session.query(Work).filter_by(id=test_work_id).first().to_dict()
    assert test_work['roles'] == updated_test_creator['roles']
    assert test_creator_dict['aliases'] == updated_test_creator['aliases']
    assert 'author' == created_role['role']