-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix issue non dictionary in request_params * change terminology of bbox * add zarr cache size checker * increase read and send timeouts of uwsgi and nginx
- Loading branch information
1 parent
3a64ede
commit daa48a9
Showing
11 changed files
with
283 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# coding=utf-8 | ||
""" | ||
Tomorrow Now GAP. | ||
.. note:: Unit test for file utils. | ||
""" | ||
import os | ||
import tempfile | ||
|
||
from django.test import TestCase | ||
|
||
from core.utils.file import get_directory_size, format_size | ||
|
||
|
||
class TestFileUtilities(TestCase): | ||
"""Test File utilities.""" | ||
|
||
def setUp(self): | ||
"""Set test class.""" | ||
# Create a temporary directory | ||
self.test_dir = tempfile.TemporaryDirectory() | ||
self.test_dir_path = self.test_dir.name | ||
|
||
# Create files and subdirectories for testing | ||
self.file1 = os.path.join(self.test_dir_path, "file1.txt") | ||
self.file2 = os.path.join(self.test_dir_path, "file2.txt") | ||
self.sub_dir = os.path.join(self.test_dir_path, "subdir") | ||
os.mkdir(self.sub_dir) | ||
|
||
self.sub_file = os.path.join(self.sub_dir, "subfile.txt") | ||
|
||
# Write data to files | ||
with open(self.file1, "wb") as f: | ||
f.write(b"a" * 1024) # 1 KB | ||
with open(self.file2, "wb") as f: | ||
f.write(b"b" * 2048) # 2 KB | ||
with open(self.sub_file, "wb") as f: | ||
f.write(b"c" * 4096) # 4 KB | ||
|
||
def tearDown(self): | ||
"""Clean up temporary directory.""" | ||
self.test_dir.cleanup() | ||
|
||
def test_get_directory_size(self): | ||
"""Test get directory size.""" | ||
# Expected total size: 1 KB + 2 KB + 4 KB = 7 KB | ||
expected_size = 1024 + 2048 + 4096 | ||
calculated_size = get_directory_size(self.test_dir_path) | ||
self.assertEqual(calculated_size, expected_size) | ||
|
||
def test_format_size(self): | ||
"""Test format_size function.""" | ||
test_cases = [ | ||
(512, "512.00 B"), | ||
(1024, "1.00 KB"), | ||
(1536, "1.50 KB"), | ||
(1048576, "1.00 MB"), | ||
(1073741824, "1.00 GB"), | ||
(1099511627776, "1.00 TB"), | ||
(1125899906842624, "1.00 PB"), | ||
] | ||
|
||
for size, expected in test_cases: | ||
with self.subTest(size=size): | ||
self.assertEqual(format_size(size), expected) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# coding=utf-8 | ||
""" | ||
Tomorrow Now GAP. | ||
.. note:: Utilities for file. | ||
""" | ||
import os | ||
|
||
|
||
def get_directory_size(path): | ||
"""Get size of directory. | ||
:param path: directory path | ||
:type path: string | ||
:return: size in bytes | ||
:rtype: int | ||
""" | ||
total_size = 0 | ||
for dirpath, dirnames, filenames in os.walk(path): | ||
for file in filenames: | ||
file_path = os.path.join(dirpath, file) | ||
# Add file size, skipping broken symbolic links | ||
if os.path.exists(file_path): | ||
total_size += os.path.getsize(file_path) | ||
return total_size | ||
|
||
|
||
def format_size(size_in_bytes): | ||
"""Format size to human readable. | ||
:param size_in_bytes: size | ||
:type size_in_bytes: int | ||
:return: human readable size | ||
:rtype: str | ||
""" | ||
for unit in ['B', 'KB', 'MB', 'GB', 'TB']: | ||
if size_in_bytes < 1024: | ||
return f"{size_in_bytes:.2f} {unit}" | ||
size_in_bytes /= 1024 | ||
return f"{size_in_bytes:.2f} PB" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
django_project/gap/migrations/0040_datasourcefilecache_size.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 4.2.7 on 2024-11-19 20:17 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('gap', '0039_preferences_dask_threads_num_api'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='datasourcefilecache', | ||
name='size', | ||
field=models.PositiveIntegerField(default=0), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.