-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
191 additions
and
56 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
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
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,37 @@ | ||
from __future__ import annotations | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
from django_qstash.discovery.utils import discover_tasks | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "View all available tasks" | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
"--locations", | ||
action="store_true", | ||
help="Only show task paths", | ||
) | ||
|
||
def handle(self, *args, **options): | ||
locations_only = options["locations"] or False | ||
self.stdout.write("Available tasks:") | ||
discover_tasks.cache_clear() | ||
if locations_only: | ||
tasks = discover_tasks(locations_only=locations_only) | ||
for task in tasks: | ||
self.stdout.write(f"\t- {self.style.SQL_FIELD(task)}") | ||
else: | ||
tasks = discover_tasks(locations_only=False) | ||
for task in tasks: | ||
name = task["name"] | ||
field_label = task["field_label"] | ||
location = task["location"] | ||
self.stdout.write( | ||
f" Name: {self.style.SQL_FIELD(name)}\n" | ||
f" Location: {self.style.SQL_FIELD(location)}\n" | ||
f" Field Label: {self.style.SQL_FIELD(field_label)}" | ||
) | ||
self.stdout.write("") |
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 |
---|---|---|
@@ -1,29 +1,29 @@ | ||
from __future__ import annotations | ||
|
||
from django.test import override_settings | ||
|
||
from django_qstash.discovery.utils import discover_tasks | ||
|
||
|
||
@override_settings(INSTALLED_APPS=["tests.discovery"]) | ||
def test_discovers_basic_task(): | ||
"""Test that basic task discovery works""" | ||
tasks = discover_tasks() | ||
expected_tasks = [ | ||
( | ||
"tests.discovery.tasks.custom_name_task", | ||
"Custom Name Task (tests.discovery.tasks)", | ||
), | ||
( | ||
"tests.discovery.tasks.debug_task", | ||
"tests.discovery.tasks.debug_task", | ||
), | ||
{ | ||
"name": "Custom Name Task", | ||
"field_label": "Custom Name Task (tests.discovery.tasks)", | ||
"location": "tests.discovery.tasks.custom_name_task", | ||
}, | ||
{ | ||
"name": "debug_task", | ||
"field_label": "tests.discovery.tasks.debug_task", | ||
"location": "tests.discovery.tasks.debug_task", | ||
}, | ||
{ | ||
"name": "Cleanup Task Results", | ||
"field_label": "Cleanup Task Results (django_qstash.results.tasks)", | ||
"location": "django_qstash.results.tasks.clear_stale_results_task", | ||
}, | ||
] | ||
assert len(tasks) == len(expected_tasks) | ||
|
||
task_values = [task[0] for task in tasks] | ||
expected_task_values = [task[0] for task in expected_tasks] | ||
assert expected_task_values == task_values | ||
task_labels = [task[1] for task in tasks] | ||
expected_task_labels = [task[1] for task in expected_tasks] | ||
assert expected_task_labels == task_labels | ||
tasks_set = {tuple(sorted(t.items())) for t in tasks} | ||
expected_tasks_set = {tuple(sorted(t.items())) for t in expected_tasks} | ||
assert tasks_set == expected_tasks_set |
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,52 @@ | ||
from __future__ import annotations | ||
|
||
from io import StringIO | ||
|
||
import pytest | ||
from django.core.management import call_command | ||
|
||
|
||
@pytest.mark.django_db | ||
class TestAvailableTasks: | ||
def test_available_tasks_basic(self): | ||
"""Test that the available_tasks command outputs all task information""" | ||
out = StringIO() | ||
call_command("available_tasks", stdout=out) | ||
output = out.getvalue() | ||
|
||
# Check header | ||
assert "Available tasks:" in output | ||
|
||
# Updated assertions to match actual implementation | ||
assert "Name: Custom Name Task" in output | ||
assert "Location: tests.discovery.tasks.custom_name_task" in output | ||
assert "Field Label: Custom Name Task (tests.discovery.tasks)" in output | ||
|
||
assert "Name: debug_task" in output | ||
assert "Location: tests.discovery.tasks.debug_task" in output | ||
assert "Field Label: tests.discovery.tasks.debug_task" in output | ||
|
||
assert "Name: Cleanup Task Results" in output | ||
assert ( | ||
"Location: django_qstash.results.tasks.clear_stale_results_task" in output | ||
) | ||
assert ( | ||
"Field Label: Cleanup Task Results (django_qstash.results.tasks)" in output | ||
) | ||
|
||
def test_available_tasks_locations_only(self): | ||
"""Test that the --locations flag only shows task paths""" | ||
out = StringIO() | ||
call_command("available_tasks", "--locations", stdout=out) | ||
output = out.getvalue() | ||
|
||
# Check header | ||
assert "Available tasks:" in output | ||
|
||
# Updated assertions to match actual output format | ||
assert "tests.discovery.tasks.custom_name_task" in output | ||
assert "tests.discovery.tasks.debug_task" in output | ||
|
||
# Verify other details are not present | ||
assert "Name:" not in output | ||
assert "Field Label:" not in output |
Oops, something went wrong.