summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/fixtures/initial_data-fr.json33
-rw-r--r--ishtar_common/tests.py86
2 files changed, 110 insertions, 9 deletions
diff --git a/ishtar_common/fixtures/initial_data-fr.json b/ishtar_common/fixtures/initial_data-fr.json
index 48793410f..24a0d7a6c 100644
--- a/ishtar_common/fixtures/initial_data-fr.json
+++ b/ishtar_common/fixtures/initial_data-fr.json
@@ -59,16 +59,13 @@
"available": true,
"txt_idx": "sra_agent",
"groups": [
- 30,
- 31,
- 32,
- 2,
1,
- 4,
+ 2,
3,
+ 4,
5,
- 7,
6,
+ 7,
8,
9,
10,
@@ -86,7 +83,13 @@
26,
27,
28,
- 29
+ 29,
+ 30,
+ 31,
+ 32,
+ 33,
+ 34,
+ 35
],
"label": "Agent SRA (prescripteur)"
}
@@ -131,7 +134,19 @@
"comment": "Article 13 D\u00e9cret 2004\r\n\r\nLe pr\u00e9fet de r\u00e9gion \u00e9dicte les prescriptions arch\u00e9ologiques, d\u00e9livre l'autorisation de fouille et d\u00e9signe le responsable scientifique de toute op\u00e9ration d'arch\u00e9ologie pr\u00e9ventive.\r\n\r\nLe responsable scientifique est l'interlocuteur du pr\u00e9fet de r\u00e9gion et le garant de la qualit\u00e9 scientifique de l'op\u00e9ration arch\u00e9ologique. A ce titre, il prend, dans le cadre de la mise en oeuvre du projet d'intervention de l'op\u00e9rateur, les d\u00e9cisions relatives \u00e0 la conduite scientifique de l'op\u00e9ration et \u00e0 l'\u00e9laboration du rapport dont il dirige la r\u00e9daction. Il peut \u00eatre diff\u00e9rent pour la r\u00e9alisation du diagnostic et pour la r\u00e9alisation de la fouille.",
"available": true,
"txt_idx": "head_scientist",
- "groups": [],
+ "groups": [
+ 30,
+ 32,
+ 1,
+ 4,
+ 6,
+ 15,
+ 21,
+ 25,
+ 33,
+ 34,
+ 35
+ ],
"label": "Responsable scientifique"
}
},
@@ -165,7 +180,7 @@
],
"label": "Secr\u00e9tariat SRA"
}
- },
+ },
{
"pk": 5,
"model": "ishtar_common.organizationtype",
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py
index 82ab009e0..1b8601dfb 100644
--- a/ishtar_common/tests.py
+++ b/ishtar_common/tests.py
@@ -17,10 +17,13 @@
# See the file COPYING for details.
+from BeautifulSoup import BeautifulSoup as Soup
+
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.core.cache import cache
+from django.core.exceptions import ValidationError
from django.core.urlresolvers import reverse
from django.template.defaultfilters import slugify
from django.test import TestCase
@@ -54,6 +57,89 @@ class OOOGenerationTest(TestCase):
"""
+def create_superuser():
+ username = 'username4277'
+ password = 'dcbqj756456!@%'
+ user = User.objects.create_superuser(username, "nomail@nomail.com",
+ password)
+ return username, password, user
+
+
+def create_user():
+ username = 'username678'
+ password = 'dcbqj756456!@%'
+ user = User.objects.create_user(username, email="nomail2@nomail.com")
+ user.set_password(password)
+ user.save()
+ return username, password, user
+
+
+class WizardTest(object):
+ url_name = None
+ wizard_name = ''
+ steps = None
+ condition_dict = None
+ form_datas = []
+
+ def setUp(self):
+ self.username, self.password, self.user = create_superuser()
+
+ def pre_wizard(self):
+ self.client.login(**{'username': self.username,
+ 'password': self.password})
+
+ def post_wizard(self):
+ pass
+
+ def test_wizard(self):
+ url = reverse(self.url_name)
+ self.pre_wizard()
+ for form_data, ignored in self.form_datas:
+ for idx, step in enumerate(self.steps):
+ current_step, current_form = step
+ if current_step in ignored:
+ continue
+ data = {
+ '{}{}-current_step'.format(self.url_name,
+ self.wizard_name):
+ [current_step],
+ }
+ if current_step in form_data:
+ d = form_data[current_step]
+ for k in d:
+ data['{}-{}'.format(current_step, k)] = d[k]
+
+ next_idx, next_form = idx + 1, None
+ while len(self.steps) > next_idx:
+ if self.steps[idx + 1][0] not in ignored:
+ next_form = self.steps[idx + 1][0]
+ break
+ next_idx = next_idx + 1
+
+ if next_form:
+ try:
+ response = self.client.post(url, data)
+ except ValidationError as e:
+ raise ValidationError(u"Errors: {} on {}.".format(
+ u" - ".join(e.messages), current_step))
+ if "errorlist" in response.content:
+ soup = Soup(response.content)
+ errorlist = soup.findAll(
+ "ul", {"class": "errorlist"})
+ errors = []
+ for li in errorlist:
+ lbl = li.findParent().findParent().findChild().text
+ errors.append(u"{} - {}".format(lbl, li.text))
+ raise ValidationError(u"Errors: {} on {}.".format(
+ u" ".join(errors), current_step))
+ self.assertRedirects(
+ response,
+ '/{}/{}'.format(self.url_name, next_form))
+ else:
+ response = self.client.post(url, data, follow=True)
+ self.post_wizard()
+
+
class MergeTest(TestCase):
def setUp(self):
self.user, created = User.objects.get_or_create(username='username')