[damned-lies] Catch InvalidURL exception and add test
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Catch InvalidURL exception and add test
- Date: Fri, 14 Jan 2011 15:09:30 +0000 (UTC)
commit 00930346a53acbbfe97458cde070d060fa4e6877
Author: Claude Paroz <claude 2xlibre net>
Date: Fri Jan 14 16:09:09 2011 +0100
Catch InvalidURL exception and add test
people/forms.py | 3 ++-
people/tests/__init__.py | 27 +++++++++++++++++++++++++--
2 files changed, 27 insertions(+), 3 deletions(-)
---
diff --git a/people/forms.py b/people/forms.py
index 8cf134f..4493e69 100644
--- a/people/forms.py
+++ b/people/forms.py
@@ -98,10 +98,11 @@ def get_image_size(url):
Code partially copied from http://effbot.org/zone/pil-image-size.htm """
import urllib
import ImageFile
+ from httplib import InvalidURL
try:
file = urllib.urlopen(url)
- except (IOError, UnicodeError):
+ except (IOError, UnicodeError, InvalidURL):
raise forms.ValidationError(_(u"The URL you provided is not valid"))
size = None
p = ImageFile.Parser()
diff --git a/people/tests/__init__.py b/people/tests/__init__.py
index 055440c..c2c5a1a 100644
--- a/people/tests/__init__.py
+++ b/people/tests/__init__.py
@@ -21,12 +21,35 @@
from django.test import TestCase
from django.test.client import Client
from django.core.urlresolvers import reverse
+from django.forms import ValidationError
+
+from people.models import Person
+from people import forms
class PeopleTestCase(TestCase):
def test_register(self):
- c = Client()
- response = c.post(reverse('register'),
+ response = self.client.post(reverse('register'),
{'username': u'test01', 'password1': u'1234567',
'password2': u'1234567', 'email': u'test01 example org'})
self.assertRedirects(response, reverse('register_success'))
+ self.assertEqual(Person.objects.filter(username=u'test01').count(), 1)
+
+ def test_edit_details(self):
+ self.pn = Person(first_name='John', last_name='Nothing',
+ email='jn devnull com', username= 'jn')
+ self.pn.set_password('password')
+ self.pn.save()
+ self.client.login(username='jn', password='password')
+ post_data = {
+ 'first_name': "Johnny", 'last_name': "Nothing", 'email': u'test02 example org',
+ 'image': '', 'webpage_url': "http://www.example.org/"
+ }
+ response = self.client.post(reverse('person_detail_change'), post_data)
+ self.pn = Person.objects.get(pk=self.pn.pk)
+ self.assertEqual(self.pn.email, u'test02 example org')
+ # bad image url
+ post_data['image'] = "http://http://www.example.org/image.jpg"
+ form = forms.DetailForm(post_data, instance=self.pn)
+ self.assertFalse(form.is_valid())
+ self.assertTrue('image' in form.errors)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]