web/ldt/ldt_utils/tests.py
author wakimd
Sun, 14 Nov 2010 20:25:22 +0100
changeset 1 3a30d255c235
child 2 59311c28454f
permissions -rw-r--r--
First version of API with tests
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     1
#encoding:UTF-8
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     2
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     3
""" Run these tests with 'python manage.py test ldt_utils'  """
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     4
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     5
from django.test import TestCase
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     6
import unittest
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     7
import lxml.etree
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     8
from ldt.ldt_utils.models import *
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     9
from ldt.core.models import Owner
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    10
from views import *
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    11
import base64
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    12
import uuid
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    13
import tempfile
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    14
import datetime
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    15
from django.contrib.auth.models import *
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    16
from django.conf import settings
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    17
from django.test.client import Client
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    18
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    19
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    20
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    21
# This test creates an annotation and checks that:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    22
# 1. the annotation was created in the database (by trying to access it through a 'get')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    23
# 2. the returned xml contains correct data
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    24
class CreateTest(unittest.TestCase):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    25
    def setUp(self):
3a30d255c235 First version of API with tests
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>')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    27
        self.c = Client()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    28
    def tearDown(self):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    29
        annotlist=Annotation.objects.all()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    30
        for annot in annotlist:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    31
            annot.delete()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    32
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    33
    def test_create_annotation(self):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    34
        response = self.c.post('/create/', {'content':self.content})
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    35
        self.annot1 = lxml.etree.fromstring(response.content)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    36
        #self.assertEqual(lxml.etree.tostring(self.annot1),"lala")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    37
        self.assertEqual(self.annot1.xpath("/iri/text-annotation/id/text()")[0],"f2c1d1fa-629d-4520-a3d2-955b4f2582c0")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    38
        self.assertEqual(self.annot1.xpath("/iri/text-annotation/content")[0].tag,"content")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    39
        self.assertEqual(self.annot1.xpath("/iri/text-annotation/tags/tag/text()")[0],"tag1")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    40
        self.assertEqual(self.annot1.xpath("/iri/text-annotation/content/text/text()")[0],u"texte selectionne lors de la creation de l\'annotation")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    41
        self.assertEqual(self.annot1.xpath("/iri/text-annotation/meta/created/text()")[0],"2010-09-06 12:33:53.417550")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    42
        annot = Annotation.objects.get(id="f2c1d1fa-629d-4520-a3d2-955b4f2582c0")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    43
        self.assertEqual(annot.uri, "http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    44
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    45
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    46
# This test creates an annotation, then gets it, and checks that the returned xml contains correct data
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    47
class GetTest(unittest.TestCase):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    48
    def setUp(self):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    49
        self.annotation = Annotation(id="d2c1d1fa-629d-4520-a3d2-955b4f2582c0", tags=[u"tag1",u"tag2",u"tag3"], title="titre de l\'annotation",text="texte selectionne lors de la creation de l\'annotation",color="#AAAAAA", creation_date="2010-09-06T12:33:53.417550", update_date="2010-09-06T12:33:53.420459")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    50
        self.annotation.save()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    51
    def tearDown(self):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    52
        annotlist=Annotation.objects.all()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    53
        for annot in annotlist:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    54
            annot.delete()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    55
      
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    56
    def test_get_annotation(self):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    57
        response = self.c.get('/get/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    58
        self.annot1 = lxml.etree.fromstring(response.content)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    59
        #self.annot1 = get_annotation("d2c1d1fa-629d-4520-a3d2-955b4f2582c0")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    60
        #self.assertEqual(lxml.etree.tostring(self.annot1),"lala")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    61
        self.assertEqual(self.annot1.xpath("/iri/text-annotation/id/text()")[0],self.annotation.id)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    62
        self.assertEqual(self.annot1.xpath("/iri/text-annotation/tags/tag/text()")[1], self.annotation.tags[1])
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    63
        self.assertEqual(self.annot1.xpath("/iri/text-annotation/content/color/text()")[0],self.annotation.color)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    64
        #self.assertEqual(self.annot1.xpath("/iri/text-annotation/meta/created/text()"), self.annotation.creation_date)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    65
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    66
        
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    67
class FilterTest(unittest.TestCase):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    68
    def setUp(self):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    69
        self.annotation = Annotation(id="k2c1d1fa-629d-4520-a3d2-955b4f2582c0",title="titre de l\'annotation",text="texte selectionne lors de la creation de l\'annotation",color="#AAAAAA", uri="http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168", creator="wakimd")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    70
        self.annotation.save()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    71
        self.annotation2 = Annotation(id="l2c1d1fa-629d-4520-a3d2-955b4f2582c0",title="titre de l\'annotation2",text="texte selectionne lors de la creation de l\'annotation2",color="#BBBBBB", uri="http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168", creator="wakimd")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    72
        self.annotation2.save()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    73
        self.annotation3 = Annotation(id="m2c1d1fa-629d-4520-a3d2-955b4f2582c0", title="titre3", text="texte3", color="#CCCCCC", uri="http://blabla", creator="wakimd")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    74
        self.annotation3.save()        
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    75
    def tearDown(self):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    76
        annotlist=Annotation.objects.all()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    77
        for annot in annotlist:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    78
            annot.delete()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    79
        
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    80
    def test_filter_annotation_creator(self):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    81
        user = 'wakimd'
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    82
        uri = None
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    83
        limit= 2
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    84
        doc = filter_annotation(uri,None,limit,user)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    85
        cpt = 0
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    86
        for elem in doc.xpath("/iri/text-annotation"):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    87
            cpt = cpt + 1
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    88
        #self.assertEqual(lxml.etree.tostring(doc),"lala")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    89
        if limit is not None:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    90
            self.assertEqual(cpt,limit)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    91
        for elem in doc.xpath("/iri/text-annotation/meta/creator/text()"):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    92
            self.assertEqual(elem,user)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    93
        
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    94
    def test_filter_annotation_uri(self):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    95
        uri = "http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168"
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    96
        limit = None
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    97
        doc = filter_annotation(uri,None,limit,None)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    98
        for elem in doc.xpath("/iri/text-annotation/uri/text()"):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    99
            self.assertEqual(elem[:57],"http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   100
            
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   101
    def test_filter_annotation_filter(self):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   102
        user = 'wakimd'
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   103
        uri = None
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   104
        filter = 'lors'
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   105
        limit = None
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   106
        doc = filter_annotation(uri,filter,limit,user)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   107
        #self.assertEqual(lxml.etree.tostring(doc),"lala")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   108
        for elem in doc.xpath("/iri/text-annotation/content/text/text()"):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   109
            self.assertTrue('lors' in elem)  
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   110
        for elem in doc.xpath("/iri/text-annotation/meta/creator/text()"):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   111
            self.assertEqual(elem,user)          
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   112
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   113
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   114
# This test creates an annotation, then deletes it, and checks that:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   115
# 1. the annotation doesn't exist anymore in the database (by trying to access it through a 'get')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   116
# 2. the returned xml contains no data
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   117
class DeleteTest(unittest.TestCase):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   118
    def setUp(self):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   119
        self.annotation = Annotation(id="d2c1d1fa-629d-4520-a3d2-955b4f2582c0",title="titre de l\'annotation",text="texte selectionne lors de la creation de l\'annotation",color="#AAAAAA", creation_date="2010-09-06T12:33:53.417550", update_date="2010-09-06T12:33:53.420459")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   120
        self.annotation.save()    
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   121
    def tearDown(self):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   122
        annotlist=Annotation.objects.all()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   123
        for annot in annotlist:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   124
            annot.delete()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   125
    
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   126
    def test_delete_annotation(self):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   127
        response = self.c.post('/delete/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   128
        response2 - self.c.get('/get/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   129
        doc = lxml.etree.fromstring(response.content)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   130
        #doc=delete_annotation("d2c1d1fa-629d-4520-a3d2-955b4f2582c0")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   131
        self.assertEqual(self.annot1.xpath("/iri/text-annotation/id/text()")[0],'')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   132
        self.assertEqual(self.annot1.xpath("/iri/text-annotation/tags/tag/text()")[1], '')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   133
        self.assertEqual(self.annot1.xpath("/iri/text-annotation/content/color/text()")[0],'')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   134
        self.assertEqual(self.annot1.xpath("/iri/text-annotation/meta/creator/text()")[0],'')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   135
        self.assertEqual(response2.status_code, '404')   
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   136
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   137
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   138
# This test creates an annotation, then updates it with new content, and checks that the returned xml contains the updated data
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   139
class UpdateTest(unittest.TestCase):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   140
    def setUp(self):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   141
        self.annotation = Annotation(id="d2c1d1fa-629d-4520-a3d2-955b4f2582c0", tags=['tag1','mytag'],title="titre de l\'annotation",text="texte selectionne lors de la creation de l\'annotation",color="#AAAAAA", creation_date="2010-09-06T12:33:53.417550", update_date="2010-09-06T12:33:53.420459")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   142
        self.annotation.save()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   143
    def tearDown(self):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   144
        annotlist=Annotation.objects.all()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   145
        for annot in annotlist:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   146
            annot.delete()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   147
            
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   148
    def test_update_annotation(self):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   149
        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>')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   150
        response = self.c.post('/update/', {'content':content,'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   151
        doc = lxml.etree.fromstring(response.content)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   152
        #doc = update_annotation(content,'d2c1d1fa-629d-4520-a3d2-955b4f2582c0')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   153
        #self.assertEqual(lxml.etree.tostring(doc),"lala")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   154
        self.assertEqual(doc.xpath("/iri/text-annotation/id/text()")[0],"d2c1d1fa-629d-4520-a3d2-955b4f2582c0")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   155
        self.assertEqual(doc.xpath("/iri/text-annotation/tags/tag/text()")[1], "mytag")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   156
        self.assertEqual(doc.xpath("/iri/text-annotation/content/color/text()")[0],"#DDDDDD")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   157
               
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   158
                
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   159
#class AnnotTest(unittest.TestCase):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   160
#    def setUp(self):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   161
#        self.annot = Annotation(id=u'd2c1d1fa-629d-4520-a3d2-955b4f2582c0', uri=u'http://iri.blabla', tags=[u'tag1',u'tag2'], title=u'montitre', description=u'madesc', text=u'letexteselectionne', color=u'#AAAAAA', creator=u'wakimd', contributor=u'wakimd', creation_date=u'2010-09-06 12:33:53.417550', update_date=u'2010-09-06 12:33:53.417550')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   162
#        self.annot.save()       
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   163
#    def tearDown(self):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   164
#        annotlist=Annotation.objects.all()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   165
#        for annot in annotlist:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   166
#            annot.delete()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   167
#  
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   168
#    def test_create_annotation(self):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   169
#        b = Annotation.objects.get(id=u'd2c1d1fa-629d-4520-a3d2-955b4f2582c0')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   170
#        self.assertEqual(b.title, 'montitre')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   171
#            
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   172
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   173
# These tests check common error codes are raised when needed
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   174
class ErrorTest(unittest.TestCase):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   175
    def setUp(self):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   176
        self.annot = Annotation(id=u'd2c1d1fa-629d-4520-a3d2-955b4f2582c0', uri=u'http://iri.blabla', tags=[u'tag1',u'tag2'], title=u'montitre', description=u'madesc', text=u'letexteselectionne', color=u'#AAAAAA', creator=u'wakimd', contributor=u'wakimd', creation_date=u'2010-09-06 12:33:53.417550', update_date=u'2010-09-06 12:33:53.417550')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   177
        self.annot.save()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   178
    
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   179
    def tearDown(self):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   180
        annotlist=Annotation.objects.all()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   181
        for annot in annotlist:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   182
            annot.delete()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   183
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   184
    def test_error_create(self):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   185
        content = base64.urlsafe_b64encode('<iri><text-annotation><id>d2c1d1fa-629d-4520-a3d2-955b4f2582c0</id><uri>http://www.leezam.com/pub/epub/123456!/OPS/chapter2.xhtml#pos=56,168</uri><tags><tag>tag1</tag><tag>tag2</tag></tags><content><color>#AAAAAA</color><description><![CDATA[texte de description]]></description><title><![CDATA[titre de l�annotation]]></title><text><![CDATA[texte selectionne lors de la creation de l\'annotation]]></text></content><meta><contributor>oaubert</contributor><contributor-id>79cd0532-1dda-4130-b351-6a181130a7c9</contributor-id><created>2010-09-06 12:33:53.417550</created><creator>oaubert</creator><creator-id>79cd0532-1dda-4130-b351-6a181130a7c9</creator-id><modified>2010-09-06 12:33:53.420459</modified></meta></text-annotation></iri>')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   186
        response = self.c.post('/create/', {'content':self.content})
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   187
        #annot2 = create_annotation(content)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   188
        self.assertEqual(response.status_code, '409')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   189
        
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   190
    def test_error_get(self):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   191
        response = self.c.get('/get/', {'id':'d2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   192
        #annot3 = get_annotation('d2c1d1fa-629d-4520-a3d2-955b4f2582c0')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   193
        resp = response.status_code
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   194
        self.assertEqual(response.status_code,'404')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   195
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   196
    def test_error_delete(self):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   197
        response = self.c.post('/delete/', {'id':'f2c1d1fa-629d-4520-a3d2-955b4f2582c0'})
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   198
        #annot4 = delete_annotation('f2c1d1fa-629d-4520-a3d2-955b4f2582c0')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   199
        self.assertEqual(response.status_code,'404')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   200
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   201
    def test_error_update(self):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   202
        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>')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   203
        response = self.c.post('/update/', {'content':content,'id':'dfc1d1fa-629d-4520-a3d2-955b4f2582c0'})
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   204
        #annot5=update_annotation()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   205
        self.assertEqual(response.status_code,'404')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   206