Skip to content

Commit

Permalink
Merge pull request #4 from mgaitan/fix_no_selector_defined
Browse files Browse the repository at this point in the history
Fix when no selector is provided.
  • Loading branch information
matiasb committed Sep 7, 2014
2 parents 17a9f57 + b31b77f commit b45d847
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion demiurge/demiurge.py
Expand Up @@ -209,7 +209,7 @@ def html(self):
@classmethod
def _get_items(cls, *args, **kwargs):
pq = pyquery.PyQuery(*args, **kwargs)
items = pq.find(cls._meta.selector)
items = pq(cls._meta.selector)
return items

@classmethod
Expand Down
10 changes: 10 additions & 0 deletions tests/test_demiurge.py
Expand Up @@ -54,6 +54,11 @@ class Meta:
extra_attribute = 'value'


class TestItemNoSelector(demiurge.Item):
class Meta:
base_url = 'http://localhost'


class TestItemWithClean(demiurge.Item):
label = demiurge.TextField(selector='.link')

Expand Down Expand Up @@ -151,6 +156,11 @@ def test_item_html(self):
self.assertIsNotNone(item)
self.assertEqual(item.html, expected)

def test_no_selector_uses_whole_html(self):
self.mock_opener.return_value = "<html><body><p>body</p></body></html>"
item = TestItemNoSelector.one()
self.assertEqual(item.html, '<body><p>body</p></body>')

def test_item_clean(self):
item = TestItemWithClean.one()
self.assertEqual(item.label, 'LINK TEXT.')
Expand Down

0 comments on commit b45d847

Please sign in to comment.