Esempio n. 1
0
def __set_text_field(text, text_type):
    # type: (str, str) -> Union[None, PlainText, RichText]
    """Helper method to create text field according to text type.

    :type text: str
    :param text_type: Type of the primary text field. Allowed values
        are `PlainText` and `RichText`.
    :type text_type: str
    :return: Object of type
        :py:class:`ask_sdk_model.interfaces.display.PlainText` or
        :py:class:`ask_sdk_model.interfaces.display.RichText` depending
        on text_type
    :rtype: object
    :raises: ValueError
    """
    if text:
        if text_type not in [PLAIN_TEXT_TYPE, RICH_TEXT_TYPE]:
            raise ValueError("Invalid type provided: {}".format(text_type))

        if text_type == PLAIN_TEXT_TYPE:
            return PlainText(text=text)
        else:
            return RichText(text=text)
    else:
        return None
    def test_build_primary_text(self):
        text_val = "test"

        rich_text = RichText(text=text_val)
        text_content = TextContent(primary_text=rich_text)

        assert get_rich_text_content(primary_text=text_val) == text_content, \
            "get_rich_text_content helper returned wrong text content " \
            "with primary text"
    def test_build_tertiary_text_rich(self):
        text_val = "test"

        plain_text = RichText(text=text_val)
        text_content = TextContent(tertiary_text=plain_text)

        assert get_text_content(
            tertiary_text=text_val, tertiary_text_type=RICH_TEXT_TYPE) == text_content, \
            "get_text_content helper returned wrong text content with " \
            "tertiary text and rich type"