From 1d21cd4f8a3bae925858f0b9b3651df6c2101d92 Mon Sep 17 00:00:00 2001 From: Julio-Oliveira-Encora Date: Thu, 30 May 2024 14:42:43 -0300 Subject: [PATCH] Addressed PR comment. --- netbox/utilities/templatetags/helpers.py | 8 ++++---- netbox/utilities/tests/test_humanize_megabytes_helper.py | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/netbox/utilities/templatetags/helpers.py b/netbox/utilities/templatetags/helpers.py index 18e2b2070..4f08dc107 100644 --- a/netbox/utilities/templatetags/helpers.py +++ b/netbox/utilities/templatetags/helpers.py @@ -98,15 +98,15 @@ def humanize_megabytes(mb): # Factors in bytes factors = { - "mega": 1024 ** 2, - "giga": 1024 ** 3, - "tera": 1024 ** 4, + "mega": 1000 ** 2, + "giga": 1000 ** 3, + "tera": 1000 ** 4, } if not mb: return "" - bytes = int(mb * 1024**2) + bytes = int(mb * 1000**2) if bytes >= factors["tera"]: return f"{bytes / factors['tera']:.2f} TB" diff --git a/netbox/utilities/tests/test_humanize_megabytes_helper.py b/netbox/utilities/tests/test_humanize_megabytes_helper.py index be6e2a29d..642e92b9f 100644 --- a/netbox/utilities/tests/test_humanize_megabytes_helper.py +++ b/netbox/utilities/tests/test_humanize_megabytes_helper.py @@ -10,11 +10,11 @@ class TestConvertByteSize(TestCase): def test_humanize_megabytes_converts_to_gigabytes(self): """Test that humanize_megabytes converts megabytes to gigabytes.""" - self.assertEqual(humanize_megabytes(1024), "1.00 GB") + self.assertEqual(humanize_megabytes(1000), "1.00 GB") def test_humanize_megabytes_converts_to_terabytes(self): """Test that humanize_megabytes converts megabytes to terabytes.""" - self.assertEqual(humanize_megabytes(1048576), "1.00 TB") + self.assertEqual(humanize_megabytes(1000000), "1.00 TB") def test_humanize_megabytes_returns_empty_for_none(self): """Test that humanize_megabytes returns empty for None.""" @@ -22,4 +22,4 @@ class TestConvertByteSize(TestCase): def test_humanize_megabytes_without_unit(self): """Test that humanize_megabytes returns the value without unit.""" - self.assertEqual(humanize_megabytes(123456789), "117.74 TB") + self.assertEqual(humanize_megabytes(123456789), "123.46 TB")