Skip to content

Commit 49a3265

Browse files
committed
🐛(backend) fix management command to rename BBB documents
After some IRL tests on preprod, the management commands was not working for some documents. Fixing the command for these cases.
1 parent e18e66b commit 49a3265

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/backend/marsha/bbb/management/commands/rename_classroom_documents.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import boto3
1010

1111
from marsha.bbb.models import ClassroomDocument
12-
from marsha.core.defaults import AWS_STORAGE_BASE_DIRECTORY
12+
from marsha.core.defaults import AWS_S3, AWS_STORAGE_BASE_DIRECTORY, READY
1313
from marsha.core.storage.storage_class import file_storage
1414
from marsha.core.utils import time_utils
1515

@@ -44,7 +44,11 @@ def validate_filename(self, value):
4444
def handle(self, *args, **options):
4545
"""Execute management command."""
4646

47-
for document in ClassroomDocument.objects.all():
47+
documents = ClassroomDocument.objects.filter(
48+
storage_location=AWS_S3, upload_state=READY
49+
)
50+
51+
for document in documents:
4852
# Get the file stored on Scaleway S3 under `aws/`
4953
stamp = time_utils.to_timestamp(document.uploaded_on)
5054
extension = ""

src/backend/marsha/bbb/tests/test_command_rename_classroom_documents.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from marsha.bbb.factories import ClassroomDocumentFactory, ClassroomFactory
1414
from marsha.bbb.management.commands import rename_classroom_documents
1515
from marsha.bbb.models import ClassroomDocument
16+
from marsha.core.defaults import AWS_S3, PENDING, READY, SCW_S3
1617
from marsha.core.utils import time_utils
1718

1819

@@ -44,8 +45,9 @@ def test_rename_classroom_documents(self, mock_exists):
4445
classroom=ClassroomFactory(),
4546
filename=filename_src,
4647
uploaded_on=now,
48+
upload_state=READY,
49+
storage_location=AWS_S3,
4750
)
48-
4951
documents.append(document)
5052

5153
# Create mocks for copy_objects with Stubber
@@ -82,6 +84,18 @@ def test_rename_classroom_documents(self, mock_exists):
8284
}
8385
s3_client_stubber.add_response("copy_object", {}, expected_params)
8486

87+
# Create some classroom documents that should not be concerned
88+
ClassroomDocumentFactory(
89+
classroom=ClassroomFactory(),
90+
upload_state=READY,
91+
storage_location=SCW_S3,
92+
)
93+
ClassroomDocumentFactory(
94+
classroom=ClassroomFactory(),
95+
upload_state=PENDING,
96+
storage_location=AWS_S3,
97+
)
98+
8599
call_command("rename_classroom_documents")
86100

87101
s3_client_stubber.assert_no_pending_responses()

0 commit comments

Comments
 (0)