mirror of
https://github.com/chatmail/relay.git
synced 2026-05-20 12:58:04 +00:00
tests: first attempt to mock shell() call
This commit is contained in:
@@ -11,13 +11,15 @@ All functions of this module
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
from pprint import pprint
|
||||||
from .rshell import CalledProcessError, shell, log_progress
|
from .rshell import CalledProcessError, shell, log_progress
|
||||||
|
|
||||||
|
|
||||||
def perform_initial_checks(mail_domain, pre_command=""):
|
def perform_initial_checks(mail_domain, pre_command=""):
|
||||||
"""Collecting initial DNS settings."""
|
"""Collecting initial DNS settings."""
|
||||||
assert mail_domain
|
assert mail_domain
|
||||||
|
pprint("rdns.perform_initial_checks: " + shell.__module__)
|
||||||
|
|
||||||
if not shell("dig", fail_ok=True, print=log_progress):
|
if not shell("dig", fail_ok=True, print=log_progress):
|
||||||
shell("apt-get update && apt-get install -y dnsutils", print=log_progress)
|
shell("apt-get update && apt-get install -y dnsutils", print=log_progress)
|
||||||
A = query_dns("A", mail_domain)
|
A = query_dns("A", mail_domain)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import sys
|
import sys
|
||||||
|
from pprint import pprint
|
||||||
from subprocess import DEVNULL, CalledProcessError, check_output
|
from subprocess import DEVNULL, CalledProcessError, check_output
|
||||||
|
|
||||||
|
|
||||||
@@ -9,6 +9,7 @@ def log_progress(data):
|
|||||||
|
|
||||||
|
|
||||||
def shell(command, fail_ok=False, print=print):
|
def shell(command, fail_ok=False, print=print):
|
||||||
|
pprint("test_cmdeploy: " + shell.__module__)
|
||||||
print(f"$ {command}")
|
print(f"$ {command}")
|
||||||
args = dict(shell=True)
|
args = dict(shell=True)
|
||||||
if fail_ok:
|
if fail_ok:
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import pytest
|
|||||||
|
|
||||||
from cmdeploy.cmdeploy import get_parser, main
|
from cmdeploy.cmdeploy import get_parser, main
|
||||||
from cmdeploy.www import get_paths
|
from cmdeploy.www import get_paths
|
||||||
|
import cmdeploy.remote.rshell
|
||||||
|
import cmdeploy.dns
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
@@ -59,3 +61,27 @@ def test_www_folder(example_config, tmp_path):
|
|||||||
assert www_path == tmp_path
|
assert www_path == tmp_path
|
||||||
assert src_dir == src_path
|
assert src_dir == src_path
|
||||||
assert build_dir == tmp_path.joinpath("build")
|
assert build_dir == tmp_path.joinpath("build")
|
||||||
|
|
||||||
|
|
||||||
|
def test_dns_when_ssh_docker(monkeypatch):
|
||||||
|
commands = []
|
||||||
|
|
||||||
|
def shell(command, fail_ok=None, print=None):
|
||||||
|
assert command == False
|
||||||
|
commands.append(command)
|
||||||
|
|
||||||
|
# mock shell function to add called commands to a global list
|
||||||
|
monkeypatch.setattr(
|
||||||
|
cmdeploy.remote.rshell, shell.__name__, shell
|
||||||
|
) # still doesn't get called in get_initial_remote_data :(
|
||||||
|
print("test_cmdeploy: " + shell.__module__)
|
||||||
|
# run cmdeploy dns with --ssh-host
|
||||||
|
# @docker
|
||||||
|
cmdeploy.dns.get_initial_remote_data("@docker", "chatmail.example.org")
|
||||||
|
for cmd in commands:
|
||||||
|
print(cmd)
|
||||||
|
# localhost
|
||||||
|
# @local
|
||||||
|
# without --ssh-host
|
||||||
|
# check which commands were called
|
||||||
|
assert False
|
||||||
|
|||||||
Reference in New Issue
Block a user