1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-08 19:26:48 +00:00
webvirtcloud/vrtManager/tests/test_dhcp_leases.py
catborise c55f52f025 test: each app keeps its tests in a tests package
131 test modules sat next to the code they test; instances alone had
51 of them beside views.py and utils.py. They move into a
tests/ package per app, and the JavaScript checks into
webvirtcloud/tests/js. Each non-empty tests.py becomes tests/test_views.py;
the empty generated stubs are removed.

Imports of the app's own modules become absolute, paths built from
__file__ go one level up, the live helper is instances.tests.livetest,
and coverage omits */tests/*. The suite discovers the same 960 tests as
before.
2026-10-12 15:17:30 +03:00

36 lines
1.2 KiB
Python

"""refresh_dhcp_leases must raise a real exception (handled as a libvirt error),
not a bare string (which Python turns into TypeError, masking the cause)."""
import unittest
from unittest.mock import Mock
from django.conf import settings
if not settings.configured:
settings.configure(MAC_OUI="52:54:10")
from vrtManager import util
from vrtManager.network import wvmNetwork
def network_with_leases(side_effect):
net = wvmNetwork.__new__(wvmNetwork)
net.leases = None
net.net = Mock()
net.net.DHCPLeases.side_effect = side_effect
return net
class RefreshDhcpLeasesTestCase(unittest.TestCase):
def test_a_lease_error_raises_an_operation_error(self):
net = network_with_leases(Exception("no DHCP on this network"))
with self.assertRaises(util.OperationError):
net.refresh_dhcp_leases()
def test_the_error_keeps_the_cause_and_clears_leases(self):
cause = Exception("boom")
net = network_with_leases(cause)
with self.assertRaises(util.OperationError) as caught:
net.refresh_dhcp_leases()
self.assertIs(caught.exception.__cause__, cause)
self.assertEqual(net.leases, [])