Skip to content

Commit

Permalink
Merge pull request #27 from mkouhei/devel
Browse files Browse the repository at this point in the history
release 0.3.3
  • Loading branch information
mkouhei committed May 11, 2014
2 parents 93dd2fa + ba8c2d7 commit 61f2419
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 8 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
@@ -1,4 +1,5 @@
include MANIFEST.in
include README.rst
include LICENSE
recursive-include docs *.rst
recursive-include shiori *.py *.html *.js *.css *.png
1 change: 0 additions & 1 deletion README

This file was deleted.

3 changes: 2 additions & 1 deletion docs/README.rst → README.rst
Expand Up @@ -168,7 +168,7 @@ You copy pre-commit hook scripts after git clone.::
Next install python 2.7 later and setuptools, pytest, pep8.
Below way is for Debian GNU/Linux Sid system.::

$ sudo apt-get install python python-setuptools python-pytest pep8 libxml2-dev libxml2 python-dev closure-linter
$ sudo apt-get install python python-setuptools python-pytest pep8 libxml2-dev libxml2 python-dev closure-linter python-tox

Then checkout 'devel' branch for development, commit your changes.
Before pull request, execute git rebase.
Expand All @@ -179,3 +179,4 @@ See also
* `django REST framework <http://www.django-rest-framework.org/>`_
* `django-openid-auth README <http://bazaar.launchpad.net/~django-openid-auth/django-openid-auth/trunk/view/head:/README.txt>`_
* `Backbone.js <http://backbonejs.org/>`_

6 changes: 6 additions & 0 deletions docs/HISTORY.rst
@@ -1,6 +1,12 @@
History
-------

0.3.3 (2014-05-12)
^^^^^^^^^^^^^^^^^^

* Fixed bug of validators.
* Added unit test of feed_parser.

0.3.2 (2014-04-18)
^^^^^^^^^^^^^^^^^^

Expand Down
10 changes: 5 additions & 5 deletions setup.py
Expand Up @@ -48,10 +48,10 @@ def run_tests(self):
]


long_description = \
open(os.path.join("docs", "README.rst")).read() + \
open(os.path.join("docs", "HISTORY.rst")).read() + \
open(os.path.join("docs", "TODO.rst")).read()
long_description = (
open("README.rst").read() +
open(os.path.join("docs", "HISTORY.rst")).read() +
open(os.path.join("docs", "TODO.rst")).read())

requires = ['setuptools',
'django',
Expand All @@ -67,7 +67,7 @@ def run_tests(self):
'netaddr']

