def test_eq(self, SwitchCls): sw1 = mock.MagicMock() sw1.dpid = 1 sw2 = SwitchCls() sw2.dpid = 2 # It's really hard to mock this, because of using assert_type p1 = ofp_phy_port(port_no=1) p2 = ofp_phy_port(port_no=2) sw1.ports = [p1] sw2.ports = [p2] link1 = Link(sw1, p1, sw2, p2) link2 = Link(sw2, p2, sw1, p1) self.assertEquals(link1, link1) self.assertNotEquals(link1, link2)
def test_init(self, SwitchCls): sw1 = mock.MagicMock() sw1.dpid = 1 sw2 = SwitchCls() sw2.dpid = 2 # It's really hard to mock this, because of using assert_type p1 = ofp_phy_port(port_no=1) p2 = ofp_phy_port(port_no=2) sw1.ports = [p1] sw2.ports = [p2] link = Link(sw1, p1, sw2, p2) self.assertEquals(sw1.dpid, link.start_software_switch.dpid) self.assertEquals(sw2.dpid, link.end_software_switch.dpid) self.assertEquals(p1, link.start_port) self.assertEquals(p2, link.end_port)
def test_to_json(self): # Arrange sw1 = mock.Mock() sw1.dpid = 1 sw1.to_json.return_value = 1 sw2 = mock.Mock() sw2.dpid = 2 sw2.to_json.return_value = 2 # It's really hard to mock this, because of using assert_type p1 = ofp_phy_port(port_no=1) p2 = ofp_phy_port(port_no=2) sw1.ports = [p1] sw2.ports = [p2] link = Link(sw1, p1, sw2, p2) # Act json_dict = link.to_json() # Assert self.assertEquals(json_dict['start_node'], 1) self.assertEquals(json_dict['start_port']['port_no'], 1) self.assertEquals(json_dict['end_node'], 2) self.assertEquals(json_dict['end_port']['port_no'], 2)