Show size of database file next to download link, closes #172

This commit is contained in:
Simon Willison 2019-02-05 20:53:44 -08:00
commit 4462a5ab28
7 changed files with 37 additions and 1 deletions

View file

@ -374,3 +374,18 @@ def test_path_with_format(path, format, extra_qs, expected):
)
actual = utils.path_with_format(request, format, extra_qs)
assert expected == actual
@pytest.mark.parametrize(
"bytes,expected",
[
(120, '120 bytes'),
(1024, '1.0 KB'),
(1024 * 1024, '1.0 MB'),
(1024 * 1024 * 1024, '1.0 GB'),
(1024 * 1024 * 1024 * 1.3, '1.3 GB'),
(1024 * 1024 * 1024 * 1024, '1.0 TB'),
]
)
def test_format_bytes(bytes, expected):
assert expected == utils.format_bytes(bytes)