mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-10 01:28:16 -06:00
Addressed PR comment.
This commit is contained in:
parent
3c8b184fdf
commit
1d21cd4f8a
@ -98,15 +98,15 @@ def humanize_megabytes(mb):
|
|||||||
|
|
||||||
# Factors in bytes
|
# Factors in bytes
|
||||||
factors = {
|
factors = {
|
||||||
"mega": 1024 ** 2,
|
"mega": 1000 ** 2,
|
||||||
"giga": 1024 ** 3,
|
"giga": 1000 ** 3,
|
||||||
"tera": 1024 ** 4,
|
"tera": 1000 ** 4,
|
||||||
}
|
}
|
||||||
|
|
||||||
if not mb:
|
if not mb:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
bytes = int(mb * 1024**2)
|
bytes = int(mb * 1000**2)
|
||||||
|
|
||||||
if bytes >= factors["tera"]:
|
if bytes >= factors["tera"]:
|
||||||
return f"{bytes / factors['tera']:.2f} TB"
|
return f"{bytes / factors['tera']:.2f} TB"
|
||||||
|
@ -10,11 +10,11 @@ class TestConvertByteSize(TestCase):
|
|||||||
|
|
||||||
def test_humanize_megabytes_converts_to_gigabytes(self):
|
def test_humanize_megabytes_converts_to_gigabytes(self):
|
||||||
"""Test that humanize_megabytes converts megabytes to gigabytes."""
|
"""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):
|
def test_humanize_megabytes_converts_to_terabytes(self):
|
||||||
"""Test that humanize_megabytes converts megabytes to terabytes."""
|
"""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):
|
def test_humanize_megabytes_returns_empty_for_none(self):
|
||||||
"""Test that humanize_megabytes returns empty for None."""
|
"""Test that humanize_megabytes returns empty for None."""
|
||||||
@ -22,4 +22,4 @@ class TestConvertByteSize(TestCase):
|
|||||||
|
|
||||||
def test_humanize_megabytes_without_unit(self):
|
def test_humanize_megabytes_without_unit(self):
|
||||||
"""Test that humanize_megabytes returns the value without unit."""
|
"""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")
|
||||||
|
Loading…
Reference in New Issue
Block a user