Exemple #1
0
def test_validate_relpath_empty_relpath(caplog):
    relpath = ''
    settings = BookstoreSettings(fs_cloning_basedir="/anything")
    with pytest.raises(HTTPError):
        with caplog.at_level(logging.INFO):
            fs_clonepath = validate_relpath(relpath, settings, log)
    assert "Request received with empty relpath." in caplog.text
Exemple #2
0
def test_validate_relpath_escape_basedir(caplog):
    relpath = '../hi'
    settings = BookstoreSettings(fs_cloning_basedir="/anything")
    with pytest.raises(HTTPError):
        with caplog.at_level(logging.INFO):
            fs_clonepath = validate_relpath(relpath, settings, log)
    assert f"Request to clone from a path outside of base directory" in caplog.text
Exemple #3
0
def test_collect_handlers_only_version():
    expected = [('/api/bookstore', BookstoreVersionHandler)]
    web_app = Application()
    mock_settings = {"BookstoreSettings": {"enable_cloning": False}}
    bookstore_settings = BookstoreSettings(config=Config(mock_settings))
    validation = validate_bookstore(bookstore_settings)
    handlers = collect_handlers(log, '/', validation)
    assert expected == handlers
def test_disable_cloning():
    """Tests that all bookstore features validate with an s3_bucket."""
    expected = {
        "bookstore_valid": True,
        "publish_valid": True,
        "archive_valid": True,
        "clone_valid": False,
    }
    settings = BookstoreSettings(s3_bucket="A_bucket", enable_cloning=False)
    assert validate_bookstore(settings) == expected
def test_validate_bookstore_defaults():
    """Tests that all bookstore validates with default values."""
    expected = {
        "bookstore_valid": False,
        "publish_valid": False,
        "archive_valid": False,
        "clone_valid": True,
    }
    settings = BookstoreSettings()
    assert validate_bookstore(settings) == expected
def test_validate_bookstore_workspace():
    """Tests that bookstore does not validate with an empty workspace_prefix."""
    expected = {
        "bookstore_valid": True,
        "publish_valid": True,
        "archive_valid": False,
        "clone_valid": True,
    }
    settings = BookstoreSettings(s3_bucket="A_bucket", workspace_prefix="")
    assert validate_bookstore(settings) == expected
def test_validate_bookstore_endpoint():
    """Tests that bookstore does not validate with an empty s3_endpoint_url."""
    expected = {
        "bookstore_valid": False,
        "publish_valid": False,
        "archive_valid": False,
        "clone_valid": True,
    }
    settings = BookstoreSettings(s3_endpoint_url="")
    assert validate_bookstore(settings) == expected
def test_disable_cloning():
    """Tests that cloning from s3_bucket can be disabled."""
    expected = {
        "bookstore_valid": True,
        "publish_valid": True,
        "archive_valid": True,
        "s3_clone_valid": False,
        "fs_clone_valid": False,
    }
    settings = BookstoreSettings(s3_bucket="A_bucket", enable_s3_cloning=False)
    assert validate_bookstore(settings) == expected
def test_validate_bookstore_bucket():
    """Tests that bookstore features validate with an s3_bucket."""
    expected = {
        "bookstore_valid": True,
        "publish_valid": True,
        "archive_valid": True,
        "s3_clone_valid": True,
        "fs_clone_valid": False,
    }
    settings = BookstoreSettings(s3_bucket="A_bucket")
    assert validate_bookstore(settings) == expected
def test_enable_fs_cloning():
    """Tests that file system cloning works even if s3 cloning is disabled."""
    expected = {
        "bookstore_valid": False,
        "publish_valid": False,
        "archive_valid": False,
        "s3_clone_valid": False,
        "fs_clone_valid": True,
    }
    settings = BookstoreSettings(enable_s3_cloning=False,
                                 fs_cloning_basedir="/Users/bookstore")
    assert validate_bookstore(settings) == expected
