From ce65c6861bd2a6925cbed05c177054890087785f Mon Sep 17 00:00:00 2001 From: Sander Sweers Date: Mon, 23 Dec 2024 02:02:48 +0100 Subject: [PATCH] Fix test? --- test/main/test_netconf.py | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/test/main/test_netconf.py b/test/main/test_netconf.py index 6bd0bc928..48770a372 100644 --- a/test/main/test_netconf.py +++ b/test/main/test_netconf.py @@ -2,6 +2,7 @@ import shutil import subprocess from ipaddress import IPv4Address +from pathlib import Path from subprocess import Popen from typing import Optional, List from unittest import TestCase @@ -24,8 +25,8 @@ def connect_ex(self, *_args: object) -> int: return self._ret -@patch("blueman.main.NetConf.have", return_value="/usr/bin/mydnsmasq") -@patch("blueman.main.NetConf.DnsMasqHandler._pid_path", PropertyMock(return_value="/tmp/pid")) +@patch("blueman.main.NetConf.have", return_value=Path("/usr/bin/mydnsmasq")) +@patch("blueman.main.NetConf.DnsMasqHandler._pid_path", PropertyMock(return_value=Path("/tmp/pid"))) class TestDnsmasqHandler(TestCase): @patch("blueman.main.NetConf.Popen", return_value=Popen("true")) @patch("blueman.main.NetConf.NetConf.lock") @@ -68,9 +69,9 @@ def _check_invocation(self, have_mock: Mock, popen_mock: Mock, additional_args: ) -@patch("blueman.main.NetConf.have", return_value="/usr/bin/mydhcpd") -@patch("blueman.main.NetConf.DhcpdHandler._pid_path", PropertyMock(return_value="/tmp/pid")) -@patch("blueman.main.NetConf.DHCP_CONFIG_FILE", "/tmp/dhcpd.conf") +@patch("blueman.main.NetConf.have", return_value=Path("/usr/bin/mydhcpd")) +@patch("blueman.main.NetConf.DhcpdHandler._pid_path", PropertyMock(return_value=Path("/tmp/pid"))) +@patch("blueman.main.NetConf.DHCP_CONFIG_FILE", Path("/tmp/dhcpd.conf")) @patch("blueman.main.NetConf.DNSServerProvider.get_servers", lambda: []) class TestDhcpdHandler(TestCase): @classmethod @@ -107,8 +108,8 @@ def _check_invocation(self, have_mock: Mock, popen_mock: Mock) -> None: ) -@patch("blueman.main.NetConf.have", return_value="/usr/bin/myudhcpd") -@patch("blueman.main.NetConf.UdhcpdHandler._pid_path", PropertyMock(return_value="/tmp/pid")) +@patch("blueman.main.NetConf.have", return_value=Path("/usr/bin/myudhcpd")) +@patch("blueman.main.NetConf.UdhcpdHandler._pid_path", PropertyMock(return_value=Path("/tmp/pid"))) @patch("blueman.main.NetConf.DNSServerProvider.get_servers", lambda: []) class TestUdhcpdHandler(TestCase): @classmethod @@ -148,16 +149,22 @@ def _check_invocation(self, have_mock: Mock, popen_mock: Mock) -> None: self.assertEqual(args[1], {"stderr": subprocess.PIPE}) -@patch("blueman.main.NetConf.NetConf._IPV4_SYS_PATH", "/tmp/blueman-test/ipv4") -@patch("blueman.main.NetConf.NetConf._RUN_PATH", "/tmp/blueman-test/run") +@patch("blueman.main.NetConf.NetConf._IPV4_SYS_PATH", Path("/tmp/blueman-test/ipv4")) +@patch("blueman.main.NetConf.NetConf._RUN_PATH", Path("/tmp/blueman-test/run")) @patch("blueman.main.NetConf.create_bridge") @patch("blueman.main.NetConf.call", return_value=0) class TestNetConf(TestCase): def setUp(self) -> None: - os.makedirs("/tmp/blueman-test/run", exist_ok=True) - os.makedirs("/tmp/blueman-test/ipv4/conf", exist_ok=True) - os.makedirs("/tmp/blueman-test/ipv4/conf/i0", exist_ok=True) - os.makedirs("/tmp/blueman-test/ipv4/conf/i1", exist_ok=True) + tmpdir = Path("/tmp/blueman-test") + tmpdir.joinpath("run").mkdir(parents=True) + tmpdir.joinpath("ipv4").mkdir(parents=True) + tmpdir.joinpath("ipv4/ip_forward").write_text("0") + + for iface in ("i0", "i1"): + ifacedir = tmpdir / "ipv4" / "conf" / iface + ifacedir.mkdir(parents=True) + ifacedir.joinpath("forwarding").write_text("0") + def tearDown(self) -> None: shutil.rmtree("/tmp/blueman-test")