Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions openedx_filters/management/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
Package where filters related to management command execution are implemented.
"""
59 changes: 59 additions & 0 deletions openedx_filters/management/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""
Package where filters related to management command execution are implemented.
"""

from contextlib import AbstractContextManager

from openedx_filters.tooling import OpenEdxPublicFilter


class ManagementCommandContextmanagerRequested(OpenEdxPublicFilter):
"""
Filter used to wrap Django management command execution in a context manager.

Purpose:
This filter is triggered in ``manage.py`` before a management command is
executed, allowing pipeline steps to provide a context manager wrapper.

Filter Type:
org.openedx.platform.management.command.contextmanager.requested.v1

Trigger:
- Repository: openedx/openedx-platform
- Path: manage.py
- Function or Method: __main__
"""

filter_type = "org.openedx.platform.management.command.contextmanager.requested.v1"

@classmethod
def run_filter(
cls,
command_contextmanager: AbstractContextManager[None],
command_name: str,
service_variant: str,
) -> tuple[AbstractContextManager[None], str, str]:
"""
Process management command context manager arguments through the pipeline.

Arguments:
command_contextmanager (AbstractContextManager[None]): context manager used to wrap command execution.
command_name (str): name of the management command being executed.
service_variant (str): service variant, such as lms or cms.

Returns:
tuple[AbstractContextManager[None], str, str]:
- context manager used to wrap command execution.
- name of the management command.
- service variant, such as lms or cms.
"""
data = super().run_pipeline(
command_contextmanager=command_contextmanager,
command_name=command_name,
service_variant=service_variant,
)
return (
data.get("command_contextmanager", command_contextmanager),
data.get("command_name", command_name),
data.get("service_variant", service_variant),
)
39 changes: 39 additions & 0 deletions openedx_filters/management/tests/test_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
Tests for management subdomain filters.
"""
from contextlib import nullcontext

from django.test import TestCase

from openedx_filters.management.filters import ManagementCommandContextmanagerRequested


class TestManagementFilters(TestCase):
"""
Test class to verify standard behavior of management filters.
"""

def test_management_command_contextmanager_requested(self):
"""
Test ManagementCommandContextmanagerRequested filter behavior.

Expected behavior:
- The filter should return context manager and command metadata.
"""
command_contextmanager = nullcontext()
command_name = "migrate"
service_variant = "lms"

(
filtered_command_contextmanager,
filtered_command_name,
filtered_service_variant,
) = ManagementCommandContextmanagerRequested.run_filter(
command_contextmanager=command_contextmanager,
command_name=command_name,
service_variant=service_variant,
)

assert command_contextmanager == filtered_command_contextmanager
assert command_name == filtered_command_name
assert service_variant == filtered_service_variant
8 changes: 4 additions & 4 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#
# make upgrade
#
asgiref==3.11.1
asgiref==3.12.1
# via django
django==5.2.14
django==5.2.16
# via
# -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt
# -r requirements/base.in
Expand All @@ -18,9 +18,9 @@ pymongo==4.17.0
# via edx-opaque-keys
sqlparse==0.5.5
# via django
stevedore==5.7.0
stevedore==5.9.0
# via edx-opaque-keys
typing-extensions==4.15.0
typing-extensions==4.16.0
# via edx-opaque-keys

# The following packages are considered to be unsafe in a requirements file:
Expand Down
16 changes: 8 additions & 8 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
#
# make upgrade
#
cachetools==7.1.1
cachetools==7.1.6
# via tox
colorama==0.4.6
# via tox
distlib==0.4.0
distlib==0.4.3
# via virtualenv
filelock==3.29.0
filelock==3.32.2
# via
# python-discovery
# tox
Expand All @@ -19,22 +19,22 @@ packaging==26.2
# via
# pyproject-api
# tox
platformdirs==4.9.6
platformdirs==4.11.0
# via
# python-discovery
# tox
# virtualenv
pluggy==1.6.0
# via tox
pyproject-api==1.10.0
pyproject-api==1.11.0
# via tox
python-discovery==1.3.0
python-discovery==1.5.0
# via
# tox
# virtualenv
tomli-w==1.2.0
# via tox
tox==4.53.1
tox==4.58.0
# via -r requirements/ci.in
virtualenv==21.3.1
virtualenv==21.7.0
# via tox
Loading