Spaces:
Running
Running
Sahil Kumar
Claude Opus 5
cms: carry a question pattern on every path that writes or approves
572a729 Download tests/test_question_pattern.py from sahil-12kumar/IL_CMS_Tools: direct link, hf CLI and curl.
- Browser
- Download file 2.52 kB
-
https://huggingface.co/spaces/sahil-12kumar/IL_CMS_Tools/resolve/main/tests/test_question_pattern.py
- Command line
-
hf download hf://spaces/sahil-12kumar/IL_CMS_Tools/tests/test_question_pattern.py
-
curl -L -o test_question_pattern.py https://huggingface.co/spaces/sahil-12kumar/IL_CMS_Tools/resolve/main/tests/test_question_pattern.py
2.52 kB
| """The question-pattern placeholder every write path has to carry. | |
| CMS started requiring a question pattern wherever a question is approved. The | |
| real vocabulary isn't published yet — it is not in /lookups and no live question | |
| carries a real value — so every writer stamps the same placeholder for now. What | |
| matters is that no write path drops it, and that none of them stomp on a genuine | |
| value once SMEs start setting one in CMS. | |
| """ | |
| import sys | |
| from pathlib import Path | |
| import pytest | |
| sys.path.insert(0, str(Path(__file__).resolve().parent.parent / 'backend' / 'ai_tagger')) | |
| def pt(): | |
| import push_tags | |
| return push_tags | |
| def test_missing_pattern_is_filled(pt, existing): | |
| data = {} if existing is None else {'question_patterns': existing} | |
| assert pt.ensure_question_pattern(data) is True | |
| assert data['question_patterns'] == [pt.DEFAULT_QUESTION_PATTERN] | |
| def test_null_value_is_filled(pt): | |
| data = {'question_patterns': None} | |
| assert pt.ensure_question_pattern(data) is True | |
| assert data['question_patterns'] == [pt.DEFAULT_QUESTION_PATTERN] | |
| def test_placeholder_is_left_alone(pt): | |
| data = {'question_patterns': [pt.DEFAULT_QUESTION_PATTERN]} | |
| assert pt.ensure_question_pattern(data) is False | |
| assert data['question_patterns'] == [pt.DEFAULT_QUESTION_PATTERN] | |
| def test_a_real_pattern_is_never_overwritten(pt): | |
| """The whole point of the placeholder is to be replaced. Once a human sets a | |
| real pattern in CMS, a tagging or solutions run must not undo it.""" | |
| data = {'question_patterns': ['assertion_reason']} | |
| assert pt.ensure_question_pattern(data) is False | |
| assert data['question_patterns'] == ['assertion_reason'] | |
| def test_uploader_payload_carries_a_pattern(app_mod, pt): | |
| """The uploader builds its payload from scratch rather than fetch-modify-PUT, | |
| so it needs the field independently — and with the same value as the tagger, | |
| or approvability depends on which tool touched the question last.""" | |
| payload = app_mod.build_payload({ | |
| 'question_text': 'What is 2 + 2?', | |
| 'option_a': '3', 'option_b': '4', 'option_c': '5', 'option_d': '6', | |
| 'correct_answer': 'B', 'difficulty': 'easy', | |
| }) | |
| assert payload['question_patterns'] == [pt.DEFAULT_QUESTION_PATTERN] | |