52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
"""Unit: `bot-bottle doctor` host prerequisite checks."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from bot_bottle.cli import doctor
|
|
|
|
|
|
class TestDoctor(unittest.TestCase):
|
|
def test_success_when_prerequisites_present(self):
|
|
with tempfile.TemporaryDirectory() as tmp, patch.object(
|
|
doctor.Path, "home", return_value=Path(tmp),
|
|
), patch.object(
|
|
doctor.shutil, "which", return_value="/usr/bin/docker",
|
|
), patch.object(
|
|
doctor.subprocess, "run",
|
|
return_value=MagicMock(returncode=0),
|
|
):
|
|
Path(tmp, ".bot-bottle").mkdir()
|
|
self.assertEqual(0, doctor.cmd_doctor([]))
|
|
|
|
def test_missing_config_fails(self):
|
|
with tempfile.TemporaryDirectory() as tmp, patch.object(
|
|
doctor.Path, "home", return_value=Path(tmp),
|
|
), patch.object(
|
|
doctor.shutil, "which", return_value="/usr/bin/docker",
|
|
), patch.object(
|
|
doctor.subprocess, "run",
|
|
return_value=MagicMock(returncode=0),
|
|
):
|
|
self.assertEqual(1, doctor.cmd_doctor([]))
|
|
|
|
def test_missing_docker_fails_before_daemon_check(self):
|
|
with tempfile.TemporaryDirectory() as tmp, patch.object(
|
|
doctor.Path, "home", return_value=Path(tmp),
|
|
), patch.object(
|
|
doctor.shutil, "which", return_value=None,
|
|
), patch.object(
|
|
doctor.subprocess, "run",
|
|
) as run:
|
|
Path(tmp, ".bot-bottle").mkdir()
|
|
self.assertEqual(1, doctor.cmd_doctor([]))
|
|
run.assert_not_called()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|