- Added DM Sans font to the project, including multiple weights and styles for improved typography. - Updated package.json and package-lock.json to include @fontsource/dm-sans dependency. - Enhanced dashboard context to include current cluster CPU state, integrating new data into the context and API responses. - Updated relevant templates and JavaScript to utilize the new current cluster data for better visualization and user experience.
108 lines
4.0 KiB
Python
108 lines
4.0 KiB
Python
"""Tests for dashboard.mock_data."""
|
|
import json
|
|
|
|
from django.test import TestCase
|
|
|
|
from dashboard.mock_data import get_mock_context
|
|
|
|
|
|
class GetMockContextTest(TestCase):
|
|
"""Tests for get_mock_context()."""
|
|
|
|
def test_returns_all_top_level_keys(self):
|
|
ctx = get_mock_context()
|
|
expected_keys = {"region", "pcpu", "vcpu", "pram", "vram", "vm", "flavors", "audits", "current_cluster"}
|
|
self.assertEqual(set(ctx.keys()), expected_keys)
|
|
|
|
def test_region_structure(self):
|
|
ctx = get_mock_context()
|
|
region = ctx["region"]
|
|
self.assertIn("name", region)
|
|
self.assertIn("hosts_total", region)
|
|
self.assertEqual(region["name"], "mock-region")
|
|
self.assertEqual(region["hosts_total"], 6)
|
|
|
|
def test_pcpu_structure_and_types(self):
|
|
ctx = get_mock_context()
|
|
pcpu = ctx["pcpu"]
|
|
self.assertEqual(pcpu["total"], 48)
|
|
self.assertEqual(pcpu["usage"], 12.5)
|
|
self.assertEqual(pcpu["free"], 48 - 12.5)
|
|
self.assertIsInstance(pcpu["used_percentage"], (int, float))
|
|
|
|
def test_vcpu_structure(self):
|
|
ctx = get_mock_context()
|
|
vcpu = ctx["vcpu"]
|
|
self.assertIn("total", vcpu)
|
|
self.assertIn("allocated", vcpu)
|
|
self.assertIn("free", vcpu)
|
|
self.assertIn("allocated_percentage", vcpu)
|
|
self.assertIn("overcommit_ratio", vcpu)
|
|
self.assertIn("overcommit_max", vcpu)
|
|
self.assertEqual(vcpu["overcommit_max"], 2.0)
|
|
|
|
def test_pram_vram_structure(self):
|
|
ctx = get_mock_context()
|
|
pram = ctx["pram"]
|
|
vram = ctx["vram"]
|
|
self.assertIn("total", pram)
|
|
self.assertIn("usage", pram)
|
|
self.assertIn("free", pram)
|
|
self.assertIn("used_percentage", pram)
|
|
self.assertIn("total", vram)
|
|
self.assertIn("allocated", vram)
|
|
self.assertIn("overcommit_max", vram)
|
|
|
|
def test_vm_structure(self):
|
|
ctx = get_mock_context()
|
|
vm = ctx["vm"]
|
|
self.assertEqual(vm["count"], 24)
|
|
self.assertEqual(vm["active"], 22)
|
|
self.assertEqual(vm["stopped"], 2)
|
|
self.assertIn("avg_cpu", vm)
|
|
self.assertIn("avg_ram", vm)
|
|
self.assertIn("density", vm)
|
|
|
|
def test_flavors_structure(self):
|
|
ctx = get_mock_context()
|
|
flavors = ctx["flavors"]
|
|
for key in ("first_common_flavor", "second_common_flavor", "third_common_flavor"):
|
|
self.assertIn(key, flavors)
|
|
self.assertIn("name", flavors[key])
|
|
self.assertIn("count", flavors[key])
|
|
self.assertEqual(flavors["first_common_flavor"]["name"], "m1.small")
|
|
self.assertEqual(flavors["first_common_flavor"]["count"], 12)
|
|
|
|
def test_audits_serialized_fields(self):
|
|
ctx = get_mock_context()
|
|
self.assertIsInstance(ctx["audits"], list)
|
|
self.assertGreaterEqual(len(ctx["audits"]), 1)
|
|
for audit in ctx["audits"]:
|
|
self.assertIn("migrations", audit)
|
|
self.assertIn("host_labels", audit)
|
|
self.assertIn("cpu_current", audit)
|
|
self.assertIn("cpu_projected", audit)
|
|
# These must be JSON strings (render-ready for JS)
|
|
self.assertIsInstance(audit["migrations"], str)
|
|
self.assertIsInstance(audit["host_labels"], str)
|
|
self.assertIsInstance(audit["cpu_current"], str)
|
|
self.assertIsInstance(audit["cpu_projected"], str)
|
|
# Must be valid JSON
|
|
json.loads(audit["migrations"])
|
|
json.loads(audit["host_labels"])
|
|
json.loads(audit["cpu_current"])
|
|
json.loads(audit["cpu_projected"])
|
|
|
|
def test_audits_metadata_fields(self):
|
|
ctx = get_mock_context()
|
|
audit = ctx["audits"][0]
|
|
self.assertIn("id", audit)
|
|
self.assertIn("name", audit)
|
|
self.assertIn("created_at", audit)
|
|
self.assertIn("strategy", audit)
|
|
self.assertIn("goal", audit)
|
|
self.assertIn("type", audit)
|
|
self.assertIn("scope", audit)
|
|
self.assertIn("cpu_weight", audit)
|
|
self.assertIn("ram_weight", audit)
|