diff -r 37e051f2264d -r d0f617472760 web/ldt/text/tests.py --- a/web/ldt/text/tests.py Wed Nov 17 10:28:55 2010 +0100 +++ b/web/ldt/text/tests.py Wed Nov 17 18:57:34 2010 +0100 @@ -8,7 +8,7 @@ from ldt.text.models import * from ldt.core.models import Owner from views import * -import base64 +import urllib import uuid import tempfile import datetime @@ -23,7 +23,7 @@ # 2. the returned xml contains correct data class CreateTest(unittest.TestCase): def setUp(self): - self.content = base64.urlsafe_b64encode('f2c1d1fa-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') + self.content = str('f2c1d1fa-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') self.c = Client() self.annot = Annotation(external_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() @@ -34,19 +34,21 @@ def test_create_annotation(self): response = self.c.post('/api/'+ VERSION_STR +'/text/create/', {'content':self.content}) + #self.assertEqual(response.content, " ") self.annot1 = lxml.etree.fromstring(response.content) 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") self.assertEqual(self.annot1.xpath("/iri/text-annotation/content/text/text()")[0],u"texte selectionne lors de la creation de l\'annotation") self.assertEqual(self.annot1.xpath("/iri/text-annotation/meta/created/text()")[0],"2010-09-06 12:33:53.417550") - annot = Annotation.objects.get(external_id="f2c1d1fa-629d-4520-a3d2-955b4f2582c0") - self.assertEqual(annot.uri, "http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168") + response2 = self.c.get('/api/'+ VERSION_STR +'/text/get/', {'id':'f2c1d1fa-629d-4520-a3d2-955b4f2582c0'}) + annot2 = lxml.etree.fromstring(response.content) + self.assertEqual(annot2.xpath("/iri/text-annotation/uri/text()")[0], "http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168") -# 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}) -# self.assertEqual(response.status_code, 409) + def test_error_create(self): + content = '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}) + self.assertEqual(response.status_code, 409) # This test creates an annotation, then gets it, and checks that the returned xml contains correct data @@ -136,6 +138,8 @@ annot.delete() def test_delete_annotation(self): + id = urllib.urlencode({'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'}) + f = urllib.urlopen("http://127.0.0.1:8000/api/1.0/text/delete/", id) 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'}) doc = lxml.etree.fromstring(response.content) @@ -162,17 +166,45 @@ annot.delete() def test_update_annotation(self): - 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'}) + content = '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(lxml.etree.tostring(doc), " ") - self.assertEqual(doc.xpath("/iri/text-annotation/id/text()"),"d2c1d1fa-629d-4520-a3d2-955b4f2582c0") + #self.assertEqual(lxml.etree.tostring(doc), " ") + 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") 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') + content = '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) +class OnServerGlobalTest(unittest.TestCase): + def setUp(self): + self.content = urllib.urlencode({'content':'mypersonnalidhttp://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'}) + self.content2 = urllib.urlencode({'content':'mypersonnalid2http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168tag1tag2#BBBBBB<![CDATA[titre de l\'annotation2]]>wakimd79cd0532-1dda-4130-b351-6a181130a7c92010-09-06 12:33:53.417550oaubert79cd0532-1dda-4130-b351-6a181130a7c92010-09-06 12:33:53.420459'}) + self.id = urllib.urlencode({"id":"mypersonnalid"}) + self.id2 = urllib.urlencode({"id":"mypersonnalid2"}) + self.uri = urllib.urlencode({"uri":"http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168"}) + self.filt1 = urllib.urlencode({"uri":"http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168", "creator":"","limit":"","filter":""}) + self.filt2 = urllib.urlencode({"uri":"http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168","creator":"wakimd","limit":"","filter":""}) + self.up = urllib.urlencode({'content':'tag1tag2newtag3#DDDDDDoaubert80cd0532-1dda-4130-b351-6a181130a7c92010-11-06 12:33:53.420459','id':'mypersonnalid'}) + + def test_everything(self): + creation = urllib.urlopen("http://127.0.0.1:8000/api/"+VERSION_STR+"/text/create/", self.content) + creation2 = urllib.urlopen("http://127.0.0.1:8000/api/"+VERSION_STR+"/text/create/", self.content2) + + get = urllib.urlopen("http://127.0.0.1:8000/api/"+VERSION_STR+"/text/get/?%s" % self.id) + + update = urllib.urlopen("http://127.0.0.1:8000/api/"+VERSION_STR+"/text/update/", self.up) + + filt1 = urllib.urlopen("http://127.0.0.1:8000/api/"+VERSION_STR+"/text/filter/?%s", self.uri) + filt2 = urllib.urlopen("http://127.0.0.1:8000/api/"+VERSION_STR+"/text/filter/?uri=http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168?creator=wakimd") + tmp = open('debug.html','r+') + tmp.write(filt2.read()) + + delete = urllib.urlopen("http://127.0.0.1:8000/api/"+VERSION_STR+"/text/delete/", self.id) + delete = urllib.urlopen("http://127.0.0.1:8000/api/"+VERSION_STR+"/text/delete/", self.id2) + + \ No newline at end of file