web/ldt/text/tests.py
changeset 10 000f3ca19eaa
parent 9 22ab430e9b64
child 16 d0f617472760
equal deleted inserted replaced
9:22ab430e9b64 10:000f3ca19eaa
    44         self.assertEqual(annot.uri, "http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168")
    44         self.assertEqual(annot.uri, "http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168")
    45         
    45         
    46 #    def test_error_create(self):
    46 #    def test_error_create(self):
    47 #        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>')
    47 #        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>')
    48 #        response = self.c.post('/api/'+ VERSION_STR +'/text/create/', {'content':content})
    48 #        response = self.c.post('/api/'+ VERSION_STR +'/text/create/', {'content':content})
    49 #        #annot2 = create_annotation(content)
    49 #        self.assertEqual(response.status_code, 409)
    50 #        self.assertEqual(response.status_code, '409')
       
    51 
    50 
    52 
    51 
    53 # This test creates an annotation, then gets it, and checks that the returned xml contains correct data
    52 # This test creates an annotation, then gets it, and checks that the returned xml contains correct data
    54 class GetTest(unittest.TestCase):
    53 class GetTest(unittest.TestCase):
    55     def setUp(self):
    54     def setUp(self):
    67         self.assertEqual(self.annot1.xpath("/iri/text-annotation/id/text()")[0],self.annotation.external_id)
    66         self.assertEqual(self.annot1.xpath("/iri/text-annotation/id/text()")[0],self.annotation.external_id)
    68         self.assertEqual(self.annot1.xpath("/iri/text-annotation/tags/tag/text()")[1], self.annotation.tags[1])
    67         self.assertEqual(self.annot1.xpath("/iri/text-annotation/tags/tag/text()")[1], self.annotation.tags[1])
    69         self.assertEqual(self.annot1.xpath("/iri/text-annotation/content/color/text()")[0],self.annotation.color)
    68         self.assertEqual(self.annot1.xpath("/iri/text-annotation/content/color/text()")[0],self.annotation.color)
    70         self.assertEqual(self.annot1.xpath("/iri/text-annotation/meta/created/text()")[0], str(self.annotation.creation_date))
    69         self.assertEqual(self.annot1.xpath("/iri/text-annotation/meta/created/text()")[0], str(self.annotation.creation_date))
    71 
    70 
    72 #    def test_error_get(self):
    71     def test_error_get(self):
    73 #        response = self.c.get('/api/'+ VERSION_STR +'/text/get/', {'id':'2'})
    72         response = self.c.get('/api/'+ VERSION_STR +'/text/get/', {'id':'2'})
    74 #        #response = self.c.get('/api/'+ VERSION_STR +'/text/get/', {'id':'2'})
    73         self.assertEqual(response.status_code,404)
    75 #        #annot3 = get_annotation('d2c1d1fa-629d-4520-a3d2-955b4f2582c0')
       
    76 #        #resp = response.status_code
       
    77 #        self.assertEqual(response.status_code,'404')
       
    78         
    74         
    79         
    75         
    80 class FilterTest(unittest.TestCase):
    76 class FilterTest(unittest.TestCase):
    81     def setUp(self):
    77     def setUp(self):
    82         self.annotation = Annotation(external_id="k2c1d1fa-629d-4520-a3d2-955b4f2582c0",title="titre de l\'annotation",text="texte selectionne lors de la creation de l\'annotation",color="#AAAAAA", uri="http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168", creator="wakimd")
    78         self.annotation = Annotation(external_id="k2c1d1fa-629d-4520-a3d2-955b4f2582c0",title="titre de l\'annotation",text="texte selectionne lors de la creation de l\'annotation",color="#AAAAAA", uri="http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168", creator="wakimd")
   139         for annot in annotlist:
   135         for annot in annotlist:
   140             annot.delete()
   136             annot.delete()
   141     
   137     
   142     def test_delete_annotation(self):
   138     def test_delete_annotation(self):
   143         response = self.c.post('/api/'+ VERSION_STR +'/text/delete/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
   139         response = self.c.post('/api/'+ VERSION_STR +'/text/delete/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
   144         #response2 = self.c.get('/ldt/get/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
   140         response2 = self.c.get('/ldt/get/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
   145         doc = lxml.etree.fromstring(response.content)
   141         doc = lxml.etree.fromstring(response.content)
   146         self.assertEqual(doc.xpath("/iri/text-annotation/id/text()"),[])
   142         self.assertEqual(doc.xpath("/iri/text-annotation/id/text()"),[])
   147         self.assertEqual(doc.xpath("/iri/text-annotation/tags/tag/text()"), [])
   143         self.assertEqual(doc.xpath("/iri/text-annotation/tags/tag/text()"), [])
   148         self.assertEqual(doc.xpath("/iri/text-annotation/content/color/text()"),[])
   144         self.assertEqual(doc.xpath("/iri/text-annotation/content/color/text()"),[])
   149         self.assertEqual(doc.xpath("/iri/text-annotation/meta/creator/text()"),[])
   145         self.assertEqual(doc.xpath("/iri/text-annotation/meta/creator/text()"),[])
   150         #self.assertEqual(response2.status_code, '404')   
   146         self.assertEqual(response2.status_code, 404)   
   151 
   147 
   152 #    def test_error_delete(self):
   148     def test_error_delete(self):
   153 #        response = self.c.post('/api/'+ VERSION_STR +'/text/ldt/delete/', {'id':'1'})
   149         response = self.c.post('/api/'+ VERSION_STR +'/text/ldt/delete/', {'id':'1'})
   154 #        #annot4 = delete_annotation('f2c1d1fa-629d-4520-a3d2-955b4f2582c0')
   150         self.assertEqual(response.status_code,404)
   155 #        self.assertEqual(response.status_code,'404')
       
   156         
   151         
   157 
   152 
   158 # This test creates an annotation, then updates it with new content, and checks that the returned xml contains the updated data
   153 # This test creates an annotation, then updates it with new content, and checks that the returned xml contains the updated data
   159 class UpdateTest(unittest.TestCase):
   154 class UpdateTest(unittest.TestCase):
   160     def setUp(self):
   155     def setUp(self):
   168             
   163             
   169     def test_update_annotation(self):
   164     def test_update_annotation(self):
   170         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>')
   165         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>')
   171         response = self.c.post('/api/'+ VERSION_STR +'/text/update/', {'content':content,'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
   166         response = self.c.post('/api/'+ VERSION_STR +'/text/update/', {'content':content,'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
   172         doc = lxml.etree.fromstring(response.content)
   167         doc = lxml.etree.fromstring(response.content)
   173         self.assertEqual(doc.xpath("/iri/text-annotation/id/text()")[0],"d2c1d1fa-629d-4520-a3d2-955b4f2582c0")
   168         self.assertEqual(lxml.etree.tostring(doc), " ")
       
   169         self.assertEqual(doc.xpath("/iri/text-annotation/id/text()"),"d2c1d1fa-629d-4520-a3d2-955b4f2582c0")
   174         self.assertEqual(doc.xpath("/iri/text-annotation/tags/tag/text()")[1], "mytag")
   170         self.assertEqual(doc.xpath("/iri/text-annotation/tags/tag/text()")[1], "mytag")
   175         self.assertEqual(doc.xpath("/iri/text-annotation/content/color/text()")[0],"#DDDDDD")
   171         self.assertEqual(doc.xpath("/iri/text-annotation/content/color/text()")[0],"#DDDDDD")
   176         
   172         
   177 #    def test_error_update(self):
   173     def test_error_update(self):
   178 #        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>')
   174         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>')
   179 #        response = self.c.post('/api/'+ VERSION_STR +'/text/update/', {'content':content,'id':'1'})
   175         response = self.c.post('/api/'+ VERSION_STR +'/text/update/', {'content':content,'id':'1'})
   180 #        #annot5=update_annotation()
   176         self.assertEqual(response.status_code,404)
   181 #        self.assertEqual(response.status_code,'404')
   177                
   182 #               
       
   183 
   178