fix tests

This commit is contained in:
Martin Zimmermann 2013-09-05 21:13:33 +02:00
parent 3f37b6ff24
commit 35926037a6
3 changed files with 3 additions and 6 deletions

View File

@ -46,7 +46,7 @@ class Comment(object):
for field in self.fields: for field in self.fields:
if field == 'text' and field not in data: if field == 'text' and field not in data:
raise ValueError('Comment needs at least text, but no text was provided.') raise ValueError('Comment needs at least text, but no text was provided.')
comment.__dict__[field] = data.get(field) setattr(comment, field, data.get(field))
return comment return comment
@ -62,5 +62,5 @@ class Comment(object):
def md5(self): def md5(self):
hv = hashlib.md5() hv = hashlib.md5()
for key in set(self.fields) - set(['parent', ]): for key in set(self.fields) - set(['parent', ]):
hv.update(getattr(self, key).encode('utf-8', errors="replace") or u'') hv.update((getattr(self, key) or u"").encode('utf-8', errors="replace"))
return hv.hexdigest() return hv.hexdigest()

View File

@ -45,7 +45,6 @@ def create(app, environ, request, uri):
try: try:
comment = models.Comment.fromjson(request.data) comment = models.Comment.fromjson(request.data)
except ValueError as e: except ValueError as e:
print(1)
return Response(unicode(e), 400) return Response(unicode(e), 400)
for attr in 'author', 'email', 'website': for attr in 'author', 'email', 'website':
@ -53,13 +52,11 @@ def create(app, environ, request, uri):
try: try:
setattr(comment, attr, cgi.escape(getattr(comment, attr))) setattr(comment, attr, cgi.escape(getattr(comment, attr)))
except AttributeError: except AttributeError:
print(1)
Response('', 400) Response('', 400)
try: try:
rv = app.db.add(uri, comment) rv = app.db.add(uri, comment)
except ValueError: except ValueError:
print(1)
abort(400) # FIXME: custom exception class, error descr abort(400) # FIXME: custom exception class, error descr
md5 = rv.md5 md5 = rv.md5

View File

@ -19,7 +19,7 @@ class TestComments(unittest.TestCase):
def setUp(self): def setUp(self):
fd, self.path = tempfile.mkstemp() fd, self.path = tempfile.mkstemp()
self.app = Isso(self.path, '...', '...', 15*60) self.app = Isso(self.path, '...', '...', 15*60, "...")
self.client = Client(self.app, Response) self.client = Client(self.app, Response)
self.get = lambda *x, **z: self.client.get(*x, **z) self.get = lambda *x, **z: self.client.get(*x, **z)