Add singleuser tests
This commit is contained in:
parent
f1f6526daa
commit
1f4d8e28fa
2 changed files with 35 additions and 1 deletions
|
@ -34,5 +34,5 @@ def main(argv=None):
|
|||
run_path(cmd_path, run_name='__main__')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == '__main__': # pragma: no cover
|
||||
main()
|
||||
|
|
34
tests/test_singleuser.py
Normal file
34
tests/test_singleuser.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
"""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'
|
Loading…
Add table
Reference in a new issue