Added 404 templates + some views corrections
authorwakimd
Tue, 16 Nov 2010 15:35:12 +0100
changeset 10 000f3ca19eaa
parent 9 22ab430e9b64
child 11 19bcbf2a2cfa
Added 404 templates + some views corrections
web/ldt/text/tests.py
web/ldt/text/views.py
web/leezam/templates/404.html
web/leezam/urls.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('<iri><text-annotation><id>d2c1d1fa-629d-4520-a3d2-955b4f2582c0</id><uri>http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168</uri><tags><tag>tag1</tag><tag>tag2</tag></tags><content><color>#AAAAAA</color><description><![CDATA[texte de description]]></description><title><![CDATA[titre de l\'annotation]]></title><text><![CDATA[texte selectionne lors de la creation de l\'annotation]]></text></content><meta><contributor>oaubert</contributor><contributor-id>79cd0532-1dda-4130-b351-6a181130a7c9</contributor-id><created>2010-09-06 12:33:53.417550</created><creator>oaubert</creator><creator-id>79cd0532-1dda-4130-b351-6a181130a7c9</creator-id><modified>2010-09-06 12:33:53.420459</modified></meta></text-annotation></iri>')
 #        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('<iri><text-annotation><id></id><uri></uri><tags><tag>tag1</tag><tag>tag2new</tag><tag>tag3</tag></tags><content><color>#DDDDDD</color><description><![CDATA[texte de description update]]></description><title></title><text><![CDATA[texte selectionne a nouveau lors de la creation de l\'annotation]]></text></content><meta><contributor>oaubert</contributor><contributor-id>80cd0532-1dda-4130-b351-6a181130a7c9</contributor-id><created></created><creator></creator><creator-id></creator-id><modified>2010-11-06 12:33:53.420459</modified></meta></text-annotation></iri>')
         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('<iri><text-annotation><id>d2c1d1fa-629d-4520-a3d2-955b4f2582c0</id><uri>http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168</uri><tags><tag>tag1</tag><tag>tag2</tag></tags><content><color>#AAAAAA</color><description><![CDATA[texte de description]]></description><title><![CDATA[titre de l\'annotation]]></title><text><![CDATA[texte selectionne lors de la creation de l\'annotation]]></text></content><meta><contributor>oaubert</contributor><contributor-id>79cd0532-1dda-4130-b351-6a181130a7c9</contributor-id><created>2010-09-06 12:33:53.417550</created><creator>oaubert</creator><creator-id>79cd0532-1dda-4130-b351-6a181130a7c9</creator-id><modified>2010-09-06 12:33:53.420459</modified></meta></text-annotation></iri>')
-#        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('<iri><text-annotation><id>d2c1d1fa-629d-4520-a3d2-955b4f2582c0</id><uri>http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168</uri><tags><tag>tag1</tag><tag>tag2</tag></tags><content><color>#AAAAAA</color><description><![CDATA[texte de description]]></description><title><![CDATA[titre de l\'annotation]]></title><text><![CDATA[texte selectionne lors de la creation de l\'annotation]]></text></content><meta><contributor>oaubert</contributor><contributor-id>79cd0532-1dda-4130-b351-6a181130a7c9</contributor-id><created>2010-09-06 12:33:53.417550</created><creator>oaubert</creator><creator-id>79cd0532-1dda-4130-b351-6a181130a7c9</creator-id><modified>2010-09-06 12:33:53.420459</modified></meta></text-annotation></iri>')
+        response = self.c.post('/api/'+ VERSION_STR +'/text/update/', {'content':content,'id':'1'})
+        self.assertEqual(response.status_code,404)
+               
 
--- 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()")
--- /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 @@
+<h1>Not found</h1>
\ No newline at end of file
--- 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