Skip to content
test_inline.py 31.8 KiB
Newer Older
from __future__ import annotations


Dong Zhuang's avatar
Dong Zhuang committed
__copyright__ = "Copyright (C) 2018 Dong Zhuang"

__license__ = """
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""

Josh Asplund's avatar
Josh Asplund committed
import pytest
Andreas Klöckner's avatar
Andreas Klöckner committed
from django.test import TestCase
Dong Zhuang's avatar
Dong Zhuang committed
from course.content import get_repo_blob
from course.flow import get_page_behavior
Dong Zhuang's avatar
Dong Zhuang committed
from tests.base_test_mixins import SingleCourseQuizPageTestMixin
Dong Zhuang's avatar
Dong Zhuang committed
from tests.constants import PAGE_ERRORS
Andreas Klöckner's avatar
Andreas Klöckner committed
from tests.test_sandbox import SingleCoursePageSandboxTestBaseMixin
Josh Asplund's avatar
Josh Asplund committed
from tests.utils import mock
Andreas Klöckner's avatar
Andreas Klöckner committed

Dong Zhuang's avatar
Dong Zhuang committed
INLINE_MULTI_MARKDOWN_SINGLE = """
type: InlineMultiQuestion
id: inlinemulti
value: 10
prompt: |

    # An InlineMultiQuestion example

    Complete the following paragraph.

question: |

    Foo and [[blank1]] are often used in code examples.

answers:

    blank1:
        type: ShortAnswer
        width: 4em
        required: False
        hint: Tex can be rendered in hint, e.g. $x_1$.
        hint_title: Hint
        correct_answer:
        - <plain> BAR
        - <plain>bar
"""

Andreas Klöckner's avatar
Andreas Klöckner committed
INLINE_MULTI_MARKDOWN_TWO_NOT_REQUIRED = r"""
Dong Zhuang's avatar
Dong Zhuang committed
type: InlineMultiQuestion
id: inlinemulti
value: 10
prompt: |

    # An InlineMultiQuestion example

    Complete the following paragraph.

question: |

    Foo and [[blank1]] are often used in code examples.
    A quarter equals [[choice1]].

answers:

    blank1:
        type: ShortAnswer
        width: 4em
        required: False
        hint: Tex can be rendered in hint, e.g. $x_1$.
        hint_title: Hint
        correct_answer:
        - <regex>(?:bar)?\s+
        - <plain> BAR
        - <plain>bar

    choice1:
        type: ChoicesAnswer
        choices:
        - 0.2
        - 1/6
        - ~CORRECT~ 0.25
        - <div><p>This_should_be_wrapped_by_p_tag</p></div>
        - [0.25]
"""

INLINE_MULTI_MARKDOWN_EMBEDDED_ATTR_PATTERN = """
type: InlineMultiQuestion
id: inlinemulti
value: 10
prompt: |

    # An InlineMultiQuestion example

    Complete the following paragraph.

question: |

    Foo and [[blank1]] are often used in code examples.
    One dollar is [[blank2]].

answers:

    blank1:
        type: ShortAnswer
        %(attr1)s
        correct_answer:
        - <plain> BAR
        - <plain>bar

    blank2:
        type: ShortAnswer
        %(attr2)s
        correct_answer:
        - type: float
          rtol: 0.00001
          value: 1
        - <plain> one
"""

INLINE_MULTI_MARKDOWN_FLOAT_WITHOUT_TOL = """
type: InlineMultiQuestion
id: inlinemulti
value: 10
prompt: |

    # An InlineMultiQuestion example

    Complete the following paragraph.

question: |

    Foo and [[blank1]] are often used in code examples.
    One dollar is [[blank2]].

answers:

    blank1:
        type: ShortAnswer
        width: 4em
        required: False
        hint: Tex can be rendered in hint, e.g. $x_1$.
        hint_title: Hint
        correct_answer:
        - <plain> BAR
        - <plain>bar

    blank2:
        type: ShortAnswer
        width: 3em
        prepended_text: "$"
        hint: Blank with prepended text
        correct_answer:
        - type: float
          value: 1

"""

INLINE_MULTI_MARKDOWN_NOT_ALLOWED_EMBEDDED_QTYPE = """
type: InlineMultiQuestion
id: inlinemulti
value: 10
prompt: |

    # An InlineMultiQuestion example

    Complete the following paragraph.

question: |

    Foo and [[blank1]] are often used in code examples.

answers:

    blank1:
        type: SomeQuestionType
        width: 4em
        required: False
        hint: Tex can be rendered in hint, e.g. $x_1$.
        hint_title: Hint
        correct_answer:
        - <plain> BAR
        - <plain>bar

"""
Loading
Loading full blame...