def _get_questionnaire(self, id=None, version=None): form = get_form('xls-form') kwargs = {'project': self.prj, 'xls_form': form} if id: kwargs.update({'id_string': id}) if version: kwargs.update({'version': version}) return QuestionnaireFactory.create(**kwargs)
def _create_questionnaire(self, questionnaire_name, version, schema=True): questionnaire = QuestionnaireFactory.create( project=self.prj, xls_form=get_form(questionnaire_name), filename=questionnaire_name, id_string=questionnaire_name, version=(20160727122110 + version)) if schema: self._create_attrs_schema(self.prj) return questionnaire
def test_form_not_current_questionnaire(self): # update the default form to a new version QuestionnaireFactory.create( project=self.prj, xls_form=get_form('test_standard_questionnaire'), filename='test_standard_questionnaire_updated', id_string='test_standard_questionnaire', version=20160727122111 ) data = self._submission(form='form') response = self.request(method='POST', post_data=data, user=self.user, content_type='multipart/form-data') msg = self._getResponseMessage(response) assert msg == 'Form out of date'
def test_post_invalid_form(self): question = get_form('xls-form-invalid') user = UserFactory.create() assign_policies(user) response = self.request(user=user, method='POST', post_data={'questionnaire': question}) post_data = self.post_data.copy() post_data.update({'questionnaire': question}) form = forms.ProjectEditDetails(instance=self.project, initial={'questionnaire': question}, data=post_data) form.is_valid() form.add_error('questionnaire', "Unknown question type 'interger'.") # form.add_error('questionnaire', # "'interger' is not an accepted question type") # form.add_error('questionnaire', # "'select multiple list' is not an accepted question " # "type") assert response.status_code == 200 assert response.content == self.render_content(form=form)
def setup_models(self): self.user = UserFactory.create() self.org = OrganizationFactory.create() self.prj = ProjectFactory.create(organization=self.org) self.prj_2 = ProjectFactory.create(organization=self.org) self.prj_3 = ProjectFactory.create(organization=self.org) OrganizationRole.objects.create( organization=self.org, user=self.user, admin=True) QuestionnaireFactory.create( project=self.prj, xls_form=get_form('test_standard_questionnaire'), filename='test_standard_questionnaire', id_string='test_standard_questionnaire', version=20160727122110) questionnaire = QuestionnaireFactory.create( project=self.prj_2, xls_form=get_form('test_standard_questionnaire_2'), filename='test_standard_questionnaire_2', id_string='test_standard_questionnaire_2', version=20160727122111) QuestionFactory.create( name='location_geometry', label='Location of Parcel', type='GS', questionnaire=questionnaire) QuestionnaireFactory.create( project=self.prj_3, xls_form=get_form('test_standard_questionnaire_bad'), filename='test_standard_questionnaire_bad', id_string='test_standard_questionnaire_bad', version=20160727122112) # project 1 create_attrs_schema( project=self.prj, dict=default_party_xform_group, content_type=ContentType.objects.get( app_label='party', model='party'), errors=[]) create_attrs_schema( project=self.prj, dict=individual_party_xform_group, content_type=ContentType.objects.get( app_label='party', model='party'), errors=[]) create_attrs_schema( project=self.prj, dict=location_xform_group, content_type=ContentType.objects.get( app_label='spatial', model='spatialunit'), errors=[]) create_attrs_schema( project=self.prj, dict=tenure_relationship_xform_group, content_type=ContentType.objects.get( app_label='party', model='tenurerelationship'), errors=[]) # project 2 create_attrs_schema( project=self.prj_2, dict=default_party_xform_group, content_type=ContentType.objects.get( app_label='party', model='party'), errors=[]) create_attrs_schema( project=self.prj_2, dict=individual_party_xform_group, content_type=ContentType.objects.get( app_label='party', model='party'), errors=[]) create_attrs_schema( project=self.prj_2, dict=location_xform_group, content_type=ContentType.objects.get( app_label='spatial', model='spatialunit'), errors=[]) create_attrs_schema( project=self.prj_2, dict=tenure_relationship_xform_group, content_type=ContentType.objects.get( app_label='party', model='tenurerelationship'), errors=[])