35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
|
"""Test singleuser module."""
|
||
|
import sys
|
||
|
|
||
|
from glicid_spawner import singleuser
|
||
|
|
||
|
|
||
|
async def mock_api_request(_, **kwargs):
|
||
|
"""Mock JupyterHub authentication service."""
|
||
|
sys.stdout.write(str(kwargs))
|
||
|
|
||
|
|
||
|
def test_singleuser(monkeypatch, capsys):
|
||
|
"""Test single user main query."""
|
||
|
monkeypatch.setattr(
|
||
|
singleuser.sys, 'argv', ['/bin/glicid-spawner-singleuser', 'jupyterhub-singleuser']
|
||
|
)
|
||
|
monkeypatch.setattr(singleuser.HubAuth, 'api_url', 'http://example.org')
|
||
|
monkeypatch.setattr(singleuser.HubAuth, '_api_request', mock_api_request)
|
||
|
monkeypatch.setattr(singleuser, 'random_port', lambda: 12345)
|
||
|
monkeypatch.setattr(singleuser, 'which', lambda cmd: cmd)
|
||
|
monkeypatch.setattr(singleuser, 'run_path', lambda cmd, **kwargs: sys.stderr.write(cmd))
|
||
|
|
||
|
_ = singleuser.main()
|
||
|
|
||
|
assert sys.argv[-1] == '--port=12345'
|
||
|
|
||
|
captured = capsys.readouterr()
|
||
|
|
||
|
assert (
|
||
|
captured.out
|
||
|
== "{'method': 'POST', 'url': 'http://example.org/batchspawner', 'body': '{\"port\": 12345}'}"
|
||
|
)
|
||
|
|
||
|
assert captured.err == 'jupyterhub-singleuser'
|