# HG changeset patch # User wakimd # Date 1289918112 -3600 # Node ID 000f3ca19eaa8c0bfdce2c4d3f280ee005951f35 # Parent 22ab430e9b64e9cd1a199517bc7aff86f4c3260e Added 404 templates + some views corrections diff -r 22ab430e9b64 -r 000f3ca19eaa web/ldt/text/tests.py --- a/web/ldt/text/tests.py Tue Nov 16 14:15:07 2010 +0100 +++ b/web/ldt/text/tests.py Tue Nov 16 15:35:12 2010 +0100 @@ -46,8 +46,7 @@ # def test_error_create(self): # content = base64.urlsafe_b64encode('d2c1d1fa-629d-4520-a3d2-955b4f2582c0http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168tag1tag2#AAAAAA<![CDATA[titre de l\'annotation]]>oaubert79cd0532-1dda-4130-b351-6a181130a7c92010-09-06 12:33:53.417550oaubert79cd0532-1dda-4130-b351-6a181130a7c92010-09-06 12:33:53.420459') # response = self.c.post('/api/'+ VERSION_STR +'/text/create/', {'content':content}) -# #annot2 = create_annotation(content) -# self.assertEqual(response.status_code, '409') +# self.assertEqual(response.status_code, 409) # This test creates an annotation, then gets it, and checks that the returned xml contains correct data @@ -69,12 +68,9 @@ self.assertEqual(self.annot1.xpath("/iri/text-annotation/content/color/text()")[0],self.annotation.color) self.assertEqual(self.annot1.xpath("/iri/text-annotation/meta/created/text()")[0], str(self.annotation.creation_date)) -# def test_error_get(self): -# response = self.c.get('/api/'+ VERSION_STR +'/text/get/', {'id':'2'}) -# #response = self.c.get('/api/'+ VERSION_STR +'/text/get/', {'id':'2'}) -# #annot3 = get_annotation('d2c1d1fa-629d-4520-a3d2-955b4f2582c0') -# #resp = response.status_code -# self.assertEqual(response.status_code,'404') + def test_error_get(self): + response = self.c.get('/api/'+ VERSION_STR +'/text/get/', {'id':'2'}) + self.assertEqual(response.status_code,404) class FilterTest(unittest.TestCase): @@ -141,18 +137,17 @@ def test_delete_annotation(self): response = self.c.post('/api/'+ VERSION_STR +'/text/delete/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'}) - #response2 = self.c.get('/ldt/get/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'}) + response2 = self.c.get('/ldt/get/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'}) doc = lxml.etree.fromstring(response.content) self.assertEqual(doc.xpath("/iri/text-annotation/id/text()"),[]) self.assertEqual(doc.xpath("/iri/text-annotation/tags/tag/text()"), []) self.assertEqual(doc.xpath("/iri/text-annotation/content/color/text()"),[]) self.assertEqual(doc.xpath("/iri/text-annotation/meta/creator/text()"),[]) - #self.assertEqual(response2.status_code, '404') + self.assertEqual(response2.status_code, 404) -# def test_error_delete(self): -# response = self.c.post('/api/'+ VERSION_STR +'/text/ldt/delete/', {'id':'1'}) -# #annot4 = delete_annotation('f2c1d1fa-629d-4520-a3d2-955b4f2582c0') -# self.assertEqual(response.status_code,'404') + def test_error_delete(self): + response = self.c.post('/api/'+ VERSION_STR +'/text/ldt/delete/', {'id':'1'}) + self.assertEqual(response.status_code,404) # This test creates an annotation, then updates it with new content, and checks that the returned xml contains the updated data @@ -170,14 +165,14 @@ content = base64.urlsafe_b64encode('tag1tag2newtag3#DDDDDDoaubert80cd0532-1dda-4130-b351-6a181130a7c92010-11-06 12:33:53.420459') response = self.c.post('/api/'+ VERSION_STR +'/text/update/', {'content':content,'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'}) doc = lxml.etree.fromstring(response.content) - self.assertEqual(doc.xpath("/iri/text-annotation/id/text()")[0],"d2c1d1fa-629d-4520-a3d2-955b4f2582c0") + self.assertEqual(lxml.etree.tostring(doc), " ") + self.assertEqual(doc.xpath("/iri/text-annotation/id/text()"),"d2c1d1fa-629d-4520-a3d2-955b4f2582c0") self.assertEqual(doc.xpath("/iri/text-annotation/tags/tag/text()")[1], "mytag") self.assertEqual(doc.xpath("/iri/text-annotation/content/color/text()")[0],"#DDDDDD") -# def test_error_update(self): -# content = base64.urlsafe_b64encode('d2c1d1fa-629d-4520-a3d2-955b4f2582c0http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168tag1tag2#AAAAAA<![CDATA[titre de l\'annotation]]>oaubert79cd0532-1dda-4130-b351-6a181130a7c92010-09-06 12:33:53.417550oaubert79cd0532-1dda-4130-b351-6a181130a7c92010-09-06 12:33:53.420459') -# response = self.c.post('/api/'+ VERSION_STR +'/text/update/', {'content':content,'id':'1'}) -# #annot5=update_annotation() -# self.assertEqual(response.status_code,'404') -# + def test_error_update(self): + content = base64.urlsafe_b64encode('d2c1d1fa-629d-4520-a3d2-955b4f2582c0http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168tag1tag2#AAAAAA<![CDATA[titre de l\'annotation]]>oaubert79cd0532-1dda-4130-b351-6a181130a7c92010-09-06 12:33:53.417550oaubert79cd0532-1dda-4130-b351-6a181130a7c92010-09-06 12:33:53.420459') + response = self.c.post('/api/'+ VERSION_STR +'/text/update/', {'content':content,'id':'1'}) + self.assertEqual(response.status_code,404) + diff -r 22ab430e9b64 -r 000f3ca19eaa web/ldt/text/views.py --- a/web/ldt/text/views.py Tue Nov 16 14:15:07 2010 +0100 +++ b/web/ldt/text/views.py Tue Nov 16 15:35:12 2010 +0100 @@ -100,7 +100,7 @@ ## Returns an xml-structured annotation #@login_required def create_annotation(request, content): - cont = base64.urlsafe_b64decode(request.POST["content"]) + cont = base64.urlsafe_b64decode(str(request.POST["content"])) doc = lxml.etree.fromstring(cont) id = unicode(doc.xpath("/iri/text-annotation/id/text()")[0]) @@ -128,10 +128,10 @@ annotation.save() return HttpResponse(lxml.etree.tostring(doc, pretty_print=True), mimetype="text/xml;charset=utf-8") #return doc - except: + except IntegrityError: #except Annotation.IntegrityError: #print 'This id is already used! Please choose another one!' - raise CONFLICT + return HttpResponse(status=409) @@ -211,7 +211,7 @@ except: raise Http404 - cont = base64.urlsafe_b64decode(request.POST["content"]) + cont = base64.urlsafe_b64decode(str(request.POST["content"])) doc = lxml.etree.fromstring(cont) uri = doc.xpath("/iri/text-annotation/uri/text()") diff -r 22ab430e9b64 -r 000f3ca19eaa web/leezam/templates/404.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/leezam/templates/404.html Tue Nov 16 15:35:12 2010 +0100 @@ -0,0 +1,1 @@ +

Not found

\ No newline at end of file diff -r 22ab430e9b64 -r 000f3ca19eaa web/leezam/urls.py --- a/web/leezam/urls.py Tue Nov 16 14:15:07 2010 +0100 +++ b/web/leezam/urls.py Tue Nov 16 15:35:12 2010 +0100 @@ -1,4 +1,4 @@ -from django.conf.urls.defaults import * +from django.conf.urls.defaults import patterns ,include, url, handler500, handler404 from django.contrib import admin from ldt.text import VERSION_STR