setup(name='shiori',
version='0.3.2',
version='0.3.3',
description='bookmarking tool based on Web UI and JSON REST API',
long_description=long_description,
author='Kouhei Maeda',
Expand Down
6 changes: 5 additions & 1 deletion shiori/bookmark/validators.py
Expand Up @@ -20,11 +20,13 @@ def validate_url(value):
if IPAddress(hostname).is_loopback():
raise ValidationError('loopback address is prohibited.')
except AddrFormatError:
if getaddr(hostname) is None:
if getaddr(hostname) == []:
raise ValidationError('%s is not found.' % value)
for ip in getaddr(hostname):
if IPAddress(ip).is_loopback():
raise ValidationError('loopback address is prohibited.')
if getaddr(hostname) == []:
raise ValidationError('%s is not found.' % value)
return True


Expand All @@ -38,6 +40,8 @@ def getaddr(hostname):
print(e)
try:
addresses.append(getaddrinfo(hostname, None, AF_INET6)[0][4][0])
except TypeError as e:
print(e)
except gaierror as e:
print(e)
return addresses
22 changes: 22 additions & 0 deletions shiori_tests/test_data/dummy_rss.xml
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Shiori new bookmarks</title><link>http://localhost:8000/shiori/</link><description>Updates on changes and additions to Shiori.</description><atom:link href="http://localhost:8000/shiori/feeds" rel="self"></atom:link><language>en-us</language><lastBuildDate>Sun, 11 May 2014 01:07:25 -0000</lastBuildDate><item><title>How to build custom Debian package automatically by Jenkins</title><link>http://localhost:8000/shiori/b/h6xWZg6qMFKU4hyeySZppi</link><description>&lt;div&gt;
&lt;h3&gt;category: &lt;span class="category"&gt;test&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;&lt;/p&gt;
&lt;/div&gt;
</description><guid>http://localhost:8000/shiori/b/h6xWZg6qMFKU4hyeySZppi</guid></item><item><title>Retrieve and generate debian package of Oracle JDK</title><link>http://localhost:8000/shiori/b/mP3J7ECygP4Va3MLFgYgfP</link><description>&lt;div&gt;
&lt;h3&gt;category: &lt;span class="category"&gt;test&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;&lt;/p&gt;
&lt;/div&gt;
</description><guid>http://localhost:8000/shiori/b/mP3J7ECygP4Va3MLFgYgfP</guid></item><item><title>Manage multiple distributions with reprepro</title><link>http://localhost:8000/shiori/b/2jhgpAkPNU9M8uZZ8uq6gV</link><description>&lt;div&gt;
&lt;h3&gt;category: &lt;span class="category"&gt;test&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;&lt;/p&gt;
&lt;/div&gt;
</description><guid>http://localhost:8000/shiori/b/2jhgpAkPNU9M8uZZ8uq6gV</guid></item><item><title>Infinite loop using chord of Celery</title><link>http://localhost:8000/shiori/b/FQ47A8MSpMg3gwqKt9cEC6</link><description>&lt;div&gt;
&lt;h3&gt;category: &lt;span class="category"&gt;test&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;&lt;/p&gt;
&lt;/div&gt;
</description><guid>http://localhost:8000/shiori/b/FQ47A8MSpMg3gwqKt9cEC6</guid></item><item><title>OBS266はやっぱり綺麗だなぁ。</title><link>http://localhost:8000/shiori/b/zyvKxw3eQseShLjmd7Rrwe</link><description>&lt;div&gt;
&lt;h3&gt;category: &lt;span class="category"&gt;computer&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;テストhogeだす。&lt;/p&gt;
&lt;/div&gt;
</description><guid>http://localhost:8000/shiori/b/zyvKxw3eQseShLjmd7Rrwe</guid></item></channel></rss>
49 changes: 49 additions & 0 deletions shiori_tests/tests/test_feed_parser.py
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
import unittest
from httpretty import HTTPretty, httprettified
from defusedxml.lxml import RestrictedElement
from shiori.bookmark.agents import feed_parser


class FeedParserTests(unittest.TestCase):

def test_retrieve_not_connect_server(self):
with self.assertRaises(SystemExit) as e:
parser = feed_parser.FeedParser('http://example.org/rss')
self.assertEqual(1, e.exception.code)

@httprettified
def test_feedparser_not_expected_response(self):
HTTPretty.register_uri(HTTPretty.GET,
'http://example.org/rss')
with self.assertRaises(SystemExit) as e:
parser = feed_parser.FeedParser('http://example.org/rss')
self.assertEqual(1, e.exception.code)

@httprettified
def test_feedparser_properties(self):
with open('shiori_tests/test_data/dummy_rss.xml', 'rb') as f:
content = f.read()
HTTPretty.register_uri(HTTPretty.GET,
'http://example.org/rss',
body=content)
parser = feed_parser.FeedParser('http://example.org/rss')
self.assertEqual({'atom': 'http://www.w3.org/2005/Atom'},
parser.nsmap)
self.assertEqual('', parser.ns)
self.assertEqual('Sun, 11 May 2014 01:07:25 -0000',
parser.updated)
self.assertEqual('Shiori new bookmarks', parser.title)
self.assertEqual(5, len(parser.items))
self.assertTrue(isinstance(parser.etree, RestrictedElement))

@httprettified
def test_retrieve_items(self):
with open('shiori_tests/test_data/dummy_rss.xml', 'rb') as f:
content = f.read()
HTTPretty.register_uri(HTTPretty.GET,
'http://example.org/rss',
body=content)
parser = feed_parser.FeedParser('http://example.org/rss')
items = parser.retrieve_items()
self.assertEqual(5, len(items))
29 changes: 29 additions & 0 deletions shiori_tests/tests/test_validators.py
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
import unittest
from django.core.exceptions import ValidationError
from shiori.bookmark import validators


class ValidatorsTests(unittest.TestCase):
def test_validate_url(self):
self.assertTrue(validators.validate_url('http://example.org'))

def test_validate_url_of_localhost(self):
self.assertRaises(ValidationError,
validators.validate_url,
'http://localhost')

def test_validate_url_of_not_found(self):
self.assertRaises(ValidationError,
validators.validate_url,
'http://hoge.example.org')

def test_validate_url_of_loopback_addr(self):
self.assertRaises(ValidationError,
validators.validate_url,
'http://127.0.0.1')

def test_get_addr(self):
self.assertListEqual(['93.184.216.119',
'2606:2800:220:6d:26bf:1447:1097:aa7'],
validators.getaddr('example.org'))
1 change: 1 addition & 0 deletions tox.ini
Expand Up @@ -27,6 +27,7 @@ deps=
requests
netaddr
bzr+http://bazaar.launchpad.net/~andrewsomething/django-openid-auth/1252445#egg=django-openid-auth
httpretty
closure-linter

[testenv:py27]
Expand Down

0 comments on commit 61f2419

Please sign in to comment.