mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-10 12:16:49 +00:00
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.
This commit is contained in:
parent
0906838193
commit
c55f52f025
154 changed files with 27 additions and 39 deletions
|
|
@ -1,54 +0,0 @@
|
|||
"""A running VM's addresses come from the guest agent when it answers and
|
||||
from the host's ARP table, so a VM without an agent shows its IPv4 address."""
|
||||
|
||||
import unittest
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
if not settings.configured:
|
||||
settings.configure(MAC_OUI="52:54:10")
|
||||
|
||||
from libvirt import VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT, VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_ARP
|
||||
from vrtManager.instance import wvmInstance
|
||||
|
||||
MAC = "52:54:00:00:00:01"
|
||||
ARP = {"vnet0": {"hwaddr": MAC, "addrs": [{"type": 0, "addr": "192.0.2.10", "prefix": 0}]}}
|
||||
AGENT = {"eth0": {"hwaddr": MAC, "addrs": [{"type": 0, "addr": "192.0.2.20", "prefix": 24}]}}
|
||||
|
||||
|
||||
def vm(agent):
|
||||
inst = wvmInstance.__new__(wvmInstance)
|
||||
inst._ip_cache = None
|
||||
inst.instance = MagicMock()
|
||||
inst.instance.interfaceAddresses.side_effect = lambda source: {
|
||||
VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT: AGENT,
|
||||
VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_ARP: ARP,
|
||||
}[source]
|
||||
patch.object(inst, "get_status", return_value=1).start()
|
||||
patch.object(inst, "is_agent_ready", return_value=agent).start()
|
||||
return inst
|
||||
|
||||
|
||||
class InterfaceAddressesTestCase(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
patch.stopall()
|
||||
|
||||
def test_a_vm_without_an_agent_shows_its_arp_address(self):
|
||||
inst = vm(agent=False)
|
||||
self.assertEqual(inst.get_interface_addresses(MAC), (["192.0.2.10"], []))
|
||||
self.assertEqual(
|
||||
[c.args for c in inst.instance.interfaceAddresses.call_args_list], [(VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_ARP,)]
|
||||
)
|
||||
|
||||
def test_the_agents_address_comes_first(self):
|
||||
inst = vm(agent=True)
|
||||
self.assertEqual(inst.get_interface_addresses(MAC), (["192.0.2.20"], []))
|
||||
self.assertEqual(
|
||||
[c.args for c in inst.instance.interfaceAddresses.call_args_list],
|
||||
[(VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT,), (VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_ARP,)],
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue