src/cm/tests/test_structure.py
changeset 0 40c8f766c9b8
child 103 61fd17f9ab78
equal deleted inserted replaced
-1:000000000000 0:40c8f766c9b8
       
     1 from django.test import TestCase
       
     2 from django.test.client import Client
       
     3 from django.core import management
       
     4 
       
     5 from cm.models import *
       
     6 
       
     7 class StructureTest(TestCase):
       
     8     fixtures = ['test_comments',]
       
     9     
       
    10     def test_edit_text(self):
       
    11         self.assertEqual(TextVersion.objects.count(), 1)
       
    12         self.assertEqual(Comment.objects.count(), 8)
       
    13         
       
    14         # edit with duplication, without changing content
       
    15         text = Text.objects.all()[0]
       
    16         new_text = text.edit(new_title='my title', 
       
    17                   new_format='html', 
       
    18                   new_content=text.get_latest_version().content, 
       
    19                   keep_comments = True, 
       
    20                   new_version = True)
       
    21         self.assertEqual(TextVersion.objects.count(), 2)
       
    22         self.assertEqual(Comment.objects.count(), 16)
       
    23         
       
    24         # edit with duplication changing content
       
    25         new_text = text.edit(new_title='my title', 
       
    26                   new_format='html', 
       
    27                   new_content='simple text <p>simple text</p> <p>simple text</p> ', 
       
    28                   keep_comments = True, 
       
    29                   new_version = True)
       
    30         self.assertEqual(TextVersion.objects.count(), 3)
       
    31         self.assertEqual(Comment.objects.count(), 17) # 22
       
    32 
       
    33         # edit without duplication, completely changing content
       
    34         new_text = text.edit(new_title='my title', 
       
    35                   new_format='html', 
       
    36                   new_content='xxxxxx', 
       
    37                   keep_comments = True, 
       
    38                   new_version = False)
       
    39         self.assertEqual(TextVersion.objects.count(), 3)
       
    40         self.assertEqual(Comment.objects.count(), 16) # 21
       
    41 
       
    42     def test_edit_text2(self):
       
    43         self.assertEqual(TextVersion.objects.count(), 1)
       
    44         self.assertEqual(Comment.objects.count(), 8)
       
    45         text = Text.objects.all()[0]
       
    46         new_text = text.edit(new_title='my title', 
       
    47                   new_format='html', 
       
    48                   new_content='xxxxxx', 
       
    49                   keep_comments = False, 
       
    50                   new_version = False)
       
    51         self.assertEqual(TextVersion.objects.count(), 1)
       
    52         self.assertEqual(Comment.objects.count(), 0)
       
    53 
       
    54     def test_edit_text3(self):
       
    55         self.assertEqual(TextVersion.objects.count(), 1)
       
    56         self.assertEqual(Comment.objects.count(), 8)
       
    57         text = Text.objects.all()[0]
       
    58         new_text = text.edit(new_title='my title', 
       
    59                   new_format='html', 
       
    60                   new_content='xxxxxx', 
       
    61                   keep_comments = False, 
       
    62                   new_version = True)
       
    63         self.assertEqual(TextVersion.objects.count(), 2)
       
    64         self.assertEqual(Comment.objects.count(), 8)
       
    65