-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10418 from Johnetordoff/s3-improvement-migration
[S3 Improvements] Delimiter Migration
- Loading branch information
Showing
3 changed files
with
124 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# -*- coding: utf-8 -*- | ||
import logging | ||
|
||
from django.core.management.base import BaseCommand | ||
from addons.s3.utils import update_folder_names, reverse_update_folder_names | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
Adds Colon (':') delineators to s3 buckets to separate them from them from their subfolder, so `<bucket_name>` | ||
becomes `<bucket_name>:/` , the root path. Folder names will also be updated to maintain consistency. | ||
""" | ||
|
||
def add_arguments(self, parser): | ||
super().add_arguments(parser) | ||
parser.add_argument( | ||
'--reverse', | ||
action='store_true', | ||
dest='reverse', | ||
help='Unsets date_retraction' | ||
) | ||
|
||
def handle(self, *args, **options): | ||
reverse = options.get('reverse', False) | ||
if reverse: | ||
reverse_update_folder_names() | ||
else: | ||
update_folder_names() |
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,41 @@ | ||
import pytest | ||
from addons.s3.utils import update_folder_names, reverse_update_folder_names | ||
|
||
@pytest.mark.django_db | ||
class TestUpdateFolderNamesMigration: | ||
|
||
def test_update_folder_names_migration(self): | ||
from addons.s3.models import NodeSettings | ||
from addons.s3.tests.factories import S3NodeSettingsFactory | ||
# Create sample folder names and IDs | ||
S3NodeSettingsFactory(folder_name='Folder 1 (Location 1)', folder_id='folder1') | ||
S3NodeSettingsFactory(folder_name='Folder 2', folder_id='folder2') | ||
S3NodeSettingsFactory(folder_name='Folder 3 (Location 3)', folder_id='folder3') | ||
S3NodeSettingsFactory(folder_name='Folder 4:/ (Location 4)', folder_id='folder4:/') | ||
|
||
update_folder_names() | ||
|
||
# Verify updated folder names and IDs | ||
updated_folder_names_ids = NodeSettings.objects.values_list('folder_name', 'folder_id') | ||
expected_updated_folder_names_ids = { | ||
('Folder 1:/ (Location 1)', 'folder1:/'), | ||
('Folder 2:/', 'folder2:/'), | ||
('Folder 3:/ (Location 3)', 'folder3:/'), | ||
('Folder 3:/ (Location 3)', 'folder3:/'), | ||
('Folder 4:/ (Location 4)', 'folder4:/'), | ||
|
||
} | ||
assert set(updated_folder_names_ids) == expected_updated_folder_names_ids | ||
|
||
# Reverse the migration | ||
reverse_update_folder_names() | ||
|
||
# Verify the folder names and IDs after the reverse migration | ||
reverted_folder_names_ids = NodeSettings.objects.values_list('folder_name', 'folder_id') | ||
expected_reverted_folder_names_ids = { | ||
('Folder 1 (Location 1)', 'folder1'), | ||
('Folder 2', 'folder2'), | ||
('Folder 3 (Location 3)', 'folder3'), | ||
('Folder 4 (Location 4)', 'folder4'), | ||
} | ||
assert set(reverted_folder_names_ids) == expected_reverted_folder_names_ids |