spawner/tests/test_singleuser.py

35 lines
1.1 KiB
Python
Raw Permalink Normal View History

2024-02-14 11:32:26 +01:00
"""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'