1 #encoding:UTF-8 |
1 """ |
|
2 This file demonstrates two different styles of tests (one doctest and one |
|
3 unittest). These will both pass when you run "manage.py test". |
2 |
4 |
3 """ Run these tests with 'python manage.py test ldt_utils' """ |
5 Replace these with more appropriate tests for your application. |
|
6 """ |
4 |
7 |
5 from django.test import TestCase |
8 from django.test import TestCase |
6 import unittest |
9 import unittest |
7 import lxml.etree |
10 import lxml.etree |
8 from ldt.ldt_utils.models import * |
11 from models import Project, Content |
9 from ldt.core.models import Owner |
12 from ldt.core.models import Owner |
10 from views import * |
13 from utils import LdtUtils, LdtSearch, create_ldt, create_empty_iri, copy_ldt |
11 import base64 |
14 import base64 |
12 import uuid |
15 import uuid |
13 import tempfile |
16 import tempfile |
14 import datetime |
|
15 from django.contrib.auth.models import * |
17 from django.contrib.auth.models import * |
|
18 from views import get_attrib |
16 from django.conf import settings |
19 from django.conf import settings |
17 from django.test.client import Client |
|
18 from ldt.ldt_utils import VERSION_STR |
|
19 |
20 |
20 |
21 |
21 |
22 |
22 # This test creates an annotation and checks that: |
23 class SimpleTest(TestCase): |
23 # 1. the annotation was created in the database (by trying to access it through a 'get') |
24 def test_basic_addition(self): |
24 # 2. the returned xml contains correct data |
25 """ |
25 class CreateTest(unittest.TestCase): |
26 Tests that 1 + 1 always equals 2. |
26 def setUp(self): |
27 """ |
27 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>') |
28 self.failUnlessEqual(1 + 1, 2) |
28 self.c = Client() |
|
29 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') |
|
30 self.annot.save() |
|
31 def tearDown(self): |
|
32 annotlist=Annotation.objects.all() |
|
33 for annot in annotlist: |
|
34 annot.delete() |
|
35 |
29 |
36 def test_create_annotation(self): |
30 __test__ = {"doctest": """ |
37 response = self.c.post('/api/'+ VERSION_STR +'/text/create/', {'content':self.content}) |
31 Another way to test that 1 + 1 is equal to 2. |
38 self.annot1 = lxml.etree.fromstring(response.content) |
32 |
39 self.assertEqual(self.annot1.xpath("/iri/text-annotation/id/text()")[0],"f2c1d1fa-629d-4520-a3d2-955b4f2582c0") |
33 >>> 1 + 1 == 2 |
40 self.assertEqual(self.annot1.xpath("/iri/text-annotation/content")[0].tag,"content") |
34 True |
41 self.assertEqual(self.annot1.xpath("/iri/text-annotation/tags/tag/text()")[0],"tag1") |
35 """} |
42 self.assertEqual(self.annot1.xpath("/iri/text-annotation/content/text/text()")[0],u"texte selectionne lors de la creation de l\'annotation") |
|
43 self.assertEqual(self.annot1.xpath("/iri/text-annotation/meta/created/text()")[0],"2010-09-06 12:33:53.417550") |
|
44 annot = Annotation.objects.get(id="f2c1d1fa-629d-4520-a3d2-955b4f2582c0") |
|
45 self.assertEqual(annot.uri, "http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168") |
|
46 |
|
47 # def test_error_create(self): |
|
48 # 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>') |
|
49 # response = self.c.post('/api/'+ VERSION_STR +'/text/create/', {'content':content}) |
|
50 # #annot2 = create_annotation(content) |
|
51 # self.assertEqual(response.status_code, '409') |
|
52 |
36 |
53 |
37 |
54 # This test creates an annotation, then gets it, and checks that the returned xml contains correct data |
38 |
55 class GetTest(unittest.TestCase): |
39 class UtilsTest(unittest.TestCase): |
56 def setUp(self): |
40 def setUp(self): |
57 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") |
41 self.user = Owner() |
58 self.annotation.save() |
42 self.user.username = "toto" |
59 self.c = Client() |
43 self.LU = LdtUtils() |
|
44 |
|
45 self.project = Project(title="titleproj1", owner=self.user) |
|
46 self.project.ldt = '<iri ldtversion="1.0.3" xmlns:dc="http://dublincore.org/documents/dcmi-namespace/"><project id="af3b99e4-b695-11df-bfde-00145ea4a2be" user="admin" title="CA:reponse a TC" abstract=""/> <medias> <media extra="" id="laurentcantet_entrelesmurs" pict="" src="http://amateur.iri.centrepompidou.fr//atelier/static/media/ldt/laurentcantet_entrelesmurs/laurentcantet_entrelesmurs.iri" video="rtmp://media.iri.centrepompidou.fr/ddc_player/video/regardssignes/"/> </medias> <annotations> <content id="laurentcantet_entrelesmurs"> <ensemble id="ens_perso" idProject="fe0d5d4c-2201-11df-8a24-00145ea4a2be" title="Decoupages personnels" author="perso" abstract=""> <decoupage id="c_EFC3FFE7-0204-A086-EBEC-D2A03A0E56CB" author="perso"> <title>CA: prof et admin</title> <abstract/> <elements> <element id="s_442AAB3A-42DA-F9BF-75E7-D2A0663FD5FF" begin="985690" dur="373222" author="" date="2010/09/02" color="16711680" src=""> <title/> <abstract/> <audio source=""/> <tags/> </element> <element id="s_0050F043-3AD2-0A7C-6699-D2A03A1EBA02" begin="5052858" dur="124407" author="" date="2010/09/02" color="10053375" src=""> <title>conseil de classe</title> <abstract>Reprise de la figure precedente</abstract> <audio source="undefined"/> <tags/> </element> </elements> </decoupage> <decoupage id="c_EEEF5C29-86E1-4AAE-E068-04EB5B00E492" author="perso"> <title>TC: prof et admin</title> <abstract/> <elements> <element id="s_880D9D4B-8BC0-BA43-5ECA-04EBA9FC9E59" begin="2426894" dur="141478" author="" date="2010/02/25" color="10053375" src=""> <title>Conseil de classe</title> <abstract/> <audio source=""/> <tags> <tag>Argumentation</tag> </tags> </element> <element id="s_D568A57C-7110-DED2-3165-04EC54387060" begin="5052858" dur="124407" author="" date="2010/02/25" color="10053375" src=""> <title>conseil de classe</title> <abstract>Reprise de la figure precedente</abstract> <audio source="undefined"/> <tags/> </element> </elements> </decoupage> </ensemble> </content> </annotations> <displays> <display id="0" title="Init view" idsel="laurentcantet_entrelesmurs" tc="2426424" zoom="0" scroll="0" infoBAB=""> <audio source=""/> <content id="laurentcantet_entrelesmurs"> <decoupage idens="en_2" id="de_PPP" tagsSelect=""/> <decoupage idens="laurentcantet_entrelesmurs" id="c_14A2E638-1936-97DC-E303-2DBA6A82A8B3" tagsSelect=""/> <decoupage idens="ens_perso" id="c_EEEF5C29-86E1-4AAE-E068-04EB5B00E492" tagsSelect=""/> <decoupage idens="ens_perso" id="c_EFC3FFE7-0204-A086-EBEC-D2A03A0E56CB" tagsSelect=""/> </content> </display> </displays> <edits> <editing id="0" tags=""> <title>Bout a bout 1</title> <abstract/> <edit id="edit1" tags=""> <eList/> <caption/> <audio/> <mList/> </edit> <edit id="edit2" tags=""> <eList/> <caption/> <audio/> <mList/> </edit> </editing> </edits> </iri>' |
|
47 self.project.id = "11" |
|
48 self.project.ldt_id = str(uuid.uuid1()) |
|
49 self.project.save() |
|
50 |
|
51 self.projectcopy = Project(title="the2ndproject") |
|
52 self.projectcopy.id="22" |
|
53 |
60 def tearDown(self): |
54 def tearDown(self): |
61 annotlist=Annotation.objects.all() |
55 self.project.delete() |
62 for annot in annotlist: |
56 self.projectcopy.delete() |
63 annot.delete() |
57 #self.cont1.delete() |
64 |
58 #self.cont2.delete() |
65 def test_get_annotation(self): |
|
66 response = self.c.get('/api/'+ VERSION_STR +'/text/get/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'}) |
|
67 self.annot1 = lxml.etree.fromstring(response.content) |
|
68 #self.annot1 = get_annotation("d2c1d1fa-629d-4520-a3d2-955b4f2582c0") |
|
69 self.assertEqual(self.annot1.xpath("/iri/text-annotation/id/text()")[0],self.annotation.id) |
|
70 self.assertEqual(self.annot1.xpath("/iri/text-annotation/tags/tag/text()")[1], self.annotation.tags[1]) |
|
71 self.assertEqual(self.annot1.xpath("/iri/text-annotation/content/color/text()")[0],self.annotation.color) |
|
72 #self.assertEqual(self.annot1.xpath("/iri/text-annotation/meta/created/text()"), self.annotation.creation_date) |
|
73 |
59 |
74 # def test_error_get(self): |
60 def test_generate_ldt(self): |
75 # response = self.c.get('/api/'+ VERSION_STR +'/text/get/', {'id':'2'}) |
61 self.cont1 = Content(iriurl="id1/iriurl1") |
76 # #response = self.c.get('/api/'+ VERSION_STR +'/text/get/', {'id':'2'}) |
62 self.cont1.iri_id = "id1" |
77 # #annot3 = get_annotation('d2c1d1fa-629d-4520-a3d2-955b4f2582c0') |
63 self.cont1.save() |
78 # #resp = response.status_code |
|
79 # self.assertEqual(response.status_code,'404') |
|
80 |
64 |
|
65 self.cont2 = Content(iriurl="id2/iriurl2") |
|
66 self.cont2.iri_id = "id2" |
|
67 self.cont2.save() |
81 |
68 |
82 class FilterTest(unittest.TestCase): |
69 self.project.contents.add(self.cont1,self.cont2) |
83 def setUp(self): |
70 |
84 self.annotation = Annotation(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") |
71 f=tempfile.TemporaryFile(mode='r+') |
85 self.annotation.save() |
72 self.LU.generateLdt(Content.objects.all(),f) |
86 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") |
73 f.seek(0) |
87 self.annotation2.save() |
74 ldoc = lxml.etree.parse(f) |
88 self.annotation3 = Annotation(id="m2c1d1fa-629d-4520-a3d2-955b4f2582c0", title="titre3", text="texte3", color="#CCCCCC", uri="http://blabla", creator="wakimd") |
75 self.assertEqual(ldoc.xpath("/iri/displays/display/content")[9].get("id"),self.cont2.iri_id) |
89 self.annotation3.save() |
76 self.assertEqual(ldoc.xpath("/iri/medias/media")[8].get("id"), self.cont1.iri_id) |
90 self.c = Client() |
77 f.close() |
91 def tearDown(self): |
78 |
92 annotlist=Annotation.objects.all() |
79 def test_generate_init(self): |
93 for annot in annotlist: |
80 self.cont3 = Content(iriurl="id3/iriurl1") |
94 annot.delete() |
81 self.cont3.iri_id = "id3" |
|
82 self.cont3.save() |
95 |
83 |
96 def test_filter_annotation_creator_limit(self): |
84 self.cont4 = Content(iriurl="id4/iriurl2") |
97 user = 'wakimd' |
85 self.cont4.iri_id = "id4" |
98 uri = "http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168" |
86 self.cont4.save() |
99 limit= 1 |
|
100 response = self.c.get('/api/'+ VERSION_STR +'/text/filter/', {'uri':uri,'creator':user,'limit':limit}) |
|
101 doc = lxml.etree.fromstring(response.content) |
|
102 #doc = filter_annotation(uri,None,limit,user) |
|
103 cpt = 0 |
|
104 for elem in doc.xpath("/iri/text-annotation"): |
|
105 cpt = cpt + 1 |
|
106 if limit is not None: |
|
107 self.assertEqual(cpt,limit) |
|
108 for elem in doc.xpath("/iri/text-annotation/meta/creator/text()"): |
|
109 self.assertEqual(elem,user) |
|
110 for elem in doc.xpath("/iri/text-annotation/uri/text()"): |
|
111 self.assertEqual(elem[:57],"http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml") |
|
112 |
87 |
113 def test_filter_annotation_uri(self): |
88 self.project.contents.add(self.cont3,self.cont4) |
114 uri = "http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168" |
89 ldoc = self.LU.generateInit(None,None) |
115 response = self.c.get('/api/'+ VERSION_STR +'/text/filter/', {'uri':uri}) |
90 self.assertEqual(ldoc.xpath("/iri/files/init")[0].tag, "init") |
116 doc = lxml.etree.fromstring(response.content) |
91 self.assertEqual(ldoc.xpath("/iri/files/library")[0].tag, "library") |
117 #doc = filter_annotation(uri,None,limit,None) |
92 self.assertEqual(ldoc.xpath("/iri/files/init/file")[0].get("video"), settings.STREAM_URL) |
118 for elem in doc.xpath("/iri/text-annotation/uri/text()"): |
93 |
119 self.assertEqual(elem[:57],"http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml") |
94 def test_create_ldt(self): |
120 |
95 self.cont5 = Content(iriurl="id5/iriurl1") |
121 def test_filter_annotation_filter(self): |
96 self.cont5.iri_id = "id5" |
122 uri = "http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168" |
97 self.cont5.save() |
123 filter = 'lors' |
98 |
124 limit = None |
99 self.cont6 = Content(iriurl="id6/iriurl2") |
125 response = self.c.get('/api/'+ VERSION_STR +'/text/filter/', {'uri':uri,'filter':'lors'}) |
100 self.cont6.iri_id = "id6" |
126 doc = lxml.etree.fromstring(response.content) |
101 self.cont6.save() |
127 #doc = filter_annotation(uri,filter,limit,user) |
102 |
128 for elem in doc.xpath("/iri/text-annotation/content/text/text()"): |
103 self.project.contents.add(self.cont5,self.cont6) |
129 self.assertTrue('lors' in elem) |
104 self.project.ldt="" |
130 for elem in doc.xpath("/iri/text-annotation/meta/creator/text()"): |
105 create_ldt(self.project, self.user) |
131 self.assertEqual(elem,user) |
106 ldt = lxml.etree.fromstring(self.project.ldt) |
|
107 self.assertEqual(ldt.xpath("/iri")[0].tag,"iri") |
|
108 self.assertEqual(ldt.xpath("/iri/project")[0].get("title"), self.project.title) |
|
109 self.assertEqual(ldt.xpath("/iri/medias/media")[0].get("src"), self.cont5.iri_url()) |
|
110 self.assertEqual(ldt.xpath("/iri/medias/media")[1].get("id"), self.cont6.iri_id) |
|
111 |
|
112 def test_copy_ldt(self): |
|
113 self.cont7 = Content(iriurl="id7/iriurl1") |
|
114 self.cont7.iri_id = "id7" |
|
115 self.cont7.save() |
|
116 |
|
117 self.cont8 = Content(iriurl="id8/iriurl2") |
|
118 self.cont8.iri_id = "id8" |
|
119 self.cont8.save() |
|
120 |
|
121 self.project.contents.add(self.cont7,self.cont8) |
|
122 copy_ldt(self.project, self.projectcopy, self.user) |
|
123 ldt1=lxml.etree.fromstring(self.project.ldt) |
|
124 ldt2=lxml.etree.fromstring(self.projectcopy.ldt) |
|
125 self.assertTrue(ldt1.xpath("/iri/project")[0].get("id")!= ldt2.xpath("/iri/project")[0].get("id")) |
|
126 self.assertEqual(ldt1.xpath("/iri/medias/media")[0].get("id"),ldt2.xpath("/iri/medias/media")[0].get("id")) |
|
127 self.assertEqual(ldt1.xpath("/iri/annotations/content/ensemble")[0].get("title"),ldt2.xpath("/iri/annotations/content/ensemble")[0].get("title")) |
|
128 self.assertEqual(ldt1.xpath("/iri/annotations/content/ensemble/decoupage")[0].get("id"),ldt2.xpath("/iri/annotations/content/ensemble/decoupage")[0].get("id")) |
|
129 self.assertEqual(ldt1.xpath("/iri/annotations/content/ensemble/decoupage/title")[1].text,ldt2.xpath("/iri/annotations/content/ensemble/decoupage/title")[1].text.strip("\n\t")) |
|
130 |
|
131 def test_create_empty_iri(self): |
|
132 self.cont9 = Content(iriurl="id9/iriurl1") |
|
133 self.cont9.iri_id = "id9" |
|
134 self.cont9.save() |
|
135 |
|
136 self.cont10 = Content(iriurl="id10/iriurl2") |
|
137 self.cont10.iri_id = "id10" |
|
138 self.cont10.save() |
|
139 |
|
140 self.project.contents.add(self.cont9,self.cont10) |
|
141 tmp = tempfile.TemporaryFile(mode='r+') |
|
142 create_empty_iri(tmp, self.cont9, "admin") |
|
143 tmp.seek(0) |
|
144 ldoc = lxml.etree.parse(tmp) |
|
145 self.assertEqual(ldoc.xpath("/iri/head/meta")[0].get("content"), self.cont9.iri_id) |
|
146 self.assertEqual(ldoc.xpath("/iri/body/medias/media/video")[0].get("id"), self.cont9.iri_id) |
|
147 tmp.close() |
|
148 |
132 |
149 |
133 |
150 |
134 # This test creates an annotation, then deletes it, and checks that: |
151 |
135 # 1. the annotation doesn't exist anymore in the database (by trying to access it through a 'get') |
152 class ViewsTest(unittest.TestCase): |
136 # 2. the returned xml contains no data |
|
137 class DeleteTest(unittest.TestCase): |
|
138 def setUp(self): |
153 def setUp(self): |
139 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") |
154 self.project = Project() |
140 self.annotation.save() |
155 self.project.id = "121" |
141 self.c = Client() |
156 self.project.save() |
|
157 self.project.ldt = '<iri ldtversion="1.0.3" xmlns:dc="http://dublincore.org/documents/dcmi-namespace/"><project id="af3b99e4-b695-11df-bfde-00145ea4a2be" user="admin" title="CA:reponse a TC" abstract=""/> <medias> <media extra="" id="laurentcantet_entrelesmurs" pict="" src="http://amateur.iri.centrepompidou.fr//atelier/static/media/ldt/laurentcantet_entrelesmurs/laurentcantet_entrelesmurs.iri" video="rtmp://media.iri.centrepompidou.fr/ddc_player/video/regardssignes/"/> </medias> <annotations> <content id="laurentcantet_entrelesmurs"> <ensemble id="ens_perso" idProject="fe0d5d4c-2201-11df-8a24-00145ea4a2be" title="Decoupages personnels" author="perso" abstract=""> <decoupage id="c_EFC3FFE7-0204-A086-EBEC-D2A03A0E56CB" author="perso"> <title>CA: prof et admin</title> <abstract/> <elements> <element id="s_442AAB3A-42DA-F9BF-75E7-D2A0663FD5FF" begin="985690" dur="373222" author="" date="2010/09/02" color="16711680" src=""> <title/> <abstract/> <audio source=""/> <tags/> </element> <element id="s_0050F043-3AD2-0A7C-6699-D2A03A1EBA02" begin="5052858" dur="124407" author="" date="2010/09/02" color="10053375" src=""> <title>conseil de classe</title> <abstract>Reprise de la figure precedente</abstract> <audio source="undefined"/> <tags/> </element> </elements> </decoupage> <decoupage id="c_EEEF5C29-86E1-4AAE-E068-04EB5B00E492" author="perso"> <title>TC: prof et admin</title> <abstract/> <elements> <element id="s_880D9D4B-8BC0-BA43-5ECA-04EBA9FC9E59" begin="2426894" dur="141478" author="" date="2010/02/25" color="10053375" src=""> <title>Conseil de classe</title> <abstract/> <audio source=""/> <tags> <tag>Argumentation</tag> </tags> </element> <element id="s_D568A57C-7110-DED2-3165-04EC54387060" begin="5052858" dur="124407" author="" date="2010/02/25" color="10053375" src=""> <title>conseil de classe</title> <abstract>Reprise de la figure precedente</abstract> <audio source="undefined"/> <tags/> </element> </elements> </decoupage> </ensemble> </content> </annotations> <displays> <display id="0" title="Init view" idsel="laurentcantet_entrelesmurs" tc="2426424" zoom="0" scroll="0" infoBAB=""> <audio source=""/> <content id="laurentcantet_entrelesmurs"> <decoupage idens="en_2" id="de_PPP" tagsSelect=""/> <decoupage idens="laurentcantet_entrelesmurs" id="c_14A2E638-1936-97DC-E303-2DBA6A82A8B3" tagsSelect=""/> <decoupage idens="ens_perso" id="c_EEEF5C29-86E1-4AAE-E068-04EB5B00E492" tagsSelect=""/> <decoupage idens="ens_perso" id="c_EFC3FFE7-0204-A086-EBEC-D2A03A0E56CB" tagsSelect=""/> </content> </display> </displays> <edits> <editing id="0" tags=""> <title>Bout a bout 1</title> <abstract/> <edit id="edit1" tags=""> <eList/> <caption/> <audio/> <mList/> </edit> <edit id="edit2" tags=""> <eList/> <caption/> <audio/> <mList/> </edit> </editing> </edits> </iri>' |
|
158 |
|
159 self.cont1 = Content(iriurl="/laurentcantet_entrelesmurs/iriurl1") |
|
160 self.cont1.iri_id = 'laurentcantet_entrelesmurs' |
|
161 self.cont1.save() |
|
162 |
|
163 self.cont2 = Content(iriurl="/content_notinldt/iriurl2") |
|
164 self.cont2.iri_id = 'content_notinldt' |
|
165 self.cont2.save() |
|
166 |
|
167 self.project.contents.add(self.cont1, self.cont2) |
|
168 |
142 def tearDown(self): |
169 def tearDown(self): |
143 annotlist=Annotation.objects.all() |
170 self.project.delete() |
144 for annot in annotlist: |
171 ##self.cont1.delete() |
145 annot.delete() |
172 ##self.cont2.delete() |
146 |
|
147 def test_delete_annotation(self): |
|
148 response = self.c.post('/api/'+ VERSION_STR +'/text/delete/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'}) |
|
149 #response2 = self.c.get('/ldt/get/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'}) |
|
150 doc = lxml.etree.fromstring(response.content) |
|
151 #doc=delete_annotation("d2c1d1fa-629d-4520-a3d2-955b4f2582c0") |
|
152 self.assertEqual(doc.xpath("/iri/text-annotation/id/text()"),[]) |
|
153 self.assertEqual(doc.xpath("/iri/text-annotation/tags/tag/text()"), []) |
|
154 self.assertEqual(doc.xpath("/iri/text-annotation/content/color/text()"),[]) |
|
155 self.assertEqual(doc.xpath("/iri/text-annotation/meta/creator/text()"),[]) |
|
156 #self.assertEqual(response2.status_code, '404') |
|
157 |
173 |
158 # def test_error_delete(self): |
174 # def test_get_attrib(self): |
159 # response = self.c.post('/api/'+ VERSION_STR +'/text/ldt/delete/', {'id':'1'}) |
175 # get_attrib(self.project) |
160 # #annot4 = delete_annotation('f2c1d1fa-629d-4520-a3d2-955b4f2582c0') |
176 # ldoc = lxml.etree.fromstring(self.project.ldt) |
161 # self.assertEqual(response.status_code,'404') |
177 # self.assertEqual(self.project.title, ldoc.xpath("/iri/project")[0].get("title")) |
162 |
178 # self.assertEqual(ldoc.xpath("/iri/medias/media")[0].get('id'), self.cont1.iri_id) |
163 |
179 # self.assertTrue(self.cont2.iri_id not in self.project.contents.all()) |
164 # This test creates an annotation, then updates it with new content, and checks that the returned xml contains the updated data |
|
165 class UpdateTest(unittest.TestCase): |
|
166 def setUp(self): |
|
167 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") |
|
168 self.annotation.save() |
|
169 self.c = Client() |
|
170 def tearDown(self): |
|
171 annotlist=Annotation.objects.all() |
|
172 for annot in annotlist: |
|
173 annot.delete() |
|
174 |
|
175 def test_update_annotation(self): |
|
176 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>') |
|
177 response = self.c.post('/api/'+ VERSION_STR +'/text/update/', {'content':content,'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'}) |
|
178 doc = lxml.etree.fromstring(response.content) |
|
179 #doc = update_annotation(content,'d2c1d1fa-629d-4520-a3d2-955b4f2582c0') |
|
180 self.assertEqual(doc.xpath("/iri/text-annotation/id/text()")[0],"d2c1d1fa-629d-4520-a3d2-955b4f2582c0") |
|
181 self.assertEqual(doc.xpath("/iri/text-annotation/tags/tag/text()")[1], "mytag") |
|
182 self.assertEqual(doc.xpath("/iri/text-annotation/content/color/text()")[0],"#DDDDDD") |
|
183 |
|
184 # def test_error_update(self): |
|
185 # 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>') |
|
186 # response = self.c.post('/api/'+ VERSION_STR +'/text/update/', {'content':content,'id':'1'}) |
|
187 # #annot5=update_annotation() |
|
188 # self.assertEqual(response.status_code,'404') |
|
189 # |
|
190 |
|