Skip to content

Commit

Permalink
Fix test?
Browse files Browse the repository at this point in the history
  • Loading branch information
infirit committed Dec 23, 2024
1 parent 09319fd commit ce65c68
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions test/main/test_netconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit ce65c68

Please sign in to comment.