Skip to content

Commit

Permalink
add is_found attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
vinta committed Oct 23, 2013
1 parent dc5aecc commit 1fe3323
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 2 deletions.
8 changes: 8 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
History
=======

1.3.1 (2013-10-24)
++++++++++++++++++

- Add `is_found` attribute for `HaulResult`
- Add `to_ordered_dict()` method for `HaulResult`
- `A demo site on Heroku <http://hauler.herokuapp.com/>`_


1.3.0 (2013-10-16)
++++++++++++++++++

Expand Down
2 changes: 1 addition & 1 deletion haul/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding: utf-8

__version__ = '1.3.0'
__version__ = '1.3.1'

from .api import find_images
from .core import Haul, HaulResult
4 changes: 4 additions & 0 deletions haul/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ def __init__(self):
def __repr__(self):
return '<HaulResult [Content-Type: %s]>' % (self.content_type)

@property
def is_found(self):
return True if len(self.finder_image_urls) > 0 else False

@property
def image_urls(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

setup(
name='haul',
version='1.3.0',
version='1.3.1',
description='An Extensible Image Crawler',
long_description=long_description,
keywords='haul web image content scraper parser crawler',
Expand Down
10 changes: 10 additions & 0 deletions tests/fixtures/no_image_page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Hello Haul</title>
</head>
<body>
<p>no image</p>
</body>
</html>
19 changes: 19 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class HaulBaseTestCase(unittest.TestCase):

def setUp(self):
self.complete_html = read_file(os.path.join(TESTS_DIR, 'fixtures/page.html'))
self.no_image_html = read_file(os.path.join(TESTS_DIR, 'fixtures/no_image_page.html'))
self.fragmented_html = read_file(os.path.join(TESTS_DIR, 'fixtures/fragment.html'))

self.blogspot_html = read_file(os.path.join(TESTS_DIR, 'fixtures/blogspot.html'))
Expand Down Expand Up @@ -45,6 +46,24 @@ def setUp(self):
self.not_supported_url = 'https://www.youtube.com/audiolibrary_download?vid=463864fcafcbc5bc'


class HaulResultTestCase(HaulBaseTestCase):

def setUp(self):
super(HaulResultTestCase, self).setUp()

def test_is_found_true(self):
h = Haul()
hr = h.find_images(self.complete_html)

self.assertTrue(hr.is_found)

def test_is_found_false(self):
h = Haul()
hr = h.find_images(self.no_image_html)

self.assertFalse(hr.is_found)


class FindImagesFromHTMLTestCase(HaulBaseTestCase):

def setUp(self):
Expand Down

0 comments on commit 1fe3323

Please sign in to comment.