Skip to content

Commit 2a51af1

Browse files
committed
added management command for running all notifications tests
1 parent 847c461 commit 2a51af1

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

notifications.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ notification_types:
683683
__docs__: ...
684684
object_content_type_model_name: desk
685685
template: 'emails/support_request.html.mako'
686-
tests: ['tests/test_deactivate_requested_accounts.py']
686+
tests: ['scripts/tests/test_deactivate_requested_accounts.py']
687687
- name: desk_request_export
688688
subject: 'Export Request'
689689
__docs__: ...
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import os
2+
import sys
3+
import yaml
4+
import subprocess
5+
from django.core.management.base import BaseCommand
6+
7+
class Command(BaseCommand):
8+
help = 'Run all tests referenced in notifications.yaml.'
9+
10+
def handle(self, *args, **options):
11+
notifications_path = os.path.join(os.getcwd(), 'notifications.yaml')
12+
13+
if not os.path.exists(notifications_path):
14+
self.stdout.write(self.style.ERROR(f'File not found: {notifications_path}'))
15+
return
16+
17+
with open(notifications_path, 'r') as f:
18+
data = yaml.safe_load(f) or {}
19+
20+
test_files = set()
21+
for nt in data.get('notification_types', []):
22+
for test in nt.get('tests', []):
23+
if test and test.strip():
24+
test_files.add(test.strip())
25+
26+
if not test_files:
27+
self.stdout.write(self.style.WARNING('No test files found in notifications.yaml.'))
28+
return
29+
30+
self.stdout.write(self.style.SUCCESS(f'Running tests in {len(test_files)} files...'))
31+
for test_file in sorted(test_files):
32+
self.stdout.write(f' - {test_file}')
33+
34+
# Run pytest once for all test files
35+
result = subprocess.run(
36+
[sys.executable, '-m', 'pytest', *sorted(test_files)]
37+
)
38+
39+
if result.returncode != 0:
40+
self.stdout.write(self.style.ERROR('Some tests failed.'))
41+
sys.exit(result.returncode)
42+
else:
43+
self.stdout.write(self.style.SUCCESS('All tests passed.'))

0 commit comments

Comments
 (0)