|
9
|
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". |
|
1
|
4 |
|
|
9
|
5 |
Replace these with more appropriate tests for your application. |
|
|
6 |
""" |
|
1
|
7 |
|
|
|
8 |
from django.test import TestCase |
|
|
9 |
import unittest |
|
|
10 |
import lxml.etree |
|
9
|
11 |
from models import Project, Content |
|
1
|
12 |
from ldt.core.models import Owner |
|
9
|
13 |
from utils import LdtUtils, LdtSearch, create_ldt, create_empty_iri, copy_ldt |
|
1
|
14 |
import base64 |
|
|
15 |
import uuid |
|
|
16 |
import tempfile |
|
|
17 |
from django.contrib.auth.models import * |
|
9
|
18 |
from views import get_attrib |
|
1
|
19 |
from django.conf import settings |
|
9
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
|
23 |
class SimpleTest(TestCase): |
|
|
24 |
def test_basic_addition(self): |
|
|
25 |
""" |
|
|
26 |
Tests that 1 + 1 always equals 2. |
|
|
27 |
""" |
|
|
28 |
self.failUnlessEqual(1 + 1, 2) |
|
|
29 |
|
|
|
30 |
__test__ = {"doctest": """ |
|
|
31 |
Another way to test that 1 + 1 is equal to 2. |
|
|
32 |
|
|
|
33 |
>>> 1 + 1 == 2 |
|
|
34 |
True |
|
|
35 |
"""} |
|
1
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
9
|
39 |
class UtilsTest(unittest.TestCase): |
|
1
|
40 |
def setUp(self): |
|
9
|
41 |
self.user = Owner() |
|
|
42 |
self.user.username = "toto" |
|
|
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 |
|
|
1
|
54 |
def tearDown(self): |
|
9
|
55 |
self.project.delete() |
|
|
56 |
self.projectcopy.delete() |
|
|
57 |
#self.cont1.delete() |
|
|
58 |
#self.cont2.delete() |
|
|
59 |
|
|
|
60 |
def test_generate_ldt(self): |
|
|
61 |
self.cont1 = Content(iriurl="id1/iriurl1") |
|
|
62 |
self.cont1.iri_id = "id1" |
|
|
63 |
self.cont1.save() |
|
|
64 |
|
|
|
65 |
self.cont2 = Content(iriurl="id2/iriurl2") |
|
|
66 |
self.cont2.iri_id = "id2" |
|
|
67 |
self.cont2.save() |
|
|
68 |
|
|
|
69 |
self.project.contents.add(self.cont1,self.cont2) |
|
|
70 |
|
|
|
71 |
f=tempfile.TemporaryFile(mode='r+') |
|
|
72 |
self.LU.generateLdt(Content.objects.all(),f) |
|
|
73 |
f.seek(0) |
|
|
74 |
ldoc = lxml.etree.parse(f) |
|
|
75 |
self.assertEqual(ldoc.xpath("/iri/displays/display/content")[9].get("id"),self.cont2.iri_id) |
|
|
76 |
self.assertEqual(ldoc.xpath("/iri/medias/media")[8].get("id"), self.cont1.iri_id) |
|
|
77 |
f.close() |
|
|
78 |
|
|
|
79 |
def test_generate_init(self): |
|
|
80 |
self.cont3 = Content(iriurl="id3/iriurl1") |
|
|
81 |
self.cont3.iri_id = "id3" |
|
|
82 |
self.cont3.save() |
|
|
83 |
|
|
|
84 |
self.cont4 = Content(iriurl="id4/iriurl2") |
|
|
85 |
self.cont4.iri_id = "id4" |
|
|
86 |
self.cont4.save() |
|
|
87 |
|
|
|
88 |
self.project.contents.add(self.cont3,self.cont4) |
|
|
89 |
ldoc = self.LU.generateInit(None,None) |
|
|
90 |
self.assertEqual(ldoc.xpath("/iri/files/init")[0].tag, "init") |
|
|
91 |
self.assertEqual(ldoc.xpath("/iri/files/library")[0].tag, "library") |
|
|
92 |
self.assertEqual(ldoc.xpath("/iri/files/init/file")[0].get("video"), settings.STREAM_URL) |
|
1
|
93 |
|
|
9
|
94 |
def test_create_ldt(self): |
|
|
95 |
self.cont5 = Content(iriurl="id5/iriurl1") |
|
|
96 |
self.cont5.iri_id = "id5" |
|
|
97 |
self.cont5.save() |
|
|
98 |
|
|
|
99 |
self.cont6 = Content(iriurl="id6/iriurl2") |
|
|
100 |
self.cont6.iri_id = "id6" |
|
|
101 |
self.cont6.save() |
|
|
102 |
|
|
|
103 |
self.project.contents.add(self.cont5,self.cont6) |
|
|
104 |
self.project.ldt="" |
|
|
105 |
create_ldt(self.project, self.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() |
|
2
|
120 |
|
|
9
|
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 |
|
|
1
|
149 |
|
|
|
150 |
|
|
9
|
151 |
|
|
|
152 |
class ViewsTest(unittest.TestCase): |
|
1
|
153 |
def setUp(self): |
|
9
|
154 |
self.project = Project() |
|
|
155 |
self.project.id = "121" |
|
|
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() |
|
1
|
166 |
|
|
9
|
167 |
self.project.contents.add(self.cont1, self.cont2) |
|
1
|
168 |
|
|
|
169 |
def tearDown(self): |
|
9
|
170 |
self.project.delete() |
|
|
171 |
##self.cont1.delete() |
|
|
172 |
##self.cont2.delete() |
|
1
|
173 |
|
|
9
|
174 |
# def test_get_attrib(self): |
|
|
175 |
# get_attrib(self.project) |
|
|
176 |
# ldoc = lxml.etree.fromstring(self.project.ldt) |
|
|
177 |
# self.assertEqual(self.project.title, ldoc.xpath("/iri/project")[0].get("title")) |
|
|
178 |
# self.assertEqual(ldoc.xpath("/iri/medias/media")[0].get('id'), self.cont1.iri_id) |
|
|
179 |
# self.assertTrue(self.cont2.iri_id not in self.project.contents.all()) |