summaryrefslogtreecommitdiff
path: root/archaeological_operations/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r--archaeological_operations/tests.py89
1 files changed, 83 insertions, 6 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index 0a48f4d4a..afcbc39ff 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-# Copyright (C) 2012-2013 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
+# Copyright (C) 2012-2014 É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
@@ -20,20 +20,27 @@
"""
Unit tests
"""
-import json, os
+import json, os, datetime
+from django.conf import settings
from django.core.management import call_command
+from django.core.urlresolvers import reverse
from django.test import TestCase
+from django.test.client import Client
from django.contrib.auth.models import User
import models
-from ishtar_common.models import OrganizationType, Organization, Town
+from ishtar_common.models import OrganizationType, Organization, Town, \
+ PersonType
class ImportOperationTest(TestCase):
- fixtures = [settings.ROOT_PATH + '../ishtar_common/fixtures/initial_data.json',
- settings.ROOT_PATH + '../archaeological_files/fixtures/initial_data.json',
- settings.ROOT_PATH + '../archaeological_operations/fixtures/initial_data-fr.json']
+ fixtures = [settings.ROOT_PATH +
+ '../ishtar_common/fixtures/initial_data.json',
+ settings.ROOT_PATH +
+ '../archaeological_files/fixtures/initial_data.json',
+ settings.ROOT_PATH +
+ '../archaeological_operations/fixtures/initial_data-fr.json']
def setUp(self):
user = User.objects.create_user('username')
@@ -296,3 +303,73 @@ class ImportOperationTest(TestCase):
value)
)
+def create_user():
+ username = 'username4277'
+ password = 'dcbqj756456!@%'
+ user = User.objects.create_superuser(username, "nomail@nomail.com",
+ password)
+ return username, password, user
+
+def create_operation(user):
+ dct = {'year':2010, 'operation_type_id':1,
+ 'history_modifier':user,}
+ operations = [models.Operation.objects.create(**dct)]
+ return operations
+
+class OperationTest(TestCase):
+ fixtures = [settings.ROOT_PATH +
+ '../ishtar_common/fixtures/initial_data.json',
+ settings.ROOT_PATH +
+ '../archaeological_files/fixtures/initial_data.json',
+ settings.ROOT_PATH +
+ '../archaeological_operations/fixtures/initial_data-fr.json']
+
+ def setUp(self):
+ self.username, self.password, self.user = create_user()
+ self.operations = create_operation(self.user)
+ self.item = self.operations[0]
+
+ def testSearch(self):
+ c = Client()
+ response = c.get(reverse('get-operation'), {'year': '2010',})
+ # no result when no authentification
+ self.assertTrue(not json.loads(response.content))
+ c.login(username=self.username, password=self.password)
+ response = c.get(reverse('get-operation'), {'year': '2010',})
+ self.assertTrue(json.loads(response.content)['total'] == 1)
+
+def create_administrativact(user, operation):
+ act_type, created = models.ActType.objects.get_or_create(txt_idx='act_type')
+ dct = {'history_modifier':user,
+ 'act_type':act_type,
+ 'operation':operation,
+ 'signature_date':datetime.date(2014, 05, 12),
+ 'index':322}
+ adminact, created = models.AdministrativeAct.objects.get_or_create(**dct)
+ return [act_type], [adminact]
+
+
+class RegisterTest(TestCase):
+ fixtures = [settings.ROOT_PATH +
+ '../ishtar_common/fixtures/initial_data.json',
+ settings.ROOT_PATH +
+ '../archaeological_files/fixtures/initial_data.json',
+ settings.ROOT_PATH +
+ '../archaeological_operations/fixtures/initial_data-fr.json']
+
+ def setUp(self):
+ self.username, self.password, self.user = create_user()
+ self.operations = create_operation(self.user)
+ self.act_types, self.operations = create_administrativact(
+ self.user, self.operations[0])
+
+ def testSearch(self):
+ c = Client()
+ response = c.get(reverse('get-administrativeact'), {'year': '2014',})
+ # no result when no authentification
+ self.assertTrue(not json.loads(response.content))
+ c.login(username=self.username, password=self.password)
+ response = c.get(reverse('get-administrativeact'), {'year': '2014',})
+ self.assertTrue(json.loads(response.content)['total'] == 1)
+ response = c.get(reverse('get-administrativeact'), {'indexed': '2',})
+ self.assertTrue(json.loads(response.content)['total'] == 1)