def test_validate_external_network_exception(self): test_net_client = Mock() test_net_client.show_subnet = Mock(side_effect=Exception) test_floating_ip_subnet_id = 'test_external_net' with self.assertRaises(Exception) as context: self.cp_validator.validate_floating_ip_sunbet(net_client=test_net_client, floating_ip_subnet_id=test_floating_ip_subnet_id, logger=self.mock_logger) self.assertTrue(context)
def test_external_network_not_external(self): test_net_client = Mock() mock_subnet_return_value = {'subnet': {'network_id': 'test_network_id'}} test_net_client.show_subnet = Mock(return_value=mock_subnet_return_value) net_list = {'networks': [{'router:external': False}]} test_net_client.list_networks = Mock(return_value=net_list) test_floating_ip_subnet_id = 'test_floating_ip_subnet_id' with self.assertRaises(ValueError) as context: result = self.cp_validator.validate_floating_ip_subnet(net_client=test_net_client, floating_ip_subnet_id=test_floating_ip_subnet_id, logger=self.mock_logger) self.assertTrue(context)
def test_validate_floating_ip_subnet(self): test_net_client = Mock() test_network_id = 'test_network_id' mock_subnet_result = {'subnet': {'network_id': test_network_id}} test_net_client.show_subnet = Mock(return_value=mock_subnet_result) test_floating_ip_subnet_id = 'test_floating_ip_subnet' net_list = {'networks': [{'router:external': True}]} test_net_client.list_networks = Mock(return_value=net_list) result = self.cp_validator.validate_floating_ip_subnet(net_client=test_net_client, floating_ip_subnet_id=test_floating_ip_subnet_id, logger=self.mock_logger) self.assertTrue(result)