def test_binds(monkeypatch): import jupyterhub monkeypatch.setattr("jupyterhub.spawner.Spawner", _MockSpawner) from dockerspawner.dockerspawner import DockerSpawner d = DockerSpawner() d.user = types.SimpleNamespace(name='xyz') d.volumes = { 'a': 'b', 'c': { 'bind': 'd', 'mode': 'Z' }, } assert d.volume_binds == { 'a': { 'bind': 'b', 'mode': 'rw' }, 'c': { 'bind': 'd', 'mode': 'Z' }, } d.volumes = {'a': 'b', 'c': 'd', 'e': 'f'} assert d.volume_mount_points == ['b', 'd', 'f'] d.volumes = {'/nfs/{username}': {'bind': '/home/{username}', 'mode': 'z'}} assert d.volume_binds == {'/nfs/xyz': {'bind': '/home/xyz', 'mode': 'z'}} assert d.volume_mount_points == ['/home/xyz']
def test_default_format_volume_name(monkeypatch): from dockerspawner.dockerspawner import DockerSpawner d = DockerSpawner() d.user = types.SimpleNamespace(name='*****@*****.**') d.volumes = {'data/{username}': {'bind': '/home/{username}', 'mode': 'z'}} assert d.volume_binds == {'data/[email protected]':{'bind': '/home/[email protected]', 'mode': 'z'}} assert d.volume_mount_points == ['/home/[email protected]']
def test_binds(monkeypatch): monkeypatch.setattr("jupyterhub.spawner.Spawner", _MockSpawner) from dockerspawner.dockerspawner import DockerSpawner d = DockerSpawner() d.user = types.SimpleNamespace(name="xyz") d.volumes = {"a": "b", "c": {"bind": "d", "mode": "Z"}} assert ( d.volume_binds == {"a": {"bind": "b", "mode": "rw"}, "c": {"bind": "d", "mode": "Z"}} ) d.volumes = {"a": "b", "c": "d", "e": "f"} assert d.volume_mount_points == ["b", "d", "f"] d.volumes = {"/nfs/{username}": {"bind": "/home/{username}", "mode": "z"}} assert d.volume_binds == {"/nfs/xyz": {"bind": "/home/xyz", "mode": "z"}} assert d.volume_mount_points == ["/home/xyz"]
def test_slugify(monkeypatch): import jupyterhub monkeypatch.setattr("jupyterhub.spawner.Spawner", _MockSpawner) from dockerspawner.dockerspawner import DockerSpawner d = DockerSpawner() d.user = types.SimpleNamespace(name='s! me') d.volumes = {'/opt/notebooks/{username}': '/home/jovyan/'} print(d.volume_binds['/opt/notebooks/s-me']) assert d.volume_binds['/opt/notebooks/s-me'] == {'bind': '/home/jovyan/', 'mode': 'rw'}
def test_binds(monkeypatch): import jupyterhub monkeypatch.setattr("jupyterhub.spawner.Spawner", _MockSpawner) from dockerspawner.dockerspawner import DockerSpawner d = DockerSpawner() d.user = types.SimpleNamespace(name='xyz') d.volumes = { 'a': 'b', 'c': {'bind': 'd', 'mode': 'Z'}, } assert d.volume_binds == { 'a': {'bind': 'b', 'mode': 'rw'}, 'c': {'bind': 'd', 'mode': 'Z'}, } d.volumes = {'a': 'b', 'c': 'd', 'e': 'f'} assert d.volume_mount_points == ['b', 'd', 'f'] d.volumes = {'/nfs/{username}': {'bind': '/home/{username}', 'mode': 'z'}} assert d.volume_binds == {'/nfs/xyz': {'bind': '/home/xyz', 'mode': 'z'}} assert d.volume_mount_points == ['/home/xyz']
def test_escaped_format_volume_name(monkeypatch): import dockerspawner from dockerspawner import DockerSpawner d = DockerSpawner() d.user = types.SimpleNamespace(name='*****@*****.**') d.volumes = {'data/{username}': {'bind': '/home/{username}', 'mode': 'z'}} d.format_volume_name = dockerspawner.volumenamingstrategy.escaped_format_volume_name assert d.volume_binds == {'data/user_40email_2Ecom':{'bind': '/home/user_40email_2Ecom', 'mode': 'z'}} assert d.volume_mount_points == ['/home/user_40email_2Ecom']
def test_default_format_volume_name(monkeypatch): from dockerspawner.dockerspawner import DockerSpawner d = DockerSpawner() d.user = types.SimpleNamespace(name="*****@*****.**") d.volumes = {"data/{username}": {"bind": "/home/{raw_username}", "mode": "z"}} assert ( d.volume_binds == {"data/user_40email_2Ecom": {"bind": "/home/[email protected]", "mode": "z"}} ) assert d.volume_mount_points == ["/home/[email protected]"]
def test_default_format_volume_name(monkeypatch): from dockerspawner.dockerspawner import DockerSpawner d = DockerSpawner() d.user = types.SimpleNamespace(name='*****@*****.**') d.volumes = {'data/{username}': {'bind': '/home/{username}', 'mode': 'z'}} assert d.volume_binds == { 'data/[email protected]': { 'bind': '/home/[email protected]', 'mode': 'z' } } assert d.volume_mount_points == ['/home/[email protected]']
def test_volume_naming_configuration(monkeypatch): from dockerspawner.dockerspawner import DockerSpawner d = DockerSpawner() d.user = types.SimpleNamespace(name='joe') d.volumes = {'data/{username}': {'bind': '/home/{username}', 'mode': 'z'}} def test_format(label_template, spawner): return "THIS IS A TEST" d.format_volume_name = test_format assert d.volume_binds == {'THIS IS A TEST':{'bind': 'THIS IS A TEST', 'mode': 'z'}} assert d.volume_mount_points == ['THIS IS A TEST']
def test_volume_naming_configuration(monkeypatch): from dockerspawner.dockerspawner import DockerSpawner d = DockerSpawner() d.user = types.SimpleNamespace(name="joe") d.volumes = {"data/{username}": {"bind": "/home/{username}", "mode": "z"}} def test_format(label_template, spawner): return "THIS IS A TEST" d.format_volume_name = test_format assert d.volume_binds == {"THIS IS A TEST": {"bind": "THIS IS A TEST", "mode": "z"}} assert d.volume_mount_points == ["THIS IS A TEST"]
def test_escaped_format_volume_name(monkeypatch): import dockerspawner from dockerspawner import DockerSpawner d = DockerSpawner() d.user = types.SimpleNamespace(name='*****@*****.**') d.volumes = {'data/{username}': {'bind': '/home/{username}', 'mode': 'z'}} d.format_volume_name = dockerspawner.volumenamingstrategy.escaped_format_volume_name assert d.volume_binds == { 'data/user_40email_2Ecom': { 'bind': '/home/user_40email_2Ecom', 'mode': 'z' } } assert d.volume_mount_points == ['/home/user_40email_2Ecom']
def test_escaped_format_volume_name(monkeypatch): import dockerspawner from dockerspawner import DockerSpawner d = DockerSpawner() d.user = types.SimpleNamespace(name="*****@*****.**") d.volumes = {"data/{username}": {"bind": "/home/{username}", "mode": "z"}} d.format_volume_name = dockerspawner.volumenamingstrategy.escaped_format_volume_name assert (d.volume_binds == { "data/user_40email_2Ecom": { "bind": "/home/user_40email_2Ecom", "mode": "z" } }) assert d.volume_mount_points == ["/home/user_40email_2Ecom"]
def test_escaped_format_volume_name(monkeypatch): import dockerspawner from dockerspawner import DockerSpawner d = DockerSpawner() d.user = types.SimpleNamespace(name="*****@*****.**") d.volumes = {"data/{username}": {"bind": "/home/{username}", "mode": "z"}} d.format_volume_name = dockerspawner.volumenamingstrategy.escaped_format_volume_name assert ( d.volume_binds == { "data/user_40email_2Ecom": {"bind": "/home/user_40email_2Ecom", "mode": "z"} } ) assert d.volume_mount_points == ["/home/user_40email_2Ecom"]
def test_dockerspawner_uses_raw_username_in_format_volume_name(): """ Does the dockerspawner uses correctly the username? """ d = DockerSpawner() # notice we're not using variable for username, # it helps understanding how volumes are binding d.user = types.SimpleNamespace(name='dbs__user5') d.volumes = {'data/{raw_username}': {'bind': '/home/{raw_username}'}} assert d.volume_binds == { 'data/dbs__user5': { 'bind': '/home/dbs__user5', 'mode': 'rw' } } assert d.volume_mount_points == ['/home/dbs__user5']
def test_volume_naming_configuration(monkeypatch): from dockerspawner.dockerspawner import DockerSpawner d = DockerSpawner() d.user = types.SimpleNamespace(name='joe') d.volumes = {'data/{username}': {'bind': '/home/{username}', 'mode': 'z'}} def test_format(label_template, spawner): return "THIS IS A TEST" d.format_volume_name = test_format assert d.volume_binds == { 'THIS IS A TEST': { 'bind': 'THIS IS A TEST', 'mode': 'z' } } assert d.volume_mount_points == ['THIS IS A TEST']