web/ldt/text/tests.py
author wakimd
Tue, 23 Nov 2010 17:54:36 +0100
changeset 21 1a061f244254
parent 19 7cf81d58a968
permissions -rw-r--r--
Pylucene indexation
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 *
16
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
    11
import urllib
9
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
17
683ce4109c28 various corrections, especially on the model (and tags)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    19
from django.db import transaction
19
7cf81d58a968 oauth start
wakimd
parents: 17
diff changeset
    20
from django.contrib.auth.models import User
7cf81d58a968 oauth start
wakimd
parents: 17
diff changeset
    21
import time
21
1a061f244254 Pylucene indexation
wakimd
parents: 19
diff changeset
    22
import lucene
1a061f244254 Pylucene indexation
wakimd
parents: 19
diff changeset
    23
from ldt.text import STORE, ANALYZER
1a061f244254 Pylucene indexation
wakimd
parents: 19
diff changeset
    24
from ldt.text.utils import *
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    25
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    26
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    27
# This test creates an annotation and checks that:
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    28
# 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
    29
# 2. the returned xml contains correct data
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    30
class CreateTest(unittest.TestCase):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    31
    def setUp(self):
16
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
    32
        self.content = str('<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>')
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    33
        self.c = Client()
17
683ce4109c28 various corrections, especially on the model (and tags)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    34
        self.annot = Annotation(external_id=u'd2c1d1fa-629d-4520-a3d2-955b4f2582c0', uri=u'http://iri.blabla', tags=u"tag1,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')
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    35
        self.annot.save()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    36
    def tearDown(self):
17
683ce4109c28 various corrections, especially on the model (and tags)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    37
        transaction.rollback()
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    38
        annotlist=Annotation.objects.all()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    39
        for annot in annotlist:
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    40
            annot.delete()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    41
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    42
    def test_create_annotation(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    43
        response = self.c.post('/api/'+ VERSION_STR +'/text/create/', {'content':self.content})
16
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
    44
        #self.assertEqual(response.content, "  ")
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    45
        self.annot1 = lxml.etree.fromstring(response.content)
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    46
        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
    47
        self.assertEqual(self.annot1.xpath("/iri/text-annotation/content")[0].tag,"content")
17
683ce4109c28 various corrections, especially on the model (and tags)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    48
        self.assertEqual(self.annot1.xpath("/iri/text-annotation/tags/tag/text()")[0],u"tag1")
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    49
        self.assertEqual(self.annot1.xpath("/iri/text-annotation/content/text/text()")[0],u"texte selectionne lors de la creation de l\'annotation")
17
683ce4109c28 various corrections, especially on the model (and tags)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    50
        #self.assertEqual(self.annot1.xpath("/iri/text-annotation/meta/created/text()")[0],"2010-09-06 12:33:53.417550")
16
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
    51
        response2 = self.c.get('/api/'+ VERSION_STR +'/text/get/', {'id':'f2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
    52
        annot2 = lxml.etree.fromstring(response.content)
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
    53
        self.assertEqual(annot2.xpath("/iri/text-annotation/uri/text()")[0], "http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168")
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    54
        
16
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
    55
    def test_error_create(self):
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
    56
        content = '<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>'
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
    57
        response = self.c.post('/api/'+ VERSION_STR +'/text/create/', {'content':content})
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
    58
        self.assertEqual(response.status_code, 409)
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    59
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    60
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    61
# 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
    62
class GetTest(unittest.TestCase):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    63
    def setUp(self):
17
683ce4109c28 various corrections, especially on the model (and tags)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    64
        self.annotation = Annotation(external_id="d2c1d1fa-629d-4520-a3d2-955b4f2582c0", tags=u"tag1 ,tag2 ,     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")
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    65
        self.annotation.save()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    66
        self.c = Client()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    67
    def tearDown(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    68
        annotlist=Annotation.objects.all()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    69
        for annot in annotlist:
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    70
            annot.delete()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    71
      
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    72
    def test_get_annotation(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    73
        response = self.c.get('/api/'+ VERSION_STR +'/text/get/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
17
683ce4109c28 various corrections, especially on the model (and tags)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    74
        print response
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    75
        self.annot1 = lxml.etree.fromstring(response.content)
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    76
        self.assertEqual(self.annot1.xpath("/iri/text-annotation/id/text()")[0],self.annotation.external_id)
17
683ce4109c28 various corrections, especially on the model (and tags)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    77
        self.assertEqual(self.annot1.xpath("/iri/text-annotation/tags/tag/text()")[1], "tag2")
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    78
        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
    79
        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
    80
10
000f3ca19eaa Added 404 templates + some views corrections
wakimd
parents: 9
diff changeset
    81
    def test_error_get(self):
000f3ca19eaa Added 404 templates + some views corrections
wakimd
parents: 9
diff changeset
    82
        response = self.c.get('/api/'+ VERSION_STR +'/text/get/', {'id':'2'})
000f3ca19eaa Added 404 templates + some views corrections
wakimd
parents: 9
diff changeset
    83
        self.assertEqual(response.status_code,404)
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    84
        
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    85
        
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    86
class FilterTest(unittest.TestCase):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    87
    def setUp(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    88
        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
    89
        self.annotation.save()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    90
        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
    91
        self.annotation2.save()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    92
        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
    93
        self.annotation3.save() 
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    94
        self.c = Client()       
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    95
    def tearDown(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    96
        annotlist=Annotation.objects.all()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    97
        for annot in annotlist:
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    98
            annot.delete()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    99
        
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   100
    def test_filter_annotation_creator_limit(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   101
        user = 'wakimd'
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   102
        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
   103
        limit= 1
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   104
        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
   105
        doc = lxml.etree.fromstring(response.content)
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   106
        cpt = 0
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   107
        for elem in doc.xpath("/iri/text-annotation"):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   108
            cpt = cpt + 1
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   109
        if limit is not None:
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   110
            self.assertEqual(cpt,limit)
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   111
        for elem in doc.xpath("/iri/text-annotation/meta/creator/text()"):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   112
            self.assertEqual(elem,user)
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   113
        for elem in doc.xpath("/iri/text-annotation/uri/text()"):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   114
            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
   115
        
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   116
    def test_filter_annotation_uri(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   117
        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
   118
        response = self.c.get('/api/'+ VERSION_STR +'/text/filter/', {'uri':uri})
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   119
        doc = lxml.etree.fromstring(response.content)
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   120
        for elem in doc.xpath("/iri/text-annotation/uri/text()"):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   121
            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
   122
            
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   123
    def test_filter_annotation_filter(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   124
        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
   125
        filter = 'lors'
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   126
        limit = None
21
1a061f244254 Pylucene indexation
wakimd
parents: 19
diff changeset
   127
        response = self.c.get('/api/'+ VERSION_STR +'/text/filter/', {'uri':uri,'filter':filter})
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   128
        doc = lxml.etree.fromstring(response.content)
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   129
        for elem in doc.xpath("/iri/text-annotation/content/text/text()"):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   130
            self.assertTrue('lors' in elem)  
17
683ce4109c28 various corrections, especially on the model (and tags)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   131
        #for elem in doc.xpath("/iri/text-annotation/meta/creator/text()"):
683ce4109c28 various corrections, especially on the model (and tags)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   132
        #    self.assertEqual(elem,user)          
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   133
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   134
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   135
# This test creates an annotation, then deletes it, and checks that:
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   136
# 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
   137
# 2. the returned xml contains no data
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   138
class DeleteTest(unittest.TestCase):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   139
    def setUp(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   140
        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
   141
        self.annotation.save()
21
1a061f244254 Pylucene indexation
wakimd
parents: 19
diff changeset
   142
        self.c = Client()
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   143
    def tearDown(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   144
        annotlist=Annotation.objects.all()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   145
        for annot in annotlist:
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   146
            annot.delete()
21
1a061f244254 Pylucene indexation
wakimd
parents: 19
diff changeset
   147
        
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   148
    
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   149
    def test_delete_annotation(self):
16
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   150
        id = urllib.urlencode({'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   151
        f = urllib.urlopen("http://127.0.0.1:8000/api/1.0/text/delete/", id)
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   152
        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
   153
        response2 = self.c.get('/ldt/get/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   154
        doc = lxml.etree.fromstring(response.content)
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   155
        self.assertEqual(doc.xpath("/iri/text-annotation/id/text()"),[])
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   156
        self.assertEqual(doc.xpath("/iri/text-annotation/tags/tag/text()"), [])
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   157
        self.assertEqual(doc.xpath("/iri/text-annotation/content/color/text()"),[])
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   158
        self.assertEqual(doc.xpath("/iri/text-annotation/meta/creator/text()"),[])
21
1a061f244254 Pylucene indexation
wakimd
parents: 19
diff changeset
   159
        self.assertEqual(response2.status_code, 404)
1a061f244254 Pylucene indexation
wakimd
parents: 19
diff changeset
   160
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   161
10
000f3ca19eaa Added 404 templates + some views corrections
wakimd
parents: 9
diff changeset
   162
    def test_error_delete(self):
000f3ca19eaa Added 404 templates + some views corrections
wakimd
parents: 9
diff changeset
   163
        response = self.c.post('/api/'+ VERSION_STR +'/text/ldt/delete/', {'id':'1'})
000f3ca19eaa Added 404 templates + some views corrections
wakimd
parents: 9
diff changeset
   164
        self.assertEqual(response.status_code,404)
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   165
        
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   166
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   167
# 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
   168
class UpdateTest(unittest.TestCase):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   169
    def setUp(self):
17
683ce4109c28 various corrections, especially on the model (and tags)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   170
        self.annotation = Annotation(external_id="d2c1d1fa-629d-4520-a3d2-955b4f2582c0", tags=u"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")
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   171
        self.annotation.save()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   172
        self.c = Client()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   173
    def tearDown(self):
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   174
        annotlist=Annotation.objects.all()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   175
        for annot in annotlist:
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   176
            annot.delete()
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   177
            
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   178
    def test_update_annotation(self):
16
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   179
        content = '<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>'
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   180
        response = self.c.post('/api/'+ VERSION_STR +'/text/update/', {'content':content,'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})        
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   181
        doc = lxml.etree.fromstring(response.content)
16
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   182
        #self.assertEqual(lxml.etree.tostring(doc), " ")
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   183
        self.assertEqual(doc.xpath("/iri/text-annotation/id/text()")[0],"d2c1d1fa-629d-4520-a3d2-955b4f2582c0")
17
683ce4109c28 various corrections, especially on the model (and tags)
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   184
        self.assertEqual(doc.xpath("/iri/text-annotation/tags/tag/text()")[1], "tag2new")
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   185
        self.assertEqual(doc.xpath("/iri/text-annotation/content/color/text()")[0],"#DDDDDD")
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   186
        
10
000f3ca19eaa Added 404 templates + some views corrections
wakimd
parents: 9
diff changeset
   187
    def test_error_update(self):
16
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   188
        content = '<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>'
10
000f3ca19eaa Added 404 templates + some views corrections
wakimd
parents: 9
diff changeset
   189
        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
   190
        self.assertEqual(response.status_code,404)
000f3ca19eaa Added 404 templates + some views corrections
wakimd
parents: 9
diff changeset
   191
               
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
   192
16
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   193
class OnServerGlobalTest(unittest.TestCase):
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   194
    def setUp(self):
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   195
        self.content = urllib.urlencode({'content':'<iri><text-annotation><id>mypersonnalid</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>'})
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   196
        self.content2 = urllib.urlencode({'content':'<iri><text-annotation><id>mypersonnalid2</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>#BBBBBB</color><description><![CDATA[texte de description2]]></description><title><![CDATA[titre de l\'annotation2]]></title><text><![CDATA[texte selectionne lors de la creation de l\'annotation2]]></text></content><meta><contributor>wakimd</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>'})
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   197
        self.id = urllib.urlencode({"id":"mypersonnalid"})
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   198
        self.id2 = urllib.urlencode({"id":"mypersonnalid2"})
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   199
        self.uri = urllib.urlencode({"uri":"http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168"})
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   200
        self.filt1 = urllib.urlencode({"uri":"http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168", "creator":"","limit":"","filter":""})
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   201
        self.filt2 = urllib.urlencode({"uri":"http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168","creator":"wakimd","limit":"","filter":""})
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   202
        self.up = urllib.urlencode({'content':'<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>','id':'mypersonnalid'})
21
1a061f244254 Pylucene indexation
wakimd
parents: 19
diff changeset
   203
        self.LS = LdtSearch()
16
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   204
    
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   205
    def test_everything(self):
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   206
        creation = urllib.urlopen("http://127.0.0.1:8000/api/"+VERSION_STR+"/text/create/", self.content)
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   207
        creation2 = urllib.urlopen("http://127.0.0.1:8000/api/"+VERSION_STR+"/text/create/", self.content2)
21
1a061f244254 Pylucene indexation
wakimd
parents: 19
diff changeset
   208
1a061f244254 Pylucene indexation
wakimd
parents: 19
diff changeset
   209
        res1 = self.LS.query("title","titre de l'annotation")
1a061f244254 Pylucene indexation
wakimd
parents: 19
diff changeset
   210
        self.assertEqual(len(res1),1)
1a061f244254 Pylucene indexation
wakimd
parents: 19
diff changeset
   211
        res2 = self.LS.query("title","titre de l'annotation2")
1a061f244254 Pylucene indexation
wakimd
parents: 19
diff changeset
   212
        self.assertEqual(len(res2),1)
1a061f244254 Pylucene indexation
wakimd
parents: 19
diff changeset
   213
16
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   214
        
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   215
        get = urllib.urlopen("http://127.0.0.1:8000/api/"+VERSION_STR+"/text/get/?%s" % self.id)
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   216
        
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   217
        update = urllib.urlopen("http://127.0.0.1:8000/api/"+VERSION_STR+"/text/update/", self.up)
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   218
        
21
1a061f244254 Pylucene indexation
wakimd
parents: 19
diff changeset
   219
        res3 = self.LS.query("abstract","texte de description update")
1a061f244254 Pylucene indexation
wakimd
parents: 19
diff changeset
   220
        self.assertEqual(len(res3),1)
1a061f244254 Pylucene indexation
wakimd
parents: 19
diff changeset
   221
        
1a061f244254 Pylucene indexation
wakimd
parents: 19
diff changeset
   222
        filt1 = urllib.urlopen("http://127.0.0.1:8000/api/"+VERSION_STR+"/text/filter/?%s" % self.uri)
16
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   223
        filt2 = urllib.urlopen("http://127.0.0.1:8000/api/"+VERSION_STR+"/text/filter/?uri=http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168?creator=wakimd")
21
1a061f244254 Pylucene indexation
wakimd
parents: 19
diff changeset
   224
16
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   225
        delete = urllib.urlopen("http://127.0.0.1:8000/api/"+VERSION_STR+"/text/delete/", self.id)
d0f617472760 Added tests on server + some corrections on views
wakimd
parents: 10
diff changeset
   226
        delete = urllib.urlopen("http://127.0.0.1:8000/api/"+VERSION_STR+"/text/delete/", self.id2)
19
7cf81d58a968 oauth start
wakimd
parents: 17
diff changeset
   227
21
1a061f244254 Pylucene indexation
wakimd
parents: 19
diff changeset
   228
        res4 = self.LS.query("title","titre de l'annotation")
1a061f244254 Pylucene indexation
wakimd
parents: 19
diff changeset
   229
        self.assertEqual(len(res4),0)
1a061f244254 Pylucene indexation
wakimd
parents: 19
diff changeset
   230
        res5 = self.LS.query("title","titre de l'annotation2")
1a061f244254 Pylucene indexation
wakimd
parents: 19
diff changeset
   231
        self.assertEqual(len(res5),0)
19
7cf81d58a968 oauth start
wakimd
parents: 17
diff changeset
   232
7cf81d58a968 oauth start
wakimd
parents: 17
diff changeset
   233
        
7cf81d58a968 oauth start
wakimd
parents: 17
diff changeset
   234