示例#1
0
def test_relative_content_url_with_object():
    """This function tests creating a content mention with a relative content URL but with a Khoros object.

    .. versionadded:: 2.4.0

    :returns: None
    """
    title, url, content_id = get_content_test_data(relative_url=True)
    khoros = Khoros()
    print()

    # Testing arguments without a Content ID
    response = messages.format_content_mention(khoros, title=title, url=url)
    assert expected_content_response(response)  # nosec

    # Testing arguments with a Content ID
    response = messages.format_content_mention(khoros,
                                               content_id=content_id,
                                               title=title,
                                               url=url)
    assert expected_content_response(response)  # nosec

    # Testing dictionary without a Content ID
    content_info = {'title': title, 'url': url}
    response = messages.format_content_mention(khoros, content_info)
    assert expected_content_response(response)  # nosec

    # Testing dictionary with a Content ID
    content_info['id'] = content_id
    response = messages.format_content_mention(khoros, content_info)
    assert expected_content_response(response)  # nosec
    return
示例#2
0
def test_bad_content_url():
    """This function tests creating a content mention when an invalid URL is supplied.

    .. versionadded:: 2.4.0

    :returns: None
    :raises: :py:exc:`khoros.errors.exceptions.MessageTypeNotFoundError`
    """
    title = "Click Here"
    url = "https://khoros.com/platform/communities"

    # Testing with arguments
    with pytest.raises(exceptions.MessageTypeNotFoundError):
        messages.format_content_mention(title=title, url=url)

    # Testing with content dictionary
    content_info = {'title': title, 'url': url}
    with pytest.raises(exceptions.MessageTypeNotFoundError):
        messages.format_content_mention(content_info=content_info)
    return
示例#3
0
def test_content_mention_with_no_id_arg():
    """This function tests creating a content mention when no Content ID has been supplied as an argument.

    .. versionadded:: 2.4.0

    :returns: None
    """
    title, url = get_content_test_data(include_id=False)
    response = messages.format_content_mention(title=title, url=url)
    assert response == CORRECT_CONTENT_MENTION  # nosec
    return
示例#4
0
def test_content_mention_with_no_id_dict():
    """This function tests creating a content mention when no Content ID has been supplied in the dictionary.

    .. versionadded:: 2.4.0

    :returns: None
    """
    title, url = get_content_test_data(include_id=False)
    content_info = {'title': title, 'url': url}
    response = messages.format_content_mention(content_info=content_info)
    assert response == CORRECT_CONTENT_MENTION  # nosec
    return
示例#5
0
def test_content_mention_with_false_id_dict():
    """This function tests creating a content mention when an invalid Content ID is supplied in the dictionary.

    .. versionadded:: 2.4.0

    :returns: None
    """
    title, url, content_id = get_content_test_data(false_id=True)
    content_info = {'id': content_id, 'title': title, 'url': url}
    with pytest.warns(UserWarning):
        response = messages.format_content_mention(content_info=content_info)
    assert response == CORRECT_CONTENT_MENTION  # nosec
    return
示例#6
0
def test_content_mention_with_full_dict():
    """This function tests the :py:func:`khoros.objects.messages.format_content_mention` when all required dictionary
       keys and values have been supplied.

    .. versionadded:: 2.4.0

    :returns: None
    """
    title, url, content_id = get_content_test_data()
    content_info = {'id': content_id, 'title': title, 'url': url}
    response = messages.format_content_mention(content_info=content_info)
    assert response == CORRECT_CONTENT_MENTION  # nosec
    return
示例#7
0
def test_content_mention_with_all_arguments():
    """This function tests the :py:func:`khoros.objects.messages.format_content_mention` when all required arguments
       have been supplied.

    .. versionadded:: 2.4.0

    :returns: None
    """
    title, url, content_id = get_content_test_data()
    response = messages.format_content_mention(content_id=content_id,
                                               title=title,
                                               url=url)
    assert response == CORRECT_CONTENT_MENTION  # nosec
    return
示例#8
0
def test_content_mention_with_false_id_arg():
    """This function tests creating a content mention when an invalid Content ID is supplied as an argument.

    .. versionadded:: 2.4.0

    :returns: None
    """
    title, url, content_id = get_content_test_data(false_id=True)
    with pytest.warns(UserWarning):
        response = messages.format_content_mention(content_id=content_id,
                                                   title=title,
                                                   url=url)
    assert response == CORRECT_CONTENT_MENTION  # nosec
    return
示例#9
0
def test_relative_content_url_without_object():
    """This function tests creating a content mention with a relative content URL and no Khoros object.

    .. versionadded:: 2.4.0

    :returns: None
    :raises: :py:exc:`khoros.errors.exceptions.MissingRequiredDataError`
    """
    title, url, content_id = get_content_test_data(relative_url=True)

    # Testing arguments with and without a Content ID
    with pytest.raises(exceptions.MissingRequiredDataError):
        messages.format_content_mention(title=title, url=url)
        messages.format_content_mention(content_id=content_id,
                                        title=title,
                                        url=url)

    # Testing dictionary with and without a Content ID
    content_info = {'title': title, 'url': url}
    with pytest.raises(exceptions.MissingRequiredDataError):
        messages.format_content_mention(content_info=content_info)
        content_info['id'] = content_id
        messages.format_content_mention(content_info=content_info)
    return