Example #1
0
def test_url_without_node():
    """This function tests to ensure that an appropriate exception is raised when a URL does not contain a valid node.

    :returns: None
    :raises: :py:exc:`AssertionError`, :py:exc:`khoros.errors.exceptions.NodeTypeNotFoundError`
    """
    # Import the base and exceptions modules
    set_package_path()
    from khoros.structures import nodes
    from khoros.errors import exceptions

    # Test passing a URL that does not have a node within it
    with pytest.raises(exceptions.NodeTypeNotFoundError):
        nodes.get_node_id('https://community.khoros.com/this-is-a-test-url')
    return
Example #2
0
def test_with_invalid_node_types():
    """This function tests to ensure that invalid node types will raise the appropriate exception.

    :returns: None
    :raises: :py:exc:`AssertionError`, :py:exc:`khoros.errors.exceptions.InvalidNodeTypeError`
    """
    # Import the base and exceptions modules
    set_package_path()
    from khoros.structures import nodes
    from khoros.errors import exceptions

    # Get the test data
    test_data = get_test_data()

    # Test passing a made-up node type
    with pytest.raises(exceptions.InvalidNodeTypeError):
        nodes.get_node_id(test_data.get('blog'), 'gonna_break')

    # Test passing the wrong node type for a given URL
    with pytest.raises(exceptions.InvalidNodeTypeError):
        nodes.get_node_id(test_data.get('group'), 'tkb')

    # Return when finished
    return
Example #3
0
def test_with_only_url():
    """This function tests the :py:func:`khoros.objects.base.get_node_id` function when only a URL is passed.

    :returns: None
    :raises: :py:exc:`AssertionError`
    """
    # Import the base module
    set_package_path()
    from khoros.structures import nodes

    # Get the test data
    test_data = get_test_data().values()

    # Test getting the Node ID for each URL type
    for url in test_data:
        node_id = nodes.get_node_id(url)
        assert (node_id is not False) and (len(node_id) != 0)  # nosec
    return
Example #4
0
def test_with_valid_node_types():
    """This function tests that Node IDs can be extracted from URLs when valid node types are given.

    :returns: None
    :raises: :py:exc:`AssertionError`, :py:exc:`khoros.errors.exceptions.InvalidNodeTypeError`,
             :py:exc:`khoros.errors.exceptions.NodeIDNotFoundError`,
             :py:exc:`khoros.errors.exceptions.NodeTypeNotFoundError`
    """
    # Import the base module
    set_package_path()
    from khoros.structures import nodes

    # Get the test data
    test_data = get_test_data()

    # Perform the test for each key value pair
    for node_type, url in test_data.items():
        node_id = nodes.get_node_id(url, node_type)
        assert (node_id is not False) and (len(node_id) != 0)  # nosec
    return