Ejemplo n.º 1
0
def gradebook(request: SubRequest) -> Gradebook:
    gb = api.Gradebook("sqlite:///:memory:")

    def fin() -> None:
        gb.close()
    request.addfinalizer(fin)
    return gb
Ejemplo n.º 2
0
def setup_dir(request: SubRequest) -> None:
    os.mkdir('test-dir', mode=0o777)

    def teardown_dir() -> None:
        os.rmdir('test-dir-1')

    request.addfinalizer(teardown_dir)
Ejemplo n.º 3
0
def course_dir(request: SubRequest) -> str:
    path = tempfile.mkdtemp(prefix='tmp-coursedir-')

    def fin() -> None:
        rmtree(path)
    request.addfinalizer(fin)

    return path
Ejemplo n.º 4
0
def empty_dir(request: SubRequest) -> str:
    dirpath = tempfile.NamedTemporaryFile().name

    def _remove_empty_dir():
        shutil.rmtree(dirpath)

    os.makedirs(dirpath)
    request.addfinalizer(_remove_empty_dir)
    return dirpath
Ejemplo n.º 5
0
def user_fx(request: SubRequest, db_fx: database.Database) -> dict:
    params_data = {'login': '******', 'password': get_password_hash('test')}
    db_fx[DbCollection.USER].insert_one(params_data.copy())

    def remove_user():
        db_fx[DbCollection.USER].delete_one(params_data)

    request.addfinalizer(remove_user)
    return {'login': '******', 'password': '******'}
Ejemplo n.º 6
0
def env(request: SubRequest) -> dict:
    old_env = os.environ.copy()

    def fin() -> None:
        os.environ = old_env

    request.addfinalizer(fin)

    return os.environ
Ejemplo n.º 7
0
def db(request: SubRequest) -> str:
    path = tempfile.mkdtemp(prefix='tmp-dbdir-')
    dbpath = os.path.join(path, "nbgrader_test.db")

    def fin() -> None:
        rmtree(path)
    request.addfinalizer(fin)

    return "sqlite:///" + dbpath
Ejemplo n.º 8
0
def app(request: SubRequest) -> Flask:
    app = create_app("testing")
    ctx = app.app_context()
    ctx.push()

    def teardown():
        ctx.pop()

    request.addfinalizer(teardown)
    return app
Ejemplo n.º 9
0
def session(app: Flask, request: SubRequest) -> scoped_session:
    def teardown():
        _db.session.rollback()
        _db.drop_all()
        _db.session.commit()

    _db.app = app
    _db.drop_all()
    _db.create_all()

    request.addfinalizer(teardown)

    return _db.session
Ejemplo n.º 10
0
async def event_catcher_with_namespace(app_test_client: TestClientProtocol,
                                       request: SubRequest):
    """ catch events as they happen in the background """
    _catcher = EventsCatcher(app_test_client=app_test_client,
                             blueprint_path='/events',
                             namespace='ns1')

    def teardown():
        _catcher._stop.set()

    request.addfinalizer(teardown)

    async with _catcher:
        yield _catcher
Ejemplo n.º 11
0
def auth_token_fx(request: SubRequest, db_fx: database.Database,
                  user_fx: dict) -> dict:
    auth_collection: collection.Collection = db_fx[DbCollection.AUTH]
    login: str = user_fx.get('login')
    token = str(uuid4())

    auth_collection.replace_one({'login': login}, {
        'login': login,
        'token': token,
        'expire': datetime.now() + timedelta(10)
    },
                                upsert=True)

    def remove_auth() -> None:
        db_fx[DbCollection.AUTH].delete_one({'login': login})

    request.addfinalizer(remove_auth)
    return {'Authorization': token}
Ejemplo n.º 12
0
def temp_cwd(request: SubRequest, course_dir: str) -> str:
    orig_dir = os.getcwd()
    path = tempfile.mkdtemp(prefix='tmp-cwd-')
    os.chdir(path)

    with open("nbgrader_config.py", "w") as fh:
        fh.write(dedent(
            """
            c = get_config()
            c.CourseDirectory.root = r"{}"
            """.format(course_dir)
        ))

    def fin() -> None:
        os.chdir(orig_dir)
        rmtree(path)
    request.addfinalizer(fin)

    return path
Ejemplo n.º 13
0
async def quart_events_catcher(app_test_client: TestClientProtocol,
                               request: SubRequest):
    def _getini(name, default=None):
        """
            getini returns an empty string instead of None;
            this helper fixes that
        """
        _val = request.config.getini(name)
        return _val if len(_val) > 0 else default

    """ catch events from quart-events as they are generated in the background """
    _catcher = EventsCatcher(app_test_client=app_test_client,
                             blueprint_path=_getini('quart_events_path',
                                                    default='/events'),
                             namespace=_getini('quart_events_namespace',
                                               default=None))

    def teardown():
        _catcher._stop.set()

    request.addfinalizer(teardown)

    async with _catcher:
        yield _catcher
