################################################################################ Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) ## and others ## ## All rights reserved. This program and the accompanying materials ## are made available under the terms of the Apache License, Version 2.0 ## which accompanies this distribution, and is available at ## http://www.apache.org/licenses/LICENSE-2.0 ################################################################################fromunittest.mockimportpatchfromdiscover.events.event_baseimportEventResultfromdiscover.events.event_interface_deleteimportEventInterfaceDeletefromtest.event_based_scan.test_data.event_payload_interface_delete \
importEVENT_PAYLOAD_INTERFACE_DELETE,PORT_DOC,ROUTER_DOCUMENTfromtest.event_based_scan.test_eventimportTestEventfromutils.utilimportencode_router_idclassTestInterfaceDelete(TestEvent):defget_by_id(self,env,object_id):ifobject_id==self.port_id:returnPORT_DOCelifobject_id==self.router_id:returnROUTER_DOCUMENTelse:returnNone@patch("discover.events.event_interface_delete.EventPortDelete")deftest_handle_interface_delete(self,port_delete_class_mock):self.values=EVENT_PAYLOAD_INTERFACE_DELETEself.payload=self.values['payload']self.interface=self.payload['router_interface']self.port_id=self.interface['port_id']self.host_id=self.values["publisher_id"].replace("network.","",1)self.router_id=encode_router_id(self.host_id,self.interface['id'])port_delete_mock=port_delete_class_mock.return_valueport_delete_mock.delete_port.return_value=EventResult(result=True)self.inv.get_by_id.side_effect=self.get_by_idres=EventInterfaceDelete().handle(self.env,self.values)self.assertTrue(res.result)self.assertTrue(port_delete_mock.delete_port.called)self.inv.set.assert_called_with(ROUTER_DOCUMENT)