web/ldt/ldt_utils/tests.py
changeset 2 59311c28454f
parent 1 3a30d255c235
child 6 4d17de9ee64e
--- a/web/ldt/ldt_utils/tests.py	Sun Nov 14 20:25:22 2010 +0100
+++ b/web/ldt/ldt_utils/tests.py	Mon Nov 15 18:56:22 2010 +0100
@@ -23,17 +23,18 @@
 # 2. the returned xml contains correct data
 class CreateTest(unittest.TestCase):
     def setUp(self):
-        self.content = base64.urlsafe_b64encode('<iri><text-annotation><id>f2c1d1fa-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>')
+        self.content = base64.urlsafe_b64encode('<iri><text-annotation><id>f2c1d1fa-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>')
         self.c = Client()
+        self.annot = Annotation(id=u'd2c1d1fa-629d-4520-a3d2-955b4f2582c0', uri=u'http://iri.blabla', tags=[u'tag1',u'tag2'], title=u'montitre', description=u'madesc', text=u'letexteselectionne', color=u'#AAAAAA', creator=u'wakimd', contributor=u'wakimd', creation_date=u'2010-09-06 12:33:53.417550', update_date=u'2010-09-06 12:33:53.417550')
+        self.annot.save()
     def tearDown(self):
         annotlist=Annotation.objects.all()
         for annot in annotlist:
             annot.delete()
 
     def test_create_annotation(self):
-        response = self.c.post('/create/', {'content':self.content})
+        response = self.c.post('/ldt/create/', {'content':self.content})
         self.annot1 = lxml.etree.fromstring(response.content)
-        #self.assertEqual(lxml.etree.tostring(self.annot1),"lala")
         self.assertEqual(self.annot1.xpath("/iri/text-annotation/id/text()")[0],"f2c1d1fa-629d-4520-a3d2-955b4f2582c0")
         self.assertEqual(self.annot1.xpath("/iri/text-annotation/content")[0].tag,"content")
         self.assertEqual(self.annot1.xpath("/iri/text-annotation/tags/tag/text()")[0],"tag1")
@@ -41,28 +42,41 @@
         self.assertEqual(self.annot1.xpath("/iri/text-annotation/meta/created/text()")[0],"2010-09-06 12:33:53.417550")
         annot = Annotation.objects.get(id="f2c1d1fa-629d-4520-a3d2-955b4f2582c0")
         self.assertEqual(annot.uri, "http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168")
+        
+#    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('/ldt/create/', {'content':content})
+#        #annot2 = create_annotation(content)
+#        self.assertEqual(response.status_code, '409')
 
 
 # This test creates an annotation, then gets it, and checks that the returned xml contains correct data
 class GetTest(unittest.TestCase):
     def setUp(self):
-        self.annotation = Annotation(id="d2c1d1fa-629d-4520-a3d2-955b4f2582c0", tags=[u"tag1",u"tag2",u"tag3"], title="titre de l\'annotation",text="texte selectionne lors de la creation de l\'annotation",color="#AAAAAA", creation_date="2010-09-06T12:33:53.417550", update_date="2010-09-06T12:33:53.420459")
+        self.annotation = Annotation(id="d2c1d1fa-629d-4520-a3d2-955b4f2582c0", tags=[u"tag1",u"tag2",u"tag3"], title="titre de l\'annotation",text="texte selectionne lors de la creation de l\'annotation",color="#AAAAAA", creation_date="2010-09-06 12:33:53.417550", update_date="2010-09-06 12:33:53.420459")
         self.annotation.save()
+        self.c = Client()
     def tearDown(self):
         annotlist=Annotation.objects.all()
         for annot in annotlist:
             annot.delete()
       
     def test_get_annotation(self):
