def test_yaml_vs_text_tagging():
    """
    API: ConfigBase YAML vs TEXT tagging
    """

    yaml_result, _ = ConfigBase.config_parse_yaml("""
    urls:
      - mailtos://lead2gold:[email protected]:
         tag: mytag
    """)
    assert yaml_result

    text_result, _ = ConfigBase.config_parse_text("""
    mytag=mailtos://lead2gold:[email protected]
    """)
    assert text_result

    # Now we compare our results and verify they are the same
    assert len(yaml_result) == len(text_result)
    assert isinstance(yaml_result[0], plugins.NotifyEmail)
    assert isinstance(text_result[0], plugins.NotifyEmail)
    assert 'mytag' in text_result[0]
    assert 'mytag' in yaml_result[0]
def test_config_base_config_parse_text():
    """
    API: ConfigBase.config_parse_text object

    """

    # Garbage Handling
    assert isinstance(ConfigBase.config_parse_text(object()), list)
    assert isinstance(ConfigBase.config_parse_text(None), list)
    assert isinstance(ConfigBase.config_parse_text(''), list)

    # Valid Configuration
    result = ConfigBase.config_parse_text("""
    # A comment line over top of a URL
    mailto://userb:[email protected]

    # A line with mulitiple tag assignments to it
    taga,tagb=kde://
    """,
                                          asset=AppriseAsset())

    # We expect to parse 2 entries from the above
    assert isinstance(result, list)
    assert len(result) == 2
    assert len(result[0].tags) == 0

    # Our second element will have tags associated with it
    assert len(result[1].tags) == 2
    assert 'taga' in result[1].tags
    assert 'tagb' in result[1].tags

    # Here is a similar result set however this one has an invalid line
    # in it which invalidates the entire file
    result = ConfigBase.config_parse_text("""
    # A comment line over top of a URL
    mailto://userc:[email protected]

    # A line with mulitiple tag assignments to it
    taga,tagb=windows://

    I am an invalid line that does not follow any of the Apprise file rules!
    """)

    # We expect to parse 0 entries from the above
    assert isinstance(result, list)
    assert len(result) == 0

    # More invalid data
    result = ConfigBase.config_parse_text("""
    # An invalid URL
    invalid://user:[email protected]

    # A tag without a url
    taga=

    # A very poorly structured url
    sns://:@/

    # Just 1 token provided
    sns://T1JJ3T3L2/
    """)

    # We expect to parse 0 entries from the above
    assert isinstance(result, list)
    assert len(result) == 0

    # Here is an empty file
    result = ConfigBase.config_parse_text('')

    # We expect to parse 0 entries from the above
    assert isinstance(result, list)
    assert len(result) == 0
