diff --git a/genrss/__init__.py b/genrss/__init__.py
index 64a6c06..381e82c 100644
--- a/genrss/__init__.py
+++ b/genrss/__init__.py
@@ -5,7 +5,7 @@ from datetime import datetime
import pytz
-__all__ = ('GenRSS', 'Enclosure',)
+__all__ = ('GenRSS', 'Item', 'Enclosure')
ElementT = TypeVar('ElementT')
RSS_DEFAULT_GENERATOR = f'Generated by genrss for python'
@@ -116,10 +116,8 @@ class Item:
for category in self.categories:
item.append(create_element('category', CDATA(category)))
-
if self.enclosure:
item.append(self.enclosure.to_element())
-
if self.pub_date:
item.append(create_element('pubDate', self.pub_date))
diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
index 0000000..32fdcf2
--- /dev/null
+++ b/tests/conftest.py
@@ -0,0 +1,23 @@
+import pytest
+
+IMAGE_URL = 'http://s3.smartfridge.me/image.jpg'
+
+
+@pytest.fixture(params=[
+ pytest.param((IMAGE_URL, None, None), id='+/-/-'),
+ pytest.param((IMAGE_URL, 1000, None), id='+/+/-'),
+ pytest.param((IMAGE_URL, 1000, 'image/png'), id='+/+/+'),
+ pytest.param((IMAGE_URL, None, 'image/png'), id='+/-/+'),
+])
+def enclosure_tuple(request):
+ return request.param
+
+
+@pytest.fixture(params=[
+ pytest.param(dict(url=IMAGE_URL), id='+/-/-'),
+ pytest.param(dict(url=IMAGE_URL, size=1000), id='+/+/-'),
+ pytest.param(dict(url=IMAGE_URL, size=1000, type='image/png'), id='+/+/+'),
+ pytest.param(dict(url=IMAGE_URL, type='image/png'), id='+/-/+'),
+])
+def enclosure_dict(request):
+ return request.param
diff --git a/tests/test_enclosure.py b/tests/test_enclosure.py
new file mode 100644
index 0000000..de8e6fc
--- /dev/null
+++ b/tests/test_enclosure.py
@@ -0,0 +1,23 @@
+import pytest
+from genrss import Enclosure
+
+
+def test_init_fails():
+ with pytest.raises(TypeError):
+ Enclosure()
+ assert False
+
+
+def test_init(enclosure_tuple):
+ url, size, type = enclosure_tuple
+ enclosure = Enclosure(url, size, type)
+ assert enclosure.url == url
+ assert enclosure.size == (size or 0)
+ assert enclosure.type == (type or 'image/jpeg')
+
+
+def test_init_from_dict(enclosure_dict):
+ enclosure = Enclosure.from_dict(enclosure_dict)
+ assert enclosure.url == enclosure_dict.get('url')
+ assert enclosure.size == enclosure_dict.get('size', 0)
+ assert enclosure.type == enclosure_dict.get('type', 'image/jpeg')
diff --git a/tests/test_rss.py b/tests/test_rss.py
index c2faff4..1993105 100644
--- a/tests/test_rss.py
+++ b/tests/test_rss.py
@@ -3,7 +3,7 @@ from textwrap import dedent
import pytz
import pytest
-from genrss import RSS_DEFAULT_GENERATOR
+from genrss import RSS_DEFAULT_GENERATOR, Item
from tests.support import create_rss
@@ -109,3 +109,11 @@ def test_feed_categories():
assert xml
assert '' \
'' in xml
+
+
+def test_feed_bad_items():
+ feed = create_rss(items=['item'])
+ xml = feed.xml()
+ assert xml
+ assert '- ' not in xml
+
diff --git a/tests/test_rss_item.py b/tests/test_rss_item.py
index 7610312..6a8fd12 100644
--- a/tests/test_rss_item.py
+++ b/tests/test_rss_item.py
@@ -93,4 +93,14 @@ def test_item_enclosure(feed):
xml = feed.xml()
assert xml
assert '' \
- '
'.format(0, 'image/jpeg', enclosure.url) in xml
\ No newline at end of file
+ ''.format(0, 'image/jpeg', enclosure.url) in xml
+
+
+def test_item_enclosure_from_dict(feed, enclosure_dict):
+ create_item(feed, enclosure=enclosure_dict)
+ xml = feed.xml()
+ assert xml
+ assert '' \
+ ''.format(enclosure_dict.get('size', 0),
+ enclosure_dict.get('type', 'image/jpeg'),
+ enclosure_dict.get('url')) in xml