

@test.create_stubs({
    api.network: ('floating_ip_supported', 'tenant_floating_ip_list', 'security_group_list'),
    api.nova: ('keypair_list', 'server_list'),
    api.base: ('is_service_enabled',),
    quotas: ('tenant_quota_usages',),
})
def _test_index(self, ec2_enabled=True, instanceless_ips=False):
    keypairs = self.keypairs.list()
    sec_groups = self.security_groups.list()
    floating_ips = self.floating_ips.list()
    if instanceless_ips:
        for fip in floating_ips:
            fip.instance_id = None
    quota_data = self.quota_usages.first()
    quota_data['security_groups']['available'] = 10
    if (not instanceless_ips):
        api.nova.server_list(IsA(http.HttpRequest)).AndReturn([self.servers.list(), False])
    api.nova.keypair_list(IsA(http.HttpRequest)).AndReturn(keypairs)
    api.network.floating_ip_supported(IsA(http.HttpRequest)).AndReturn(True)
    api.network.tenant_floating_ip_list(IsA(http.HttpRequest)).AndReturn(floating_ips)
    api.network.security_group_list(IsA(http.HttpRequest)).AndReturn(sec_groups)
    quotas.tenant_quota_usages(IsA(http.HttpRequest)).MultipleTimes().AndReturn(quota_data)
    api.base.is_service_enabled(IsA(http.HttpRequest), 'network').MultipleTimes().AndReturn(True)
    api.base.is_service_enabled(IsA(http.HttpRequest), 'ec2').MultipleTimes().AndReturn(ec2_enabled)
    self.mox.ReplayAll()
    res = self.client.get(INDEX_URL)
    self.assertTemplateUsed(res, 'project/access_and_security/index.html')
    self.assertItemsEqual(res.context['keypairs_table'].data, keypairs)
    self.assertItemsEqual(res.context['floating_ips_table'].data, floating_ips)
    sec_groups_from_ctx = res.context['security_groups_table'].data
    self.assertItemsEqual(sec_groups_from_ctx, sec_groups)
    self.assertTrue(all([(sec_groups_from_ctx[i].name <= sec_groups_from_ctx[(i + 1)].name) for i in range((len(sec_groups_from_ctx) - 1))]))
    if ec2_enabled:
        self.assertTrue(any(map((lambda x: isinstance(x, api_access.tables.DownloadEC2)), res.context['endpoints_table'].get_table_actions())))
    else:
        self.assertFalse(any(map((lambda x: isinstance(x, api_access.tables.DownloadEC2)), res.context['endpoints_table'].get_table_actions())))

dataset/ETHPy150Open openstack/horizon/openstack_dashboard/dashboards/project/access_and_security/tests.py AccessAndSecurityTests._test_index/original