コード例 #1
0
ファイル: tests.py プロジェクト: nitishb/horizon
 def test_usage_csv(self):
     now = timezone.now()
     usage_obj = api.nova.Usage(self.usages.first())
     quotas = self.quota_usages.first()
     api.keystone.tenant_list(IsA(http.HttpRequest), admin=True).AndReturn(self.tenants.list())
     api.usage_list(
         IsA(http.HttpRequest), datetime.datetime(now.year, now.month, 1, 0, 0, 0), Func(usage.almost_now)
     ).AndReturn([usage_obj])
     api.nova.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(quotas)
     self.mox.ReplayAll()
     csv_url = reverse("horizon:admin:overview:index") + "?format=csv"
     res = self.client.get(csv_url)
     self.assertTemplateUsed(res, "admin/overview/usage.csv")
     self.assertTrue(isinstance(res.context["usage"], usage.GlobalUsage))
     self.assertContains(
         res,
         "Tenant,VCPUs,RamMB,DiskGB,Usage(Hours)\n"
         "%s,%s,%s,%s,%f"
         % (
             usage_obj.tenant_id,
             usage_obj.vcpus,
             usage_obj.memory_mb,
             usage_obj.disk_gb_hours,
             usage_obj.vcpu_hours,
         ),
     )
コード例 #2
0
ファイル: tests.py プロジェクト: nitishb/horizon
 def test_usage(self):
     now = timezone.now()
     usage_obj = api.nova.Usage(self.usages.first())
     quotas = self.quota_usages.first()
     api.keystone.tenant_list(IsA(http.HttpRequest), admin=True).AndReturn(self.tenants.list())
     api.usage_list(
         IsA(http.HttpRequest), datetime.datetime(now.year, now.month, 1, 0, 0, 0), Func(usage.almost_now)
     ).AndReturn([usage_obj])
     api.nova.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(quotas)
     self.mox.ReplayAll()
     res = self.client.get(reverse("horizon:admin:overview:index"))
     self.assertTemplateUsed(res, "admin/overview/usage.html")
     self.assertTrue(isinstance(res.context["usage"], usage.GlobalUsage))
     self.assertContains(
         res,
         '<td class="sortable normal_column">test_tenant'
         "</td>"
         '<td class="sortable normal_column">%s</td>'
         '<td class="sortable normal_column">%s</td>'
         '<td class="sortable normal_column">%s</td>'
         '<td class="sortable normal_column">%.2f</td>'
         '<td class="sortable normal_column">%.2f</td>'
         % (
             usage_obj.vcpus,
             usage_obj.disk_gb_hours,
             mbformat(usage_obj.memory_mb),
             usage_obj.vcpu_hours,
             usage_obj.total_local_gb_usage,
         ),
     )
コード例 #3
0
 def test_usage(self):
     now = timezone.now()
     usage_obj = api.nova.NovaUsage(self.usages.first())
     quota_data = self.quota_usages.first()
     api.keystone.tenant_list(IsA(http.HttpRequest), admin=True) \
                 .AndReturn(self.tenants.list())
     api.usage_list(IsA(http.HttpRequest),
                   datetime.datetime(now.year, now.month, 1, 0, 0, 0),
                   Func(usage.almost_now)) \
                   .AndReturn([usage_obj])
     quotas.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(quota_data)
     self.mox.ReplayAll()
     res = self.client.get(reverse('horizon:admin:overview:index'))
     self.assertTemplateUsed(res, 'admin/overview/usage.html')
     self.assertTrue(isinstance(res.context['usage'], usage.GlobalUsage))
     self.assertContains(res,
                         '<td class="sortable normal_column">test_tenant'
                         '</td>'
                         '<td class="sortable normal_column">%s</td>'
                         '<td class="sortable normal_column">%s</td>'
                         '<td class="sortable normal_column">%s</td>'
                         '<td class="sortable normal_column">%.2f</td>'
                         '<td class="sortable normal_column">%.2f</td>' %
                         (usage_obj.vcpus,
                          usage_obj.disk_gb_hours,
                          mbformat(usage_obj.memory_mb),
                          usage_obj.vcpu_hours,
                          usage_obj.total_local_gb_usage))
コード例 #4
0
    def test_usage_list(self):
        usages = self.usages.list()

        novaclient = self.stub_novaclient()
        novaclient.usage = self.mox.CreateMockAnything()
        novaclient.usage.list('start', 'end', True).AndReturn(usages)
        self.mox.ReplayAll()

        ret_val = api.usage_list(self.request, 'start', 'end')
        for usage in ret_val:
            self.assertIsInstance(usage, api.Usage)
コード例 #5
0
ファイル: nova_tests.py プロジェクト: jiangy/horizon
    def test_usage_list(self):
        usages = self.usages.list()

        novaclient = self.stub_novaclient()
        novaclient.usage = self.mox.CreateMockAnything()
        novaclient.usage.list('start', 'end', True).AndReturn(usages)
        self.mox.ReplayAll()

        ret_val = api.usage_list(self.request, 'start', 'end')
        for usage in ret_val:
            self.assertIsInstance(usage, api.Usage)
コード例 #6
0
 def test_usage_csv(self):
     now = timezone.now()
     usage_obj = api.nova.NovaUsage(self.usages.first())
     quota_data = self.quota_usages.first()
     api.keystone.tenant_list(IsA(http.HttpRequest), admin=True) \
                 .AndReturn(self.tenants.list())
     api.usage_list(IsA(http.HttpRequest),
                   datetime.datetime(now.year, now.month, 1, 0, 0, 0),
                   Func(usage.almost_now)) \
                   .AndReturn([usage_obj, usage_obj])
     quotas.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(quota_data)
     self.mox.ReplayAll()
     csv_url = reverse('horizon:admin:overview:index') + "?format=csv"
     res = self.client.get(csv_url)
     self.assertTemplateUsed(res, 'admin/overview/usage.csv')
     self.assertTrue(isinstance(res.context['usage'], usage.GlobalUsage))
     hdr = 'Tenant,VCPUs,RamMB,DiskGB,Usage(Hours)'
     row = '%s,%s,%s,%s,%.2f' % (usage_obj.tenant_id,
                               usage_obj.vcpus,
                               usage_obj.memory_mb,
                               usage_obj.disk_gb_hours,
                               usage_obj.vcpu_hours)
     self.assertContains(res, '%s\n%s\n%s\n' % (hdr, row, row))
コード例 #7
0
ファイル: base.py プロジェクト: radez/horizon
 def get_usage_list(self, start, end):
     return api.usage_list(self.request, start, end)
コード例 #8
0
ファイル: base.py プロジェクト: BenJaziaSadok/horizon
 def get_usage_list(self, start, end):
     return api.usage_list(self.request, start, end)