Ejemplo n.º 14
0
def output(request: SubRequest, capfd: CaptureFixture):
    cap = CapLines(capfd)
    request.addfinalizer(cap.cleanup)
    return cap
Ejemplo n.º 15
0
def next_level_repo(request: SubRequest) -> str:
    next_level_repo = TestRepo(RepoType.Local, Template.NextDirWithGitRemoteUpstream)
    request.addfinalizer(next_level_repo.destroy)
    return next_level_repo.setup().repo_path
Ejemplo n.º 16
0
def immediate_level_repo(request: SubRequest) -> str:
    immediate_level_repo = TestRepo(RepoType.Local, Template.EmptyDirWithGitRemoteUpstream)
    request.addfinalizer(immediate_level_repo.destroy)
    return immediate_level_repo.setup().repo_path
Ejemplo n.º 17
0
def multi_notebook_category(request: SubRequest) -> str:
    multi_notebook_repo = TestRepo(RepoType.Local, Template.MultiNotebookCategory)
    request.addfinalizer(multi_notebook_repo.destroy)
    return multi_notebook_repo.setup().repo_path
Ejemplo n.º 18
0
def metadata_rich_notebooks(request: SubRequest) -> str:
    metadata_rich_repo = TestRepo(RepoType.Local, Template.MetadataRichNotebooks)
    request.addfinalizer(metadata_rich_repo.destroy)
    return metadata_rich_repo.setup().repo_path
Ejemplo n.º 19
0
def quick_build_collection(request: SubRequest) -> str:
    quick_build_repo = TestRepo(RepoType.Local, Template.QuickBuild)
    request.addfinalizer(quick_build_repo.destroy)
    return quick_build_repo.setup().repo_path
Ejemplo n.º 20
0
def repo_with_html(request: SubRequest) -> str:
    html_repo = TestRepo(RepoType.Local, Template.RepoWithHTML)
    request.addfinalizer(html_repo.destroy)
    return html_repo.setup().repo_path
Ejemplo n.º 21
0
def single_collection_repo__immediate_categories(request: SubRequest) -> str:
    immediate_categories_repo = TestRepo(RepoType.Local, Template.SingleCollectionImmediateCategories)
    request.addfinalizer(immediate_categories_repo.destroy)
    return immediate_categories_repo.setup().repo_path
Ejemplo n.º 22
0
def single_collection_repo__nth_categories(request: SubRequest) -> str:
    nth_categories_repo = TestRepo(RepoType.Local, Template.SingleCollectionNthCategories)
    request.addfinalizer(nth_categories_repo.destroy)
    return nth_categories_repo.setup().repo_path
Ejemplo n.º 23
0
def multi_collection_repo(request: SubRequest):
    multi_collection_repo = TestRepo(RepoType.Local, Template.MultiCollection)
    request.addfinalizer(multi_collection_repo.destroy)
    return multi_collection_repo.setup().repo_path
Ejemplo n.º 24
0
def single_collection_repo(request: SubRequest):
    single_collection_repo = TestRepo(RepoType.Local, Template.SingleCollection)
    request.addfinalizer(single_collection_repo.destroy)
    return single_collection_repo.setup().repo_path
Ejemplo n.º 25
0
def remove_file(request: SubRequest) -> None:
    request.addfinalizer(lambda: os.remove(_name))
Ejemplo n.º 26
0
def tempfiles(request: SubRequest) -> Tempfiles:
    t = Tempfiles()
    request.addfinalizer(t.cleanup)
    return t
Ejemplo n.º 27
0
def executed_notebook_collection(request: SubRequest) -> str:
    executed_notebook_repo = TestRepo(RepoType.Local, Template.ExecutedCollection)
    request.addfinalizer(executed_notebook_repo.destroy)
    return executed_notebook_repo.setup().repo_path
Ejemplo n.º 28
0
def multi_level_ignore_repo(request: SubRequest):
    ignore_repo = TestRepo(RepoType.Local, Template.MultiLevelIgnore)
    request.addfinalizer(ignore_repo.destroy)
    return ignore_repo.setup().repo_path
Ejemplo n.º 29
0
def git_config_file(request: SubRequest) -> str:
    git_config_repo = TestRepo(RepoType.Local, Template.OnlyGitConfigFile)
    request.addfinalizer(git_config_repo.destroy)
    return git_config_repo.setup().repo_path