web/ldt/ldt_utils/tests.py
author ymh <ymh.work@gmail.com>
Fri, 15 Oct 2010 11:58:18 +0200
changeset 89 30c6e597a7de
parent 85 3b70d84e661a
permissions -rw-r--r--
correct project serializer and take into account the display + new version
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
"""
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
This file demonstrates two different styles of tests (one doctest and one
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
unittest). These will both pass when you run "manage.py test".
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
Replace these with more appropriate tests for your application.
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
"""
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
from django.test import TestCase
80
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
     9
import unittest
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
    10
import lxml.etree
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
    11
from models import Project, Content
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
    12
from ldt.core.models import Owner
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
    13
from utils import LdtUtils, LdtSearch, create_ldt, create_empty_iri, copy_ldt
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
    14
import base64
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
    15
import uuid
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
    16
import tempfile
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
    17
from django.contrib.auth.models import *
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
    18
from views import get_attrib
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
    19
from django.conf import settings
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
    20
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
    21
0
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
class SimpleTest(TestCase):
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
    def test_basic_addition(self):
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
        """
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
        Tests that 1 + 1 always equals 2.
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
        """
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
        self.failUnlessEqual(1 + 1, 2)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
__test__ = {"doctest": """
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
Another way to test that 1 + 1 is equal to 2.
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
>>> 1 + 1 == 2
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
True
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
"""}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
80
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
    37
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
    38
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
    39
class UtilsTest(unittest.TestCase):
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
    40
    def setUp(self):
85
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    41
        self.user = Owner()
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    42
        self.user.username = "toto"
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    43
        self.LU = LdtUtils()
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    44
    
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    45
        self.project = Project(title="titleproj1", owner=self.user)
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    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>'
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    47
        self.project.id = "11"
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    48
        self.project.ldt_id = str(uuid.uuid1())
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    49
        self.project.save()
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    50
        
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    51
        self.projectcopy = Project(title="the2ndproject")
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    52
        self.projectcopy.id="22"
80
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
    53
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
    54
    def tearDown(self):
85
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    55
        self.project.delete()
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    56
        self.projectcopy.delete()
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    57
        #self.cont1.delete()
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    58
        #self.cont2.delete()
80
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
    59
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
    60
    def test_generate_ldt(self):
85
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    61
        self.cont1 = Content(iriurl="id1/iriurl1")
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    62
        self.cont1.iri_id = "id1"
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    63
        self.cont1.save()
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    64
        
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    65
        self.cont2 = Content(iriurl="id2/iriurl2")
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    66
        self.cont2.iri_id = "id2"
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    67
        self.cont2.save()
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    68
        
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    69
        self.project.contents.add(self.cont1,self.cont2)
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    70
    
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    71
        f=tempfile.TemporaryFile(mode='r+')
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    72
        self.LU.generateLdt(Content.objects.all(),f)
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    73
        f.seek(0)
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    74
        ldoc = lxml.etree.parse(f)
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    75
        self.assertEqual(ldoc.xpath("/iri/displays/display/content")[9].get("id"),self.cont2.iri_id)
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    76
        self.assertEqual(ldoc.xpath("/iri/medias/media")[8].get("id"), self.cont1.iri_id)
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    77
        f.close()
80
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
    78
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
    79
    def test_generate_init(self):
85
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    80
        self.cont3 = Content(iriurl="id3/iriurl1")
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    81
        self.cont3.iri_id = "id3"
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    82
        self.cont3.save()
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    83
        
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    84
        self.cont4 = Content(iriurl="id4/iriurl2")
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    85
        self.cont4.iri_id = "id4"
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    86
        self.cont4.save()
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    87
        
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    88
        self.project.contents.add(self.cont3,self.cont4)
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    89
        ldoc = self.LU.generateInit(None,None)
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    90
        self.assertEqual(ldoc.xpath("/iri/files/init")[0].tag, "init")
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    91
        self.assertEqual(ldoc.xpath("/iri/files/library")[0].tag, "library")
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    92
        self.assertEqual(ldoc.xpath("/iri/files/init/file")[0].get("video"), settings.STREAM_URL)
80
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
    93
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
    94
    def test_create_ldt(self):
85
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    95
        self.cont5 = Content(iriurl="id5/iriurl1")
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    96
        self.cont5.iri_id = "id5"
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    97
        self.cont5.save()
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    98
        
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    99
        self.cont6 = Content(iriurl="id6/iriurl2")
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   100
        self.cont6.iri_id = "id6"
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   101
        self.cont6.save()
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   102
        
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   103
        self.project.contents.add(self.cont5,self.cont6)
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   104
        self.project.ldt=""
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   105
        create_ldt(self.project, self.user)
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   106
        ldt = lxml.etree.fromstring(self.project.ldt)
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   107
        self.assertEqual(ldt.xpath("/iri")[0].tag,"iri")
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   108
        self.assertEqual(ldt.xpath("/iri/project")[0].get("title"), self.project.title)
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   109
        self.assertEqual(ldt.xpath("/iri/medias/media")[0].get("src"), self.cont5.iri_url())
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   110
        self.assertEqual(ldt.xpath("/iri/medias/media")[1].get("id"), self.cont6.iri_id)
