diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-11-20 15:17:42 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-11-20 15:17:42 +0100 |
commit | 9309d89a48cee876ef17213924b2cc0b026677f9 (patch) | |
tree | 59e72e3bc35787dd2e822cbfd6896e4f8da30cd3 /ishtar_common/tests.py | |
parent | a9d9b977778068d2609342d2749123618108e9d7 (diff) | |
download | Ishtar-9309d89a48cee876ef17213924b2cc0b026677f9.tar.bz2 Ishtar-9309d89a48cee876ef17213924b2cc0b026677f9.zip |
Custom forms: filter by user and by groups - tests
Diffstat (limited to 'ishtar_common/tests.py')
-rw-r--r-- | ishtar_common/tests.py | 70 |
1 files changed, 41 insertions, 29 deletions
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 63d80d5ab..016596772 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -288,6 +288,38 @@ class WizardTest(object): raise ValidationError(u"Errors: {} on {}.".format( u" ".join(errors), current_step)) + @classmethod + def wizard_post(cls, client, url, current_step, form_data=None, + follow=True): + if not url: + url = reverse(cls.url_name) + data = { + '{}{}-current_step'.format(cls.url_name, + cls.wizard_name): [current_step], + } + if not form_data: + form_data = [] + + # reconstruct a POST request + if type(form_data) in (list, tuple): # is a formset + for d_idx, item in enumerate(form_data): + for k in item: + data['{}-{}-{}'.format( + current_step, d_idx, k)] = item[k] + else: + for k in form_data: + data['{}-{}'.format(current_step, k)] = form_data[k] + + try: + response = client.post(url, data, follow=follow) + except ValidationError as e: + msg = u"Errors: {} on {}. On \"ManagementForm data is " \ + u"missing or...\" error verify the wizard_name or " \ + u"step name".format(u" - ".join(e.messages), + current_step) + raise ValidationError(msg) + return response + def test_wizard(self): if self.pass_test(): return @@ -301,35 +333,14 @@ class WizardTest(object): current_step, current_form = step if current_step in ignored: continue - data = { - '{}{}-current_step'.format(self.url_name, - self.wizard_name): - [current_step], - } - - # reconstruct a POST request - if current_step in form_data: - d = form_data[current_step] - if type(d) in (list, tuple): # is a formset - for d_idx, item in enumerate(d): - for k in item: - data['{}-{}-{}'.format( - current_step, d_idx, k)] = item[k] - else: - for k in d: - data['{}-{}'.format(current_step, k)] = d[k] - next_form_is_checked = len(self.steps) > idx + 1 and \ - self.steps[idx + 1][0] not in ignored - try: - response = self.client.post( - url, data, follow=not next_form_is_checked) - except ValidationError as e: - msg = u"Errors: {} on {}. On \"ManagementForm data is " \ - u"missing or...\" error verify the wizard_name or " \ - u"step name".format(u" - ".join(e.messages), - current_step) - raise ValidationError(msg) + self.steps[idx + 1][0] not in ignored + data = [] + if current_step in form_data: + data = form_data[current_step] + response = self.wizard_post( + self.client, url, current_step, data, + not next_form_is_checked) self.check_response(response, current_step) if next_form_is_checked: next_form = self.steps[idx + 1][0] @@ -402,7 +413,8 @@ class AdminGenTypeTest(TestCase): gen_models = [ models.OrganizationType, models.PersonType, models.TitleType, models.AuthorType, models.SourceType, models.OperationType, - models.SpatialReferenceSystem, models.Format, models.SupportType] + models.SpatialReferenceSystem, models.Format, models.SupportType, + ] models_with_data = gen_models + [models.ImporterModel] models = models_with_data module_name = 'ishtar_common' |