Exemple #11
0
def bookstore_settings(request):
    mock_settings = {
        "BookstoreSettings": {
            "s3_access_key_id": "mock_id",
            "s3_secret_access_key": "mock_access",
            "s3_bucket": "my_bucket",
        }
    }
    config = Config(mock_settings)
    bookstore_settings = BookstoreSettings(config=config)
    if request.cls is not None:
        request.cls.bookstore_settings = bookstore_settings
    return bookstore_settings
Exemple #12
0
def test_collect_handlers_all():
    expected = [
        ('/api/bookstore', BookstoreVersionHandler),
        ('/api/bookstore/publish%s' % path_regex, BookstorePublishAPIHandler),
        ('/api/bookstore/clone(?:/?)*', BookstoreCloneAPIHandler),
        ('/bookstore/clone(?:/?)*', BookstoreCloneHandler),
    ]
    web_app = Application()
    mock_settings = {"BookstoreSettings": {"s3_bucket": "mock_bucket"}}
    bookstore_settings = BookstoreSettings(config=Config(mock_settings))
    validation = validate_bookstore(bookstore_settings)
    handlers = collect_handlers(log, '/', validation)
    assert expected == handlers
def test_relative_basepath(caplog):
    """Tests that file system cloning works even if s3 cloning is disabled."""
    expected = {
        "bookstore_valid": False,
        "publish_valid": False,
        "archive_valid": False,
        "s3_clone_valid": False,
        "fs_clone_valid": False,
    }
    fs_cloning_basedir = "Users/jupyter"
    settings = BookstoreSettings(enable_s3_cloning=False,
                                 fs_cloning_basedir=fs_cloning_basedir)
    with caplog.at_level(logging.INFO):
        actual = validate_bookstore(settings)
    assert actual == expected
    assert f"{fs_cloning_basedir} is not an absolute path," in caplog.text
Exemple #14
0
def test_collect_only_fs_clone():
    expected = [
        ('/api/bookstore', BookstoreVersionHandler),
        ('/bookstore/fs-clone(?:/?)*', BookstoreFSCloneHandler),
        ('/api/bookstore/fs-clone(?:/?)*', BookstoreFSCloneAPIHandler),
    ]
    web_app = Application()
    mock_settings = {
        "BookstoreSettings": {
            "published_prefix": "",
            "fs_cloning_basedir": "/Users/jupyter",
            "enable_s3_cloning": False,
        }
    }
    bookstore_settings = BookstoreSettings(config=Config(mock_settings))
    validation = validate_bookstore(bookstore_settings)
    handlers = collect_handlers(log, '/', validation)
    assert expected == handlers
Exemple #15
0
def test_validate_bookstore_published():
    """Tests that bookstore does not validate with an empty published_prefix."""
    settings = BookstoreSettings(published_prefix="")
    assert not validate_bookstore(settings)
Exemple #16
0
def test_validate_bookstore_defaults():
    """Tests that all bookstore validates with default values."""
    settings = BookstoreSettings()
    assert not validate_bookstore(settings)['bookstore_valid']
    assert validate_bookstore(settings)['publish_valid']
    assert validate_bookstore(settings)['archive_valid']
Exemple #17
0
def test_validate_relpath():
    relpath = 'hi'
    settings = BookstoreSettings(fs_cloning_basedir="/anything")
    fs_clonepath = validate_relpath(relpath, settings, log)
    assert fs_clonepath == Path("/anything/hi")
Exemple #18
0
def test_validate_bookstore_defaults():
    """Tests that all bookstore validates with default values."""
    settings = BookstoreSettings()
    assert validate_bookstore(settings)
Exemple #19
0
def test_validate_bookstore_bucket():
    """Tests that bookstore does not validate with an empty s3_bucket."""
    settings = BookstoreSettings(s3_bucket="")
    assert not validate_bookstore(settings)
Exemple #20
0
def test_validate_bookstore_endpoint():
    """Tests that bookstore does not validate with an empty s3_endpoint_url."""
    settings = BookstoreSettings(s3_endpoint_url="")
    assert not validate_bookstore(settings)
Exemple #21
0
def test_validate_bookstore_workspace():
    """Tests that bookstore does not validate with an empty workspace_prefix."""
    settings = BookstoreSettings(workspace_prefix="")
    assert not validate_bookstore(settings)