80
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
   111
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
   112
    def test_copy_ldt(self):
85
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   113
        self.cont7 = Content(iriurl="id7/iriurl1")
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   114
        self.cont7.iri_id = "id7"
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   115
        self.cont7.save()
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   116
        
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   117
        self.cont8 = Content(iriurl="id8/iriurl2")
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   118
        self.cont8.iri_id = "id8"
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   119
        self.cont8.save()
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   120
        
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   121
        self.project.contents.add(self.cont7,self.cont8)
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   122
        copy_ldt(self.project, self.projectcopy, self.user)
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   123
        ldt1=lxml.etree.fromstring(self.project.ldt)
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   124
        ldt2=lxml.etree.fromstring(self.projectcopy.ldt)
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   125
        self.assertTrue(ldt1.xpath("/iri/project")[0].get("id")!= ldt2.xpath("/iri/project")[0].get("id"))
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   126
        self.assertEqual(ldt1.xpath("/iri/medias/media")[0].get("id"),ldt2.xpath("/iri/medias/media")[0].get("id"))
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   127
        self.assertEqual(ldt1.xpath("/iri/annotations/content/ensemble")[0].get("title"),ldt2.xpath("/iri/annotations/content/ensemble")[0].get("title"))
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   128
        self.assertEqual(ldt1.xpath("/iri/annotations/content/ensemble/decoupage")[0].get("id"),ldt2.xpath("/iri/annotations/content/ensemble/decoupage")[0].get("id"))
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   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"))
80
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
   130
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
   131
    def test_create_empty_iri(self):
85
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   132
        self.cont9 = Content(iriurl="id9/iriurl1")
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   133
        self.cont9.iri_id = "id9"
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   134
        self.cont9.save()
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   135
        
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   136
        self.cont10 = Content(iriurl="id10/iriurl2")
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   137
        self.cont10.iri_id = "id10"
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   138
        self.cont10.save()
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   139
        
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   140
        self.project.contents.add(self.cont9,self.cont10)
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   141
        tmp = tempfile.TemporaryFile(mode='r+')
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   142
        create_empty_iri(tmp, self.cont9, "admin")
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   143
        tmp.seek(0)
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   144
        ldoc = lxml.etree.parse(tmp)
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   145
        self.assertEqual(ldoc.xpath("/iri/head/meta")[0].get("content"), self.cont9.iri_id)
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   146
        self.assertEqual(ldoc.xpath("/iri/body/medias/media/video")[0].get("id"), self.cont9.iri_id)
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   147
        tmp.close()
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   148
    
80
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
   149
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
   150
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
   151
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
   152
class ViewsTest(unittest.TestCase):
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
   153
    def setUp(self):
85
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   154
        self.project = Project()
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   155
        self.project.id = "121"
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   156
        self.project.save()
80
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
   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>' 
85
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   158
    
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   159
        self.cont1 = Content(iriurl="/laurentcantet_entrelesmurs/iriurl1")
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   160
        self.cont1.iri_id = 'laurentcantet_entrelesmurs'
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   161
        self.cont1.save()
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   162
    
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   163
        self.cont2 = Content(iriurl="/content_notinldt/iriurl2")
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   164
        self.cont2.iri_id = 'content_notinldt'
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   165
        self.cont2.save()
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   166
        
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   167
        self.project.contents.add(self.cont1, self.cont2)
80
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
   168
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
   169
    def tearDown(self):
85
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   170
        self.project.delete()
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   171
        ##self.cont1.delete()
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   172
        ##self.cont2.delete()
80
1e7732f40eee Migrated to lxml and added tests
wakimd
parents: 0
diff changeset
   173
85
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   174
#    def test_get_attrib(self):
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   175
#        get_attrib(self.project)
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   176
#        ldoc = lxml.etree.fromstring(self.project.ldt)    
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   177
#        self.assertEqual(self.project.title, ldoc.xpath("/iri/project")[0].get("title"))
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   178
#        self.assertEqual(ldoc.xpath("/iri/medias/media")[0].get('id'), self.cont1.iri_id)
3b70d84e661a Bug corrections
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   179
#        self.assertTrue(self.cont2.iri_id not in self.project.contents.all())