-        response = self.c.get('/get/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
+        response = self.c.get('/ldt/get/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
         self.annot1 = lxml.etree.fromstring(response.content)
         #self.annot1 = get_annotation("d2c1d1fa-629d-4520-a3d2-955b4f2582c0")
-        #self.assertEqual(lxml.etree.tostring(self.annot1),"lala")
         self.assertEqual(self.annot1.xpath("/iri/text-annotation/id/text()")[0],self.annotation.id)
         self.assertEqual(self.annot1.xpath("/iri/text-annotation/tags/tag/text()")[1], self.annotation.tags[1])
         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()"), self.annotation.creation_date)
 
+#    def test_error_get(self):
+#        response = self.c.get('/ldt/get/', {'id':'2'})
+#        #response = self.c.get('/ldt/get/', {'id':'2'})
+#        #annot3 = get_annotation('d2c1d1fa-629d-4520-a3d2-955b4f2582c0')
+#        #resp = response.status_code
+#        self.assertEqual(response.status_code,'404')
+        
         
 class FilterTest(unittest.TestCase):
     def setUp(self):
@@ -71,40 +85,45 @@
         self.annotation2 = Annotation(id="l2c1d1fa-629d-4520-a3d2-955b4f2582c0",title="titre de l\'annotation2",text="texte selectionne lors de la creation de l\'annotation2",color="#BBBBBB", uri="http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168", creator="wakimd")
         self.annotation2.save()
         self.annotation3 = Annotation(id="m2c1d1fa-629d-4520-a3d2-955b4f2582c0", title="titre3", text="texte3", color="#CCCCCC", uri="http://blabla", creator="wakimd")
-        self.annotation3.save()        
+        self.annotation3.save() 
+        self.c = Client()       
     def tearDown(self):
         annotlist=Annotation.objects.all()
         for annot in annotlist:
             annot.delete()
         
-    def test_filter_annotation_creator(self):
+    def test_filter_annotation_creator_limit(self):
         user = 'wakimd'
-        uri = None
-        limit= 2
-        doc = filter_annotation(uri,None,limit,user)
+        uri = "http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168"
+        limit= 1
+        response = self.c.get('/ldt/filter/', {'uri':uri,'creator':user,'limit':limit})
+        doc = lxml.etree.fromstring(response.content)
+        #doc = filter_annotation(uri,None,limit,user)
         cpt = 0
         for elem in doc.xpath("/iri/text-annotation"):
             cpt = cpt + 1
-        #self.assertEqual(lxml.etree.tostring(doc),"lala")
         if limit is not None:
             self.assertEqual(cpt,limit)
         for elem in doc.xpath("/iri/text-annotation/meta/creator/text()"):
             self.assertEqual(elem,user)
+        for elem in doc.xpath("/iri/text-annotation/uri/text()"):
+            self.assertEqual(elem[:57],"http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml")
         
     def test_filter_annotation_uri(self):
         uri = "http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168"
-        limit = None
-        doc = filter_annotation(uri,None,limit,None)
+        response = self.c.get('/ldt/filter/', {'uri':uri})
+        doc = lxml.etree.fromstring(response.content)
+        #doc = filter_annotation(uri,None,limit,None)
         for elem in doc.xpath("/iri/text-annotation/uri/text()"):
             self.assertEqual(elem[:57],"http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml")
             
     def test_filter_annotation_filter(self):
-        user = 'wakimd'
-        uri = None
+        uri = "http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168"
         filter = 'lors'
         limit = None
-        doc = filter_annotation(uri,filter,limit,user)
-        #self.assertEqual(lxml.etree.tostring(doc),"lala")
+        response = self.c.get('/ldt/filter/', {'uri':uri,'filter':'lors'})
+        doc = lxml.etree.fromstring(response.content)
+        #doc = filter_annotation(uri,filter,limit,user)
         for elem in doc.xpath("/iri/text-annotation/content/text/text()"):
             self.assertTrue('lors' in elem)  
         for elem in doc.xpath("/iri/text-annotation/meta/creator/text()"):
@@ -117,29 +136,36 @@
 class DeleteTest(unittest.TestCase):
     def setUp(self):
         self.annotation = Annotation(id="d2c1d1fa-629d-4520-a3d2-955b4f2582c0",title="titre de l\'annotation",text="texte selectionne lors de la creation de l\'annotation",color="#AAAAAA", creation_date="2010-09-06T12:33:53.417550", update_date="2010-09-06T12:33:53.420459")
-        self.annotation.save()    
+        self.annotation.save()
+        self.c = Client()    
     def tearDown(self):
         annotlist=Annotation.objects.all()
         for annot in annotlist:
             annot.delete()
     
     def test_delete_annotation(self):
-        response = self.c.post('/delete/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
-        response2 - self.c.get('/get/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
+        response = self.c.post('/ldt/delete/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
+        #response2 = self.c.get('/ldt/get/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
         doc = lxml.etree.fromstring(response.content)
         #doc=delete_annotation("d2c1d1fa-629d-4520-a3d2-955b4f2582c0")
-        self.assertEqual(self.annot1.xpath("/iri/text-annotation/id/text()")[0],'')
-        self.assertEqual(self.annot1.xpath("/iri/text-annotation/tags/tag/text()")[1], '')
-        self.assertEqual(self.annot1.xpath("/iri/text-annotation/content/color/text()")[0],'')
-        self.assertEqual(self.annot1.xpath("/iri/text-annotation/meta/creator/text()")[0],'')
-        self.assertEqual(response2.status_code, '404')   
+        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')   
 
+#    def test_error_delete(self):
+#        response = self.c.post('/ldt/delete/', {'id':'1'})
+#        #annot4 = delete_annotation('f2c1d1fa-629d-4520-a3d2-955b4f2582c0')
+#        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
 class UpdateTest(unittest.TestCase):
     def setUp(self):
         self.annotation = Annotation(id="d2c1d1fa-629d-4520-a3d2-955b4f2582c0", tags=['tag1','mytag'],title="titre de l\'annotation",text="texte selectionne lors de la creation de l\'annotation",color="#AAAAAA", creation_date="2010-09-06T12:33:53.417550", update_date="2010-09-06T12:33:53.420459")
         self.annotation.save()
+        self.c = Client()
     def tearDown(self):
         annotlist=Annotation.objects.all()
         for annot in annotlist:
@@ -147,60 +173,17 @@
             
     def test_update_annotation(self):
         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('/update/', {'content':content,'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
+        response = self.c.post('/ldt/update/', {'content':content,'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
         doc = lxml.etree.fromstring(response.content)
         #doc = update_annotation(content,'d2c1d1fa-629d-4520-a3d2-955b4f2582c0')
-        #self.assertEqual(lxml.etree.tostring(doc),"lala")
         self.assertEqual(doc.xpath("/iri/text-annotation/id/text()")[0],"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")
-               
-                
-#class AnnotTest(unittest.TestCase):
-#    def setUp(self):
-#        self.annot = Annotation(id=u'd2c1d1fa-629d-4520-a3d2-955b4f2582c0', uri=u'http://iri.blabla', tags=[u'tag1',u'tag2'], title=u'montitre', description=u'madesc', text=u'letexteselectionne', color=u'#AAAAAA', creator=u'wakimd', contributor=u'wakimd', creation_date=u'2010-09-06 12:33:53.417550', update_date=u'2010-09-06 12:33:53.417550')
-#        self.annot.save()       
-#    def tearDown(self):
-#        annotlist=Annotation.objects.all()
-#        for annot in annotlist:
-#            annot.delete()
-#  
-#    def test_create_annotation(self):
-#        b = Annotation.objects.get(id=u'd2c1d1fa-629d-4520-a3d2-955b4f2582c0')
-#        self.assertEqual(b.title, 'montitre')
-#            
+        
+#    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('/update/', {'content':content,'id':'1'})
+#        #annot5=update_annotation()
+#        self.assertEqual(response.status_code,'404')
+#               
 
-# These tests check common error codes are raised when needed
-class ErrorTest(unittest.TestCase):
-    def setUp(self):
-        self.annot = Annotation(id=u'd2c1d1fa-629d-4520-a3d2-955b4f2582c0', uri=u'http://iri.blabla', tags=[u'tag1',u'tag2'], title=u'montitre', description=u'madesc', text=u'letexteselectionne', color=u'#AAAAAA', creator=u'wakimd', contributor=u'wakimd', creation_date=u'2010-09-06 12:33:53.417550', update_date=u'2010-09-06 12:33:53.417550')
-        self.annot.save()
-    
-    def tearDown(self):
-        annotlist=Annotation.objects.all()
-        for annot in annotlist:
-            annot.delete()
-
-    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('/create/', {'content':self.content})
-        #annot2 = create_annotation(content)
-        self.assertEqual(response.status_code, '409')
-        
-    def test_error_get(self):
-        response = self.c.get('/get/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
-        #annot3 = get_annotation('d2c1d1fa-629d-4520-a3d2-955b4f2582c0')
-        resp = response.status_code
-        self.assertEqual(response.status_code,'404')
-
-    def test_error_delete(self):
-        response = self.c.post('/delete/', {'id':'f2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
-        #annot4 = delete_annotation('f2c1d1fa-629d-4520-a3d2-955b4f2582c0')
-        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('/update/', {'content':content,'id':'dfc1d1fa-629d-4520-a3d2-955b4f2582c0'})
-        #annot5=update_annotation()
-        self.assertEqual(response.status_code,'404')
-