Spaces:
Sleeping
Sleeping
| """Tests for `manage.py check_checkpoints` — the >=2-checkpoints-per- | |
| COURSE/VIDEO audit gate.""" | |
| from io import StringIO | |
| import pytest | |
| from django.core.management import call_command | |
| from apps.resources.models import Resource, ResourceCheckpoint | |
| pytestmark = pytest.mark.django_db | |
| def _resource(title, type_, n_checkpoints): | |
| r = Resource.objects.create( | |
| title=title, provider='P', url=f'https://example.com/{title}', | |
| difficulty_level='BEGINNER', duration=60, type=type_, | |
| ) | |
| for i in range(1, n_checkpoints + 1): | |
| ResourceCheckpoint.objects.create( | |
| resource=r, order_index=i, title=f'cp{i}', source='manual', | |
| ) | |
| return r | |
| def _run(): | |
| out = StringIO() | |
| call_command('check_checkpoints', stdout=out) | |
| return out.getvalue() | |
| def test_passes_when_all_course_video_have_two_plus(): | |
| _resource('a', 'COURSE', 3) | |
| _resource('b', 'VIDEO', 2) | |
| out = _run() | |
| assert 'OK' in out | |
| def test_exits_nonzero_when_a_course_has_fewer_than_two(): | |
| _resource('ok', 'COURSE', 2) | |
| _resource('thin', 'COURSE', 1) | |
| with pytest.raises(SystemExit) as exc: | |
| _run() | |
| assert exc.value.code == 1 | |
| def test_zero_checkpoint_video_flagged(): | |
| _resource('novid', 'VIDEO', 0) | |
| with pytest.raises(SystemExit): | |
| _run() | |
| def test_docs_and_articles_are_exempt(): | |
| # DOCS/ARTICLE with 0 checkpoints must NOT trip the gate. | |
| _resource('docs', 'DOCS', 0) | |
| _resource('art', 'ARTICLE', 0) | |
| _resource('course', 'COURSE', 2) | |
| out = _run() | |
| assert 'OK' in out | |