summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2011-04-08 20:35:55 +0200
committerÉtienne Loks <etienne.loks@peacefrogs.net>2011-04-08 20:35:55 +0200
commitcfbcd3cd0851dcb9846e4e6701cbcb8e878dd343 (patch)
treee0e80b7d804425b10294392af5e6786eaee55298
parentcad5f0c110c87cd0e945c92e54dde9c5417eeef4 (diff)
downloadIshtar-cfbcd3cd0851dcb9846e4e6701cbcb8e878dd343.tar.bz2
Ishtar-cfbcd3cd0851dcb9846e4e6701cbcb8e878dd343.zip
Managing tests
-rw-r--r--ishtar/furnitures/fixtures/user.json30
-rw-r--r--ishtar/furnitures/tests.py79
-rw-r--r--ishtar/settings.py.example1
3 files changed, 98 insertions, 12 deletions
diff --git a/ishtar/furnitures/fixtures/user.json b/ishtar/furnitures/fixtures/user.json
new file mode 100644
index 000000000..c2486d47d
--- /dev/null
+++ b/ishtar/furnitures/fixtures/user.json
@@ -0,0 +1,30 @@
+[
+ {
+ "pk": 1,
+ "model": "auth.user",
+ "fields": {
+ "username": "lj.yann",
+ "first_name": "Yann",
+ "last_name": "Le Jeune",
+ "is_active": true,
+ "is_superuser": true,
+ "is_staff": true,
+ "last_login": "2011-04-06 18:19:27",
+ "groups": [],
+ "user_permissions": [],
+ "password": "sha1$6ecea$358d73e2f3dd3d67b64daf247b1b758094c0ed67",
+ "email": "lj.yann@gmail.com",
+ "date_joined": "2011-01-04 15:08:05"
+ }
+ },
+ {
+ "pk": 1,
+ "model": "furnitures.ishtaruser",
+ "fields": {
+ "user_permissions": [],
+ "person": 1,
+ "groups": []
+ }
+ }
+]
+
diff --git a/ishtar/furnitures/tests.py b/ishtar/furnitures/tests.py
index 2247054b3..67756cd00 100644
--- a/ishtar/furnitures/tests.py
+++ b/ishtar/furnitures/tests.py
@@ -1,23 +1,78 @@
-"""
-This file demonstrates two different styles of tests (one doctest and one
-unittest). These will both pass when you run "manage.py test".
+#!/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/>.
-Replace these with more appropriate tests for your application.
+# See the file COPYING for details.
+
+"""
+Unit tests
"""
from django.test import TestCase
-class SimpleTest(TestCase):
- def test_basic_addition(self):
+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.
"""
- self.failUnlessEqual(1 + 1, 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)
-__test__ = {"doctest": """
-Another way to test that 1 + 1 is equal to 2.
->>> 1 + 1 == 2
-True
-"""}
diff --git a/ishtar/settings.py.example b/ishtar/settings.py.example
index 64f44af1d..11b2e3a58 100644
--- a/ishtar/settings.py.example
+++ b/ishtar/settings.py.example
@@ -19,6 +19,7 @@ ODT_TEMPLATE = ROOT_PATH + "../static/template.odt"
LOGIN_REDIRECT_URL = "/" + URL_PATH
DEBUG = True
TEMPLATE_DEBUG = DEBUG
+TEST_RUNNER='django.contrib.gis.tests.run_tests'
ADMINS = (
# ('Your Name', 'your_email@domain.com'),