Skip to content

Commit acf56bd

Browse files
committed
Further work toward a solution
[skip ci]
1 parent bfc1e2c commit acf56bd

3 files changed

Lines changed: 21 additions & 13 deletions

File tree

scripts/gdrive.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,11 +521,11 @@ def select_ids_to_keep(files: list[dict[str, any]], folder_slugs: dict[str, str]
521521
# Don't trash any publicly-launched files
522522
#####
523523
file_permissions = batch_get_files_by_id([f['id'] for f in files], "id,name,permissions")
524-
are_publics = [any(p['type'] == 'anyone' for p in f['permissions']) for f in file_permissions]
525-
num_public = sum(are_publics)
524+
are_publics = {f['id']: any(p['type'] == 'anyone' for p in f.get('permissions', [])) for f in file_permissions}
525+
num_public = sum(are_publics.values())
526526
if num_public > 0:
527527
# Never suggest a public-facing file for deletion
528-
return [files[i]['id'] for i in range(len(files)) if are_publics[i]], IDSelectionReason.IS_PUBLIC
528+
return [f['id'] for f in files if are_publics.get(f['id'])], IDSelectionReason.IS_PUBLIC
529529

530530
#####
531531
# Discard files in "unimportant" subfolders first

scripts/test_fixtures/drive.sqlite

0 Bytes
Binary file not shown.

scripts/test_gdrive.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,25 +136,33 @@ def test_select_ids_to_keep_realistic(mock_website_config, mock_permissions):
136136
pytest.skip("Fixture DB not found")
137137

138138
test_cache = DriveCache(fixture_db)
139-
140-
# IDs from the user's tricky case
141-
# 17VpttQypHvoBExKbm9AX48iGFnmORgkX is in "Unread"
142-
# 1i4O9RG7ug2WWNpMN44qj-P1m2tfzoUBP is in "Early Indian Schools of Buddhism"
143-
139+
144140
with mock.patch('gdrive.gcache', test_cache):
141+
# 17VpttQypHvoBExKbm9AX48iGFnmORgkX is in "Unread"
142+
# 1i4O9RG7ug2WWNpMN44qj-P1m2tfzoUBP is in "Early Indian Schools of Buddhism"
145143
file1 = test_cache.get_item('17VpttQypHvoBExKbm9AX48iGFnmORgkX')
146144
file2 = test_cache.get_item('1i4O9RG7ug2WWNpMN44qj-P1m2tfzoUBP')
147-
148145
assert file1 is not None
149146
assert file2 is not None
150-
151147
files = [file1, file2]
152-
folder_slugs = {}
148+
folder_slugs = gdrive.load_folder_slugs() # in a realistic test, load the actual folder slugs
153149

154150
ids, reason = gdrive.select_ids_to_keep(files, folder_slugs)
155-
156151
assert ids == ['1i4O9RG7ug2WWNpMN44qj-P1m2tfzoUBP']
157-
assert reason == gdrive.IDSelectionReason.GENERIC_SUBFOLDER
152+
assert reason == gdrive.IDSelectionReason.TAG_FOLDER
153+
154+
# 1bCq5KZ2UQGt81N2qWBvr8sx7WnO_k-HS is in "Unread (Sangha)"
155+
# 17Ky1unlqJA_IkdL0Hzqxo_l9gPxjnar- is in "Buddhism"
156+
file1 = test_cache.get_item('1bCq5KZ2UQGt81N2qWBvr8sx7WnO_k-HS')
157+
file2 = test_cache.get_item('17Ky1unlqJA_IkdL0Hzqxo_l9gPxjnar-')
158+
159+
assert file1 is not None
160+
assert file2 is not None
161+
files = [file1, file2]
162+
163+
ids, reason = gdrive.select_ids_to_keep(files, folder_slugs)
164+
assert ids == ['17Ky1unlqJA_IkdL0Hzqxo_l9gPxjnar-']
165+
assert reason == gdrive.IDSelectionReason.TAG_FOLDER
158166

159167
def test_select_ids_to_keep_name_length(mock_website_config, mock_permissions):
160168
files = [

0 commit comments

Comments
 (0)