web/ldt/text/tests.py
author wakimd
Tue, 16 Nov 2010 15:35:12 +0100
changeset 10 000f3ca19eaa
parent 9 22ab430e9b64
child 16 d0f617472760
permissions -rw-r--r--
Added 404 templates + some views corrections
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     1
#encoding:UTF-8
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     2
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     3
""" Run these tests with 'python manage.py test text'  """
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     4
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     5
from django.test import TestCase
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     6
import unittest
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     7
import lxml.etree
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     8
from ldt.text.models import *
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     9
from ldt.core.models import Owner
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    10
from views import *
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    11
import base64
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    12
import uuid
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    13
import tempfile
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    14
import datetime
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    15
from django.contrib.auth.models import *
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    16
from django.conf import settings
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    17
from django.test.client import Client
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    18
from ldt.text import VERSION_STR
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    19
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    20
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    21
# This test creates an annotation and checks that:
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    22
# 1. the annotation was created in the database (by trying to access it through a 'get')
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    23
# 2. the returned xml contains correct data
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    24
class CreateTest(unittest.TestCase):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    25
    def setUp(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    26
        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>')
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    27
        self.c = Client()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    28
        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')
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    29
        self.annot.save()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    30
    def tearDown(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    31
        annotlist=Annotation.objects.all()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    32
        for annot in annotlist:
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    33
            annot.delete()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    34
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    35
    def test_create_annotation(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    36
        response = self.c.post('/api/'+ VERSION_STR +'/text/create/', {'content':self.content})
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    37
        self.annot1 = lxml.etree.fromstring(response.content)
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    38
        self.assertEqual(self.annot1.xpath("/iri/text-annotation/id/text()")[0],"f2c1d1fa-629d-4520-a3d2-955b4f2582c0")
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    39
        self.assertEqual(self.annot1.xpath("/iri/text-annotation/content")[0].tag,"content")
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    40
        self.assertEqual(self.annot1.xpath("/iri/text-annotation/tags/tag/text()")[0],"tag1")
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    41
        self.assertEqual(self.annot1.xpath("/iri/text-annotation/content/text/text()")[0],u"texte selectionne lors de la creation de l\'annotation")
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    42
        self.assertEqual(self.annot1.xpath("/iri/text-annotation/meta/created/text()")[0],"2010-09-06 12:33:53.417550")
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    43
        annot = Annotation.objects.get(external_id="f2c1d1fa-629d-4520-a3d2-955b4f2582c0")
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    44
        self.assertEqual(annot.uri, "http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168")
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    45
        
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    46
#    def test_error_create(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    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>')
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    48
#        response = self.c.post('/api/'+ VERSION_STR +'/text/create/', {'content':content})
10
000f3ca19eaa Added 404 templates + some views corrections
wakimd
parents: 9
diff changeset
    49
#        self.assertEqual(response.status_code, 409)
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    50
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    51
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    52
# This test creates an annotation, then gets it, and checks that the returned xml contains correct data
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    53
class GetTest(unittest.TestCase):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    54
    def setUp(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    55
        self.annotation = Annotation(external_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")
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    56
        self.annotation.save()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    57
        self.c = Client()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    58
    def tearDown(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    59
        annotlist=Annotation.objects.all()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    60
        for annot in annotlist:
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    61
            annot.delete()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    62
      
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    63
    def test_get_annotation(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    64
        response = self.c.get('/api/'+ VERSION_STR +'/text/get/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    65
        self.annot1 = lxml.etree.fromstring(response.content)
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    66
        self.assertEqual(self.annot1.xpath("/iri/text-annotation/id/text()")[0],self.annotation.external_id)
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    67
        self.assertEqual(self.annot1.xpath("/iri/text-annotation/tags/tag/text()")[1], self.annotation.tags[1])
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    68
        self.assertEqual(self.annot1.xpath("/iri/text-annotation/content/color/text()")[0],self.annotation.color)
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    69
        self.assertEqual(self.annot1.xpath("/iri/text-annotation/meta/created/text()")[0], str(self.annotation.creation_date))
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    70
10
000f3ca19eaa Added 404 templates + some views corrections
wakimd
parents: 9
diff changeset
    71
    def test_error_get(self):
000f3ca19eaa Added 404 templates + some views corrections
wakimd
parents: 9
diff changeset
    72
        response = self.c.get('/api/'+ VERSION_STR +'/text/get/', {'id':'2'})
000f3ca19eaa Added 404 templates + some views corrections
wakimd
parents: 9
diff changeset
    73
        self.assertEqual(response.status_code,404)
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    74
        
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    75
        
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    76
class FilterTest(unittest.TestCase):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    77
    def setUp(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    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")
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    79
        self.annotation.save()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    80
        self.annotation2 = Annotation(external_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")
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    81
        self.annotation2.save()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    82
        self.annotation3 = Annotation(external_id="m2c1d1fa-629d-4520-a3d2-955b4f2582c0", title="titre3", text="texte3", color="#CCCCCC", uri="http://blabla", creator="wakimd")
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    83
        self.annotation3.save() 
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    84
        self.c = Client()       
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    85
    def tearDown(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    86
        annotlist=Annotation.objects.all()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    87
        for annot in annotlist:
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    88
            annot.delete()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    89
        
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    90
    def test_filter_annotation_creator_limit(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    91
        user = 'wakimd'
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    92
        uri = "http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168"
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    93
        limit= 1
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    94
        response = self.c.get('/api/'+ VERSION_STR +'/text/filter/', {'uri':uri,'creator':user,'limit':limit})
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    95
        doc = lxml.etree.fromstring(response.content)
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    96
        cpt = 0
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    97
        for elem in doc.xpath("/iri/text-annotation"):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    98
            cpt = cpt + 1
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    99
        if limit is not None:
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   100
            self.assertEqual(cpt,limit)
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   101
        for elem in doc.xpath("/iri/text-annotation/meta/creator/text()"):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   102
            self.assertEqual(elem,user)
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   103
        for elem in doc.xpath("/iri/text-annotation/uri/text()"):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   104
            self.assertEqual(elem[:57],"http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml")
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   105
        
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   106
    def test_filter_annotation_uri(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   107
        uri = "http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168"
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   108
        response = self.c.get('/api/'+ VERSION_STR +'/text/filter/', {'uri':uri})
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   109
        doc = lxml.etree.fromstring(response.content)
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   110
        for elem in doc.xpath("/iri/text-annotation/uri/text()"):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   111
            self.assertEqual(elem[:57],"http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml")
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   112
            
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   113
    def test_filter_annotation_filter(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   114
        uri = "http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168"
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   115
        filter = 'lors'
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   116
        limit = None
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   117
        response = self.c.get('/api/'+ VERSION_STR +'/text/filter/', {'uri':uri,'filter':'lors'})
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   118
        doc = lxml.etree.fromstring(response.content)
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   119
        for elem in doc.xpath("/iri/text-annotation/content/text/text()"):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   120
            self.assertTrue('lors' in elem)  
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   121
        for elem in doc.xpath("/iri/text-annotation/meta/creator/text()"):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   122
            self.assertEqual(elem,user)          
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   123
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   124
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   125
# This test creates an annotation, then deletes it, and checks that:
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   126
# 1. the annotation doesn't exist anymore in the database (by trying to access it through a 'get')
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   127
# 2. the returned xml contains no data
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   128
class DeleteTest(unittest.TestCase):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   129
    def setUp(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   130
        self.annotation = Annotation(external_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")
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   131
        self.annotation.save()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   132
        self.c = Client()    
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   133
    def tearDown(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   134
        annotlist=Annotation.objects.all()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   135
        for annot in annotlist:
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   136
            annot.delete()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   137
    
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   138
    def test_delete_annotation(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   139
        response = self.c.post('/api/'+ VERSION_STR +'/text/delete/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
10
000f3ca19eaa Added 404 templates + some views corrections
wakimd
parents: 9
diff changeset
   140
        response2 = self.c.get('/ldt/get/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   141
        doc = lxml.etree.fromstring(response.content)
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   142
        self.assertEqual(doc.xpath("/iri/text-annotation/id/text()"),[])
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   143
        self.assertEqual(doc.xpath("/iri/text-annotation/tags/tag/text()"), [])
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   144
        self.assertEqual(doc.xpath("/iri/text-annotation/content/color/text()"),[])
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   145
        self.assertEqual(doc.xpath("/iri/text-annotation/meta/creator/text()"),[])
10
000f3ca19eaa Added 404 templates + some views corrections
wakimd
parents: 9
diff changeset
   146
        self.assertEqual(response2.status_code, 404)   
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   147
10
000f3ca19eaa Added 404 templates + some views corrections
wakimd
parents: 9
diff changeset
   148
    def test_error_delete(self):
000f3ca19eaa Added 404 templates + some views corrections
wakimd
parents: 9
diff changeset
   149
        response = self.c.post('/api/'+ VERSION_STR +'/text/ldt/delete/', {'id':'1'})
000f3ca19eaa Added 404 templates + some views corrections
wakimd
parents: 9
diff changeset
   150
        self.assertEqual(response.status_code,404)
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   151
        
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   152
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   153
# This test creates an annotation, then updates it with new content, and checks that the returned xml contains the updated data
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   154
class UpdateTest(unittest.TestCase):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   155
    def setUp(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   156
        self.annotation = Annotation(external_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")
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   157
        self.annotation.save()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   158
        self.c = Client()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   159
    def tearDown(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   160
        annotlist=Annotation.objects.all()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   161
        for annot in annotlist:
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   162
            annot.delete()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   163
            
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   164
    def test_update_annotation(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   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>')
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   166
        response = self.c.post('/api/'+ VERSION_STR +'/text/update/', {'content':content,'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   167
        doc = lxml.etree.fromstring(response.content)
10
000f3ca19eaa Added 404 templates + some views corrections
wakimd
parents: 9
diff changeset
   168
        self.assertEqual(lxml.etree.tostring(doc), " ")
000f3ca19eaa Added 404 templates + some views corrections
wakimd
parents: 9
diff changeset
   169
        self.assertEqual(doc.xpath("/iri/text-annotation/id/text()"),"d2c1d1fa-629d-4520-a3d2-955b4f2582c0")
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   170
        self.assertEqual(doc.xpath("/iri/text-annotation/tags/tag/text()")[1], "mytag")
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   171
        self.assertEqual(doc.xpath("/iri/text-annotation/content/color/text()")[0],"#DDDDDD")
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   172
        
10
000f3ca19eaa Added 404 templates + some views corrections
wakimd
parents: 9
diff changeset
   173
    def test_error_update(self):
000f3ca19eaa Added 404 templates + some views corrections
wakimd
parents: 9
diff changeset
   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>')
000f3ca19eaa Added 404 templates + some views corrections
wakimd
parents: 9
diff changeset
   175
        response = self.c.post('/api/'+ VERSION_STR +'/text/update/', {'content':content,'id':'1'})
000f3ca19eaa Added 404 templates + some views corrections
wakimd
parents: 9
diff changeset
   176
        self.assertEqual(response.status_code,404)
000f3ca19eaa Added 404 templates + some views corrections
wakimd
parents: 9
diff changeset
   177
               
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   178