Merge lp:~jtv/maas/split-macaddress-tests into lp:~maas-committers/maas/trunk

Proposed by Jeroen T. Vermeulen
Status: Merged
Approved by: Jeroen T. Vermeulen
Approved revision: no longer in the source branch.
Merged at revision: 2756
Proposed branch: lp:~jtv/maas/split-macaddress-tests
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 109 lines (+18/-13)
1 file modified
src/maasserver/models/tests/test_macaddress.py (+18/-13)
To merge this branch: bzr merge lp:~jtv/maas/split-macaddress-tests
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) Approve
Review via email: mp+231283@code.launchpad.net

Commit message

Split up a MACAddress test case before I add new tests to it. Preparation for an IPv6 branch.

Description of the change

This takes the original test case back to covering only a single method, as it did until I added tests for a second method the other day. Instead, I renamed the test case to reflect the name of the method it tested.

The method name didn't leave much room in the naming of the test methods to explain complex situations that need testing. Dedicating the test case to a single method lets me remove the tested method's name from the test functions' names.

Jeroen

To post a comment you must log in.
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Self-approving, since the only available reviewer is busy: affects only tests, simple, no functional change. I verified that the same number of tests gets run.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/models/tests/test_macaddress.py'
2--- src/maasserver/models/tests/test_macaddress.py 2014-08-18 11:06:11 +0000
3+++ src/maasserver/models/tests/test_macaddress.py 2014-08-19 02:34:45 +0000
4@@ -83,14 +83,15 @@
5 self.assertEqual(bytes_mac, mac.__str__())
6
7
8-class TestMACAddressForStaticIPClaiming(MAASServerTestCase):
9+class TestClaimStaticIPs(MAASServerTestCase):
10+ """Tests for `MACAddress.claim_static_ips`."""
11
12- def test_claim_statics_ip_returns_empty_if_no_cluster_interface(self):
13+ def test__returns_empty_if_no_cluster_interface(self):
14 # If mac.cluster_interface is None, we can't allocate any IP.
15 mac = factory.make_mac_address()
16 self.assertEquals([], mac.claim_static_ips())
17
18- def test_claim_static_ips_reserves_an_ip_address(self):
19+ def test__reserves_an_ip_address(self):
20 node = factory.make_node_with_mac_attached_to_nodegroupinterface()
21 mac = node.get_primary_mac()
22 [claimed_ip] = mac.claim_static_ips()
23@@ -99,20 +100,20 @@
24 self.assertEqual(
25 IPADDRESS_TYPE.AUTO, StaticIPAddress.objects.all()[0].alloc_type)
26
27- def test_claim_static_ips_sets_type_as_required(self):
28+ def test__sets_type_as_required(self):
29 node = factory.make_node_with_mac_attached_to_nodegroupinterface()
30 mac = node.get_primary_mac()
31 [claimed_ip] = mac.claim_static_ips(alloc_type=IPADDRESS_TYPE.STICKY)
32 self.assertEqual(IPADDRESS_TYPE.STICKY, claimed_ip.alloc_type)
33
34- def test_claim_static_ips_returns_none_if_no_static_range_defined(self):
35+ def test__returns_none_if_no_static_range_defined(self):
36 node = factory.make_node_with_mac_attached_to_nodegroupinterface()
37 mac = node.get_primary_mac()
38 mac.cluster_interface.static_ip_range_low = None
39 mac.cluster_interface.static_ip_range_high = None
40 self.assertEqual([], mac.claim_static_ips())
41
42- def test_claim_static_ips_raises_if_clashing_type(self):
43+ def test__raises_if_clashing_type(self):
44 node = factory.make_node_with_mac_attached_to_nodegroupinterface()
45 mac = node.get_primary_mac()
46 iptype = factory.pick_enum(
47@@ -123,7 +124,7 @@
48 StaticIPAddressTypeClash,
49 mac.claim_static_ips, alloc_type=iptype2)
50
51- def test_claim_static_ips_returns_existing_if_claiming_same_type(self):
52+ def test__returns_existing_if_claiming_same_type(self):
53 node = factory.make_node_with_mac_attached_to_nodegroupinterface()
54 mac = node.get_primary_mac()
55 iptype = factory.pick_enum(
56@@ -132,19 +133,23 @@
57 self.assertEqual(
58 [ip], mac.claim_static_ips(alloc_type=iptype))
59
60- def test_passes_requested_ip(self):
61+ def test__passes_requested_ip(self):
62 node = factory.make_node_with_mac_attached_to_nodegroupinterface()
63 mac = node.get_primary_mac()
64 ip = node.get_primary_mac().cluster_interface.static_ip_range_high
65 [allocation] = mac.claim_static_ips(requested_address=ip)
66 self.assertEqual(ip, allocation.ip)
67
68- def test_get_cluster_interfaces_returns_nothing_if_none_known(self):
69+
70+class TestGetClusterInterfaces(MAASServerTestCase):
71+ """Tests for `MACAddress.get_cluster_interfaces`."""
72+
73+ def test__returns_nothing_if_none_known(self):
74 self.assertItemsEqual(
75 [],
76 factory.make_mac_address().get_cluster_interfaces())
77
78- def test_get_cluster_interfaces_returns_cluster_interface_if_known(self):
79+ def test__returns_cluster_interface_if_known(self):
80 cluster = factory.make_node_group()
81 cluster_interface = factory.make_node_group_interface(cluster)
82 mac = factory.make_mac_address(cluster_interface=cluster_interface)
83@@ -152,7 +157,7 @@
84 [cluster_interface],
85 mac.get_cluster_interfaces())
86
87- def test_get_cluster_interfaces_includes_IPv6_cluster_interface(self):
88+ def test__includes_IPv6_cluster_interface(self):
89 # If the MAC is directly attached to an IPv4 cluster interface, but
90 # there's also an IPv6 cluster interface on the same network segment,
91 # both those cluster interfaces are included.
92@@ -171,7 +176,7 @@
93 [ipv4_interface, ipv6_interface],
94 mac.get_cluster_interfaces())
95
96- def test_get_cluster_interfaces_ignores_other_cluster_interfaces(self):
97+ def test__ignores_other_cluster_interfaces(self):
98 cluster = factory.make_node_group()
99 factory.make_node_group_interface(
100 nodegroup=cluster, network=factory.getRandomNetwork())
101@@ -182,7 +187,7 @@
102 [],
103 factory.make_mac_address(node=node).get_cluster_interfaces())
104
105- def test_get_cluster_interfaces_ignores_other_clusters(self):
106+ def test__ignores_other_clusters(self):
107 my_cluster = factory.make_node_group()
108 unrelated_cluster = factory.make_node_group()
109 my_interface = factory.make_node_group_interface(