def test_enclosure_addin():
    """Test the problem through and in the context of the enclosure
    handling addins (enclosures are one of the problem areas with respect
    to this bug.
    """

    ADDINS = [
        # both plugins separately exhibited the bug in the passed,
        # though note that ``collect_enclosure_data`` depends on
        # ``store_encloures`` and cannot be used without it
        store_enclosures(),
        collect_enclosure_data('length', 'type'),
    ]

    class BozoFeed(feedev.Feed):
        content = """
            <rss>
            <channel>
                <item>
                    <guid>item1</guid>
                    <enclosure href="http://h.com/p/f.mp3" length="10" />
                <!-- item closing tag missing -->
            </channel></rss>
        """

        def pass1(feed):
            # If the patch were not applied, we'd expect a Storm
            # "unicode expected" exception to be raised during
            # addin execution, the assertion here is just for
            # completeness sake.
            href = feed.items.one().enclosures.one().href
            assert href == 'http://h.com/p/f.mp3'
            assert type(href) == unicode

    feedev.testcaller()
from storm.locals import Unicode
from feedplatform import test as feedev
from feedplatform.lib import collect_enclosure_data


ADDINS = [
    # type is a normal string field, length and duration have
    # special handling behind them
    collect_enclosure_data('length', 'type', 'duration')
]


class ValidFeed(feedev.Feed):
    content = """
        <rss>
        <channel>
            <item>
                <guid>item-1</guid>
                <enclosure
                    {% =1 %}length="1000"{% end %}
                    {% =2 %}length="5000"{% end %}
                    {% =3 %}length=""{% end %}
                    {% =4 %}{% end %}
                    {% =5 %}length="-1"{% end %}

                    {% =1 %}type="text/html"{% end %}
                    {% =2 %}type="audio/mpeg"{% end %}
                    {% =3 %}type=""{% end %}
                    {% >4 %}{% end %}
                    href="http://example.org/files/item-1"
                />