CoolFace
Apppublic

sahil-12kumar/IL_CMS_Tools

sourceHugging Faceupdated 5d agoView on Hugging Face
1likes
test_question_pattern.py64 linesDownload Raw Back to tests
1"""The question-pattern placeholder every write path has to carry.2 3CMS started requiring a question pattern wherever a question is approved. The4real vocabulary isn't published yet — it is not in /lookups and no live question5carries a real value — so every writer stamps the same placeholder for now. What6matters is that no write path drops it, and that none of them stomp on a genuine7value once SMEs start setting one in CMS.8"""9import sys10from pathlib import Path11 12import pytest13 14sys.path.insert(0, str(Path(__file__).resolve().parent.parent / 'backend' / 'ai_tagger'))15 16 17@pytest.fixture(scope='module')18def pt():19    import push_tags20    return push_tags21 22 23@pytest.mark.parametrize('existing', [24    None,                       # key absent entirely25    [],                         # the shape most of the bank is in26    ['', '   '],                # present but blank27])28def test_missing_pattern_is_filled(pt, existing):29    data = {} if existing is None else {'question_patterns': existing}30    assert pt.ensure_question_pattern(data) is True31    assert data['question_patterns'] == [pt.DEFAULT_QUESTION_PATTERN]32 33 34def test_null_value_is_filled(pt):35    data = {'question_patterns': None}36    assert pt.ensure_question_pattern(data) is True37    assert data['question_patterns'] == [pt.DEFAULT_QUESTION_PATTERN]38 39 40def test_placeholder_is_left_alone(pt):41    data = {'question_patterns': [pt.DEFAULT_QUESTION_PATTERN]}42    assert pt.ensure_question_pattern(data) is False43    assert data['question_patterns'] == [pt.DEFAULT_QUESTION_PATTERN]44 45 46def test_a_real_pattern_is_never_overwritten(pt):47    """The whole point of the placeholder is to be replaced. Once a human sets a48    real pattern in CMS, a tagging or solutions run must not undo it."""49    data = {'question_patterns': ['assertion_reason']}50    assert pt.ensure_question_pattern(data) is False51    assert data['question_patterns'] == ['assertion_reason']52 53 54def test_uploader_payload_carries_a_pattern(app_mod, pt):55    """The uploader builds its payload from scratch rather than fetch-modify-PUT,56    so it needs the field independently — and with the same value as the tagger,57    or approvability depends on which tool touched the question last."""58    payload = app_mod.build_payload({59        'question_text': 'What is 2 + 2?',60        'option_a': '3', 'option_b': '4', 'option_c': '5', 'option_d': '6',61        'correct_answer': 'B', 'difficulty': 'easy',62    })63    assert payload['question_patterns'] == [pt.DEFAULT_QUESTION_PATTERN]64