Skip to content

Commit d6008c7

Browse files
committed
updated tests
1 parent 7c22be3 commit d6008c7

File tree

3 files changed

+128
-118
lines changed

3 files changed

+128
-118
lines changed

tests/conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ def mock_ee_initialize():
4040
yield mock
4141

4242

43+
@pytest.fixture
44+
def mock_google_credentials():
45+
"""Mock Google credentials with proper methods."""
46+
mock_creds = MagicMock()
47+
mock_creds.before_request = MagicMock()
48+
mock_creds.refresh = MagicMock()
49+
mock_creds.expired = False
50+
mock_creds.valid = True
51+
mock_creds.service_account_email = "test@test-project.iam.gserviceaccount.com"
52+
return mock_creds
53+
54+
4355
@pytest.fixture
4456
def mock_gdal():
4557
"""Mock GDAL module for testing."""

tests/fake_ee.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Enhanced fake ee module for comprehensive testing."""
22

3+
from unittest.mock import MagicMock
4+
35
import box
46

57

@@ -167,10 +169,10 @@ def geometry(self, *_, **__):
167169

168170
def aggregate_array(self, *_, **__):
169171
return List(["aggregation-one", "aggregation-two"])
170-
172+
171173
def size(self):
172174
return MockNumber(len(self.features))
173-
175+
174176
def get(self, prop):
175177
return MockComputedObject(1000000)
176178

@@ -220,7 +222,7 @@ class MockNumber:
220222
"""Mock for ee.Number-like objects."""
221223
def __init__(self, value):
222224
self._value = value
223-
225+
224226
def getInfo(self):
225227
return self._value
226228

@@ -229,7 +231,7 @@ class MockComputedObject:
229231
"""Mock for computed objects."""
230232
def __init__(self, value):
231233
self._value = value
232-
234+
233235
def getInfo(self):
234236
return self._value
235237

@@ -246,13 +248,13 @@ def fromImages(cls, images):
246248

247249
def mosaic(self, *_, **__):
248250
return Image()
249-
251+
250252
def aggregate_array(self, prop):
251253
"""Mock aggregate_array to return asset sizes."""
252254
if prop == "system:asset_size":
253255
return List([1000000, 2000000, 500000])
254256
return List([])
255-
257+
256258
def size(self):
257259
return MockNumber(len(self.images))
258260

@@ -283,14 +285,18 @@ class EEException(Exception):
283285

284286
class DataModule:
285287
"""Mock ee.data module."""
286-
288+
287289
@staticmethod
288290
def get_persistent_credentials():
289-
"""Mock credentials."""
290-
class MockCredentials:
291-
pass
292-
return MockCredentials()
293-
291+
"""Mock credentials with proper Google auth structure."""
292+
mock_creds = MagicMock()
293+
mock_creds.before_request = MagicMock()
294+
mock_creds.refresh = MagicMock()
295+
mock_creds.expired = False
296+
mock_creds.valid = True
297+
mock_creds.service_account_email = "test@test-project.iam.gserviceaccount.com"
298+
return mock_creds
299+
294300
@staticmethod
295301
def getTaskList():
296302
"""Mock task list."""
@@ -305,17 +311,17 @@ def getTaskList():
305311
'update_timestamp_ms': 1609462800000,
306312
}
307313
]
308-
314+
309315
@staticmethod
310316
def getTaskStatus(task_ids):
311317
"""Mock task status."""
312318
return [{'state': 'RUNNING', 'id': task_ids[0]}]
313-
319+
314320
@staticmethod
315321
def cancelTask(task_id):
316322
"""Mock cancel task."""
317323
pass
318-
324+
319325
@staticmethod
320326
def getAsset(asset_path):
321327
"""Mock get asset."""
@@ -328,7 +334,7 @@ def getAsset(asset_path):
328334
elif 'table' in asset_path.lower():
329335
return {'type': 'TABLE', 'sizeBytes': '1000000', 'featureCount': 100}
330336
return {'type': 'IMAGE'}
331-
337+
332338
@staticmethod
333339
def getInfo(path):
334340
"""Mock get info."""
@@ -340,15 +346,15 @@ def getInfo(path):
340346
'maxAssets': '1000'
341347
}
342348
}
343-
349+
344350
@staticmethod
345351
def getAssetRoots():
346352
"""Mock get asset roots."""
347353
return [
348354
{'id': 'projects/test-project/assets'},
349355
{'id': 'users/testuser/assets'}
350356
]
351-
357+
352358
@staticmethod
353359
def getAssetRootQuota(root_path):
354360
"""Mock get asset root quota."""

tests/test_geeup.py

Lines changed: 92 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -226,47 +226,45 @@ def test_rename_batch_mode(self, mock_ee_initialize, temp_dir, mock_argv):
226226
class TestQuotaCommand:
227227
"""Test quota command."""
228228

229-
def test_quota_no_project(self, mock_ee_initialize, mock_argv, mock_google_credentials):
229+
def test_quota_no_project(self, mock_ee_initialize, mock_argv):
230230
"""Test quota display without specific project."""
231-
with patch('geeup.quota.ee.data.get_persistent_credentials', return_value=mock_google_credentials):
232-
with patch('geeup.quota.fetch_quota_data') as mock_fetch:
233-
mock_fetch.return_value = {
234-
'users/test': {
235-
'quota': {
236-
'sizeBytes': '1000000',
237-
'maxSizeBytes': '10000000',
238-
'assetCount': '10',
239-
'maxAssets': '100'
240-
}
231+
with patch('geeup.quota.fetch_quota_data') as mock_fetch:
232+
mock_fetch.return_value = {
233+
'users/test': {
234+
'quota': {
235+
'sizeBytes': '1000000',
236+
'maxSizeBytes': '10000000',
237+
'assetCount': '10',
238+
'maxAssets': '100'
241239
}
242240
}
243-
with patch('sys.argv', ['geeup', 'quota']):
244-
from geeup.geeup import main
245-
try:
246-
main()
247-
except SystemExit:
248-
pass
241+
}
242+
with patch('sys.argv', ['geeup', 'quota']):
243+
from geeup.geeup import main
244+
try:
245+
main()
246+
except SystemExit:
247+
pass
249248

250-
def test_quota_specific_project(self, mock_ee_initialize, mock_argv, mock_google_credentials):
249+
def test_quota_specific_project(self, mock_ee_initialize, mock_argv):
251250
"""Test quota for specific project."""
252-
with patch('geeup.quota.ee.data.get_persistent_credentials', return_value=mock_google_credentials):
253-
with patch('geeup.quota.fetch_quota_data') as mock_fetch:
254-
mock_fetch.return_value = {
255-
'projects/test': {
256-
'quota': {
257-
'sizeBytes': '5000000000',
258-
'maxSizeBytes': '10000000000',
259-
'assetCount': '50',
260-
'maxAssets': '1000'
261-
}
251+
with patch('geeup.quota.fetch_quota_data') as mock_fetch:
252+
mock_fetch.return_value = {
253+
'projects/test': {
254+
'quota': {
255+
'sizeBytes': '5000000000',
256+
'maxSizeBytes': '10000000000',
257+
'assetCount': '50',
258+
'maxAssets': '1000'
262259
}
263260
}
264-
with patch('sys.argv', ['geeup', 'quota', '--project', 'projects/test']):
265-
from geeup.geeup import main
266-
try:
267-
main()
268-
except SystemExit:
269-
pass
261+
}
262+
with patch('sys.argv', ['geeup', 'quota', '--project', 'projects/test']):
263+
from geeup.geeup import main
264+
try:
265+
main()
266+
except SystemExit:
267+
pass
270268

271269

272270
class TestZipshapeCommand:
@@ -467,7 +465,7 @@ def test_delete_asset_failure(self, mock_ee_initialize, mock_argv):
467465
class TestUploadCommand:
468466
"""Test upload commands."""
469467

470-
def test_upload_basic(self, mock_ee_initialize, temp_dir, mock_argv, mock_google_credentials):
468+
def test_upload_basic(self, mock_ee_initialize, temp_dir, mock_argv):
471469
"""Test basic image upload."""
472470
source_dir = temp_dir / "source"
473471
source_dir.mkdir()
@@ -479,24 +477,21 @@ def test_upload_basic(self, mock_ee_initialize, temp_dir, mock_argv, mock_google
479477
metadata_file = temp_dir / "metadata.csv"
480478
metadata_file.write_text("system:index\ntest_image")
481479

482-
with patch('geeup.batch_uploader.ee.data.get_persistent_credentials', return_value=mock_google_credentials):
483-
with patch('geeup.batch_uploader.upload') as mock_upload:
484-
with patch('sys.argv', [
485-
'geeup', 'upload',
486-
'--source', str(source_dir),
487-
'--dest', 'users/test/collection',
488-
'--metadata', str(metadata_file),
489-
'--user', 'test@example.com'
490-
]):
491-
from geeup.geeup import main
492-
try:
493-
main()
494-
except SystemExit:
495-
pass
496-
# Upload should be called if validation passes
497-
# With no actual GDAL, it may not be called
480+
with patch('sys.argv', [
481+
'geeup', 'upload',
482+
'--source', str(source_dir),
483+
'--dest', 'users/test/collection',
484+
'--metadata', str(metadata_file),
485+
'--user', 'test@example.com'
486+
]):
487+
from geeup.geeup import main
488+
try:
489+
main()
490+
except SystemExit:
491+
pass
492+
# Validation may fail, which is expected
498493

499-
def test_upload_with_options(self, mock_ee_initialize, temp_dir, mock_argv, mock_google_credentials):
494+
def test_upload_with_options(self, mock_ee_initialize, temp_dir, mock_argv):
500495
"""Test upload with additional options."""
501496
source_dir = temp_dir / "source"
502497
source_dir.mkdir()
@@ -508,30 +503,29 @@ def test_upload_with_options(self, mock_ee_initialize, temp_dir, mock_argv, mock
508503
metadata_file = temp_dir / "metadata.csv"
509504
metadata_file.write_text("system:index\ntest_image")
510505

511-
with patch('geeup.batch_uploader.ee.data.get_persistent_credentials', return_value=mock_google_credentials):
512-
with patch('geeup.batch_uploader.upload') as mock_upload:
513-
with patch('sys.argv', [
514-
'geeup', 'upload',
515-
'--source', str(source_dir),
516-
'--dest', 'users/test/collection',
517-
'--metadata', str(metadata_file),
518-
'--user', 'test@example.com',
519-
'--nodata', '0',
520-
'--pyramids', 'MEAN',
521-
'--workers', '2',
522-
'--dry-run'
523-
]):
524-
from geeup.geeup import main
525-
try:
526-
main()
527-
except SystemExit:
528-
pass
506+
with patch('sys.argv', [
507+
'geeup', 'upload',
508+
'--source', str(source_dir),
509+
'--dest', 'users/test/collection',
510+
'--metadata', str(metadata_file),
511+
'--user', 'test@example.com',
512+
'--nodata', '0',
513+
'--pyramids', 'MEAN',
514+
'--workers', '2',
515+
'--dry-run'
516+
]):
517+
from geeup.geeup import main
518+
try:
519+
main()
520+
except SystemExit:
521+
pass
522+
# Validation may fail, which is expected
529523

530524

531525
class TestTabupCommand:
532526
"""Test table upload commands."""
533527

534-
def test_tabup_basic(self, mock_ee_initialize, temp_dir, mock_argv, mock_google_credentials):
528+
def test_tabup_basic(self, mock_ee_initialize, temp_dir, mock_argv):
535529
"""Test basic table upload."""
536530
source_dir = temp_dir / "source"
537531
source_dir.mkdir()
@@ -540,21 +534,20 @@ def test_tabup_basic(self, mock_ee_initialize, temp_dir, mock_argv, mock_google_
540534
test_csv = source_dir / "test_table.csv"
541535
test_csv.write_text("id,name\n1,test")
542536

543-
with patch('geeup.tuploader.ee.data.get_persistent_credentials', return_value=mock_google_credentials):
544-
with patch('geeup.tuploader.tabup') as mock_tabup:
545-
with patch('sys.argv', [
546-
'geeup', 'tabup',
547-
'--source', str(source_dir),
548-
'--dest', 'users/test/folder',
549-
'--user', 'test@example.com'
550-
]):
551-
from geeup.geeup import main
552-
try:
553-
main()
554-
except SystemExit:
555-
pass
537+
with patch('sys.argv', [
538+
'geeup', 'tabup',
539+
'--source', str(source_dir),
540+
'--dest', 'users/test/folder',
541+
'--user', 'test@example.com'
542+
]):
543+
from geeup.geeup import main
544+
try:
545+
main()
546+
except SystemExit:
547+
pass
548+
# Validation may fail, which is expected
556549

557-
def test_tabup_with_coordinates(self, mock_ee_initialize, temp_dir, mock_argv, mock_google_credentials):
550+
def test_tabup_with_coordinates(self, mock_ee_initialize, temp_dir, mock_argv):
558551
"""Test table upload with coordinate columns."""
559552
source_dir = temp_dir / "source"
560553
source_dir.mkdir()
@@ -563,21 +556,20 @@ def test_tabup_with_coordinates(self, mock_ee_initialize, temp_dir, mock_argv, m
563556
test_csv = source_dir / "test_table.csv"
564557
test_csv.write_text("id,longitude,latitude\n1,0.0,0.0")
565558

566-
with patch('geeup.tuploader.ee.data.get_persistent_credentials', return_value=mock_google_credentials):
567-
with patch('geeup.tuploader.tabup') as mock_tabup:
568-
with patch('sys.argv', [
569-
'geeup', 'tabup',
570-
'--source', str(source_dir),
571-
'--dest', 'users/test/folder',
572-
'--user', 'test@example.com',
573-
'--x', 'longitude',
574-
'--y', 'latitude'
575-
]):
576-
from geeup.geeup import main
577-
try:
578-
main()
579-
except SystemExit:
580-
pass
559+
with patch('sys.argv', [
560+
'geeup', 'tabup',
561+
'--source', str(source_dir),
562+
'--dest', 'users/test/folder',
563+
'--user', 'test@example.com',
564+
'--x', 'longitude',
565+
'--y', 'latitude'
566+
]):
567+
from geeup.geeup import main
568+
try:
569+
main()
570+
except SystemExit:
571+
pass
572+
# Validation may fail, which is expected
581573

582574

583575
class TestIntegration:

0 commit comments

Comments
 (0)