1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-01 16:36:06 +00:00

fix(ui): host and VM charts give their points the panel's time

A host's charts and their "Updated at" line took their times from
timezone.now(), which is UTC, while a VM's charts took time.strftime(),
the panel's time zone. With TIME_ZONE=Europe/Istanbul the same moment
read 09:00 on the host page and 12:00 on the VM page. Both now give the
panel's time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
catborise 2026-11-10 11:53:40 +03:00
parent a8f7c8aeaa
commit 0d20d07b29
4 changed files with 19 additions and 6 deletions

View file

@ -2,6 +2,7 @@
previous answer and now, without waiting, when that sample is recent and
unaltered; otherwise over one second as before."""
from datetime import datetime, timezone as dt_timezone
import json
import shutil
import subprocess
@ -11,7 +12,7 @@ from unittest.mock import PropertyMock, patch
from django.conf import settings
from django.contrib.auth import get_user_model
from django.core import signing
from django.test import TestCase
from django.test import TestCase, override_settings
from django.urls import reverse
from libvirt import libvirtError
from lxml import html
@ -53,6 +54,13 @@ class GraphTestCase(TestCase):
self.graph(cpu_sample=data["cpu_sample"])
self.assertEqual(self.previous(), (10, 20, 100.0))
@override_settings(TIME_ZONE="Europe/Istanbul")
def test_the_time_of_a_point_is_the_panels(self):
with patch("django.utils.timezone.now", return_value=datetime(2026, 11, 10, 9, 0, tzinfo=dt_timezone.utc)):
self.assertEqual(self.graph()["timeline"], "12:00:00")
self.conn.get_cpu_usage.side_effect = libvirtError("unreachable") # its error answer too
self.assertEqual(self.graph()["timeline"], "12:00:00")
def test_an_altered_old_or_foreign_sample_is_not_used(self):
token = self.graph()["cpu_sample"]
foreign = self.graph(self.other)["cpu_sample"]