'Test validates that a relevant exception is being raised when
there are more ports defined, than there is a quota for it.'

def test_validate_networks_over_limit_quota(self):

    requested_networks = [(uuids.my_netid1, '10.0.1.2', None, None), (uuids.my_netid2, '10.0.1.3', None, None)]
    list_port_values = [({'network_id': uuids.my_netid1, 'fixed_ips': 'ip_address=10.0.1.2', 'fields': 'device_id'}, {'ports': []}), ({'network_id': uuids.my_netid2, 'fixed_ips': 'ip_address=10.0.1.3', 'fields': 'device_id'}, {'ports': []}), ({'tenant_id': 'fake-project', 'fields': ['id']}, {'ports': [1, 2, 3, 4, 5]})]
    nets = [{'subnets': '1'}, {'subnets': '2'}]
    def _fake_list_ports(**search_opts):
        for (args, return_value) in list_port_values:
            if (args == search_opts):
                return return_value
    with test.nested(mock.patch.object(self.api, '_get_available_networks', return_value=nets), mock.patch.object(client.Client, 'list_ports', side_effect=_fake_list_ports), mock.patch.object(client.Client, 'show_quota', return_value={'quota': {'port': 1}})):
        exc = self.assertRaises(exception.PortLimitExceeded, self.api.validate_networks, self.context, requested_networks, 1)
        expected_exception_msg = ('The    number    of    defined    ports:    %(ports)d    is    over    the    limit:    %(quota)d' % {'ports': 5, 'quota': 1})
        self.assertEqual(expected_exception_msg, str(exc))