Beispiel #3
0
def test_config_base_config_parse_text():
    """
    API: ConfigBase.config_parse_text object

    """

    # Garbage Handling
    for garbage in (object(), None, 42):
        # A response is always correctly returned
        result = ConfigBase.config_parse_text(garbage)
        # response is a tuple...
        assert isinstance(result, tuple)
        # containing 2 items (plugins, config)
        assert len(result) == 2
        # In the case of garbage in, we get garbage out; both lists are empty
        assert result == (list(), list())

    # Valid Configuration
    result, config = ConfigBase.config_parse_text("""
    # A comment line over top of a URL
    mailto://userb:[email protected]

    # Test a URL using it's native format; in this case Ryver
    https://apprise.ryver.com/application/webhook/ckhrjW8w672m6HG

    # Invalid URL as it's not associated with a plugin
    # or a native url
    https://not.a.native.url/

    # A line with mulitiple tag assignments to it
    taga,tagb=kde://

    # An include statement to Apprise API with trailing spaces:
    include http://localhost:8080/notify/apprise

    # A relative include statement (with trailing spaces)
    include apprise.cfg     """,
                                                  asset=AppriseAsset())

    # We expect to parse 3 entries from the above
    assert isinstance(result, list)
    assert isinstance(config, list)
    assert len(result) == 3
    assert len(result[0].tags) == 0

    # Our last element will have 2 tags associated with it
    assert len(result[-1].tags) == 2
    assert 'taga' in result[-1].tags
    assert 'tagb' in result[-1].tags

    assert len(config) == 2
    assert 'http://localhost:8080/notify/apprise' in config
    assert 'apprise.cfg' in config

    # Here is a similar result set however this one has an invalid line
    # in it which invalidates the entire file
    result, config = ConfigBase.config_parse_text("""
    # A comment line over top of a URL
    mailto://userc:[email protected]

    # A line with mulitiple tag assignments to it
    taga,tagb=windows://

    I am an invalid line that does not follow any of the Apprise file rules!
    """)

    # We expect to parse 0 entries from the above because the invalid line
    # invalidates the entire configuration file. This is for security reasons;
    # we don't want to point at files load content in them just because they
    # resemble an Apprise configuration.
    assert isinstance(result, list)
    assert len(result) == 0

    # There were no include entries defined
    assert len(config) == 0

    # More invalid data
    result, config = ConfigBase.config_parse_text("""
    # An invalid URL
    invalid://user:[email protected]

    # A tag without a url
    taga=

    # A very poorly structured url
    sns://:@/

    # Just 1 token provided
    sns://T1JJ3T3L2/

    # Even with the above invalid entries, we can still
    # have valid include lines
    include file:///etc/apprise.cfg

    # An invalid include (nothing specified afterwards)
    include

    # An include of a config type we don't support
    include invalid://
    """)

    # We expect to parse 0 entries from the above
    assert isinstance(result, list)
    assert len(result) == 0

    # There was 1 valid entry
    assert len(config) == 0

    # Test case where a comment is on it's own line with nothing else
    result, config = ConfigBase.config_parse_text("#")
    # We expect to parse 0 entries from the above
    assert isinstance(result, list)
    assert len(result) == 0

    # There were no include entries defined
    assert len(config) == 0
Beispiel #4
0
def test_config_base_config_parse_text():
    """
    API: ConfigBase.config_parse_text object

    """

    # Garbage Handling
    assert isinstance(ConfigBase.config_parse_text(object()), list)
    assert isinstance(ConfigBase.config_parse_text(None), list)
    assert isinstance(ConfigBase.config_parse_text(''), list)

    # Valid Configuration
    result = ConfigBase.config_parse_text("""
    # A comment line over top of a URL
    mailto://userb:[email protected]

    # Test a URL using it's native format; in this case Ryver
    https://apprise.ryver.com/application/webhook/ckhrjW8w672m6HG

    # Invalid URL as it's not associated with a plugin
    # or a native url
    https://not.a.native.url/

    # A line with mulitiple tag assignments to it
    taga,tagb=kde://
    """, asset=AppriseAsset())

    # We expect to parse 3 entries from the above
    assert isinstance(result, list)
    assert len(result) == 3
    assert len(result[0].tags) == 0

    # Our last element will have 2 tags associated with it
    assert len(result[-1].tags) == 2
    assert 'taga' in result[-1].tags
    assert 'tagb' in result[-1].tags

    # Here is a similar result set however this one has an invalid line
    # in it which invalidates the entire file
    result = ConfigBase.config_parse_text("""
    # A comment line over top of a URL
    mailto://userc:[email protected]

    # A line with mulitiple tag assignments to it
    taga,tagb=windows://

    I am an invalid line that does not follow any of the Apprise file rules!
    """)

    # We expect to parse 0 entries from the above
    assert isinstance(result, list)
    assert len(result) == 0

    # More invalid data
    result = ConfigBase.config_parse_text("""
    # An invalid URL
    invalid://user:[email protected]

    # A tag without a url
    taga=

    # A very poorly structured url
    sns://:@/

    # Just 1 token provided
    sns://T1JJ3T3L2/
    """)

    # We expect to parse 0 entries from the above
    assert isinstance(result, list)
    assert len(result) == 0

    # Here is an empty file
    result = ConfigBase.config_parse_text('')

    # We expect to parse 0 entries from the above
    assert isinstance(result, list)
    assert len(result) == 0

    # Test case where a comment is on it's own line with nothing else
    result = ConfigBase.config_parse_text("#")
    # We expect to parse 0 entries from the above
    assert isinstance(result, list)
    assert len(result) == 0

    # Test case of empty file
    result = ConfigBase.config_parse_text("")
    # We expect to parse 0 entries from the above
    assert isinstance(result, list)
    assert len(result) == 0