1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2011 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# See the file COPYING for details.
"""
Unit tests
"""
from django.test import TestCase
import models
class FileTest(TestCase):
fixtures = ['user.json']
model = models.File
def setUp(self):
self.extra_models, self.model_list = {}, []
user = models.IshtarUser.objects.get(pk=1)
person_type = models.PersonType(label=u'Test person type',
txt_idx='test_person', available=True)
person_type.save()
self.extra_models['person_type'] = person_type
self.model_list.append(person_type)
person = models.Person(title='Mr', surname='Surname', name='Name',
person_type=person_type, history_modifier=user)
person.save()
self.extra_models['person'] = person
self.model_list.append(person)
file_type = models.FileType(label=u'Test file type',
txt_idx='test_file', available=True)
file_type.save()
self.extra_models['file_type'] = file_type
self.model_list.append(file_type)
dct = {'year':2010, 'numeric_reference':1000, 'file_type':file_type,
'internal_reference':u'UNIT_testÉ ?', 'in_charge':person,
'history_modifier':user, 'total_surface':10000}
self.item = self.model(**dct)
self.item.save()
def tearDown(self):
self.item.delete()
for item in reversed(self.model_list):
item.delete()
def testAddAndGetHistorized(self):
"""
Tests that 1 + 1 always equals 2.
"""
nb_hist = self.item.history.count()
self.assertTrue(self.item.history.count() >= 1)
base_label = self.item.internal_reference
self.item.internal_reference = u"Unité_Test"
self.item.save()
self.failUnlessEqual(self.item.history.count(), nb_hist+1)
self.failUnlessEqual(self.item.history.all()[1].internal_reference,
base_label)
|