Пример #1
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
Пример #2
0
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
Пример #3
0
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
Пример #4
0
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
Пример #5
0
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
Пример #6
0
    def setUp(self):
        super().setUp()

        validation = validate_bookstore(self.bookstore_settings)
        self.mock_application = Mock(
            spec=Application,
            ui_methods={},
            ui_modules={},
            settings={"bookstore": build_settings_dict(validation)},
            transforms=[],
        )
Пример #7
0
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
Пример #8
0
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
Пример #9
0
def test_build_settings_dict(bookstore_settings):
    expected = {
        'features': {
            'archive_valid': True,
            'bookstore_valid': True,
            'publish_valid': True,
            'clone_valid': True,
        },
        'release': version,
    }
    validation = validate_bookstore(bookstore_settings)
    assert expected == build_settings_dict(validation)
Пример #10
0
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
Пример #11
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
Пример #12
0
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
Пример #13
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
Пример #14
0
def test_validate_bookstore_defaults():
    """Tests that all bookstore validates with default values."""
    settings = BookstoreSettings()
    assert validate_bookstore(settings)
Пример #15
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)
Пример #16
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)
Пример #17
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)
Пример #18
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)
Пример #19
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']