def test_fixture_setup(self): data = FixturesData() data.delete_test_users() data.delete_test_organizations() data.delete_test_projects() data.add_test_organizations() PolicyFactory.load_policies() # Just for test coverage... PolicyFactory.load_policies(update=True) create_attribute_types() load_tenure_relationship_types() data.add_test_users_and_roles() data.add_test_projects() data.add_test_spatial_units() assert User.objects.count() == 20 assert Policy.objects.count() == 7 assert Organization.objects.count() == 2 assert Project.objects.count() == 9 assert SpatialUnit.objects.count() == 7 assert SpatialRelationship.objects.count() == 2 data.delete_test_users() data.delete_test_organizations() data.delete_test_projects() assert User.objects.count() == 0 assert Organization.objects.count() == 0 assert Project.objects.count() == 0 assert SpatialUnit.objects.count() == 0 assert SpatialRelationship.objects.count() == 0
def test_get_context(self): models.create_attribute_types() org = factories.OrganizationFactory.create() project = factories.ProjectFactory.create(organization=org) content_type = ContentType.objects.get( app_label='tests', model='party') schema1 = models.Schema.objects.create( content_type=content_type, selectors=(org.id, project.id)) models.Attribute.objects.create( schema=schema1, name='field_1', long_name='Field 1', attr_type=models.AttributeType.objects.get(name='text'), index=0 ) models.Attribute.objects.create( schema=schema1, name='field_2', long_name='Field 2', attr_type=models.AttributeType.objects.get(name='text'), index=1 ) models.Attribute.objects.create( schema=schema1, name='field_3', long_name='Field 3', attr_type=models.AttributeType.objects.get(name='select_multiple'), choices=['one', 'two', 'three'], choice_labels=['Choice 1', 'Choice 2', 'Choice 3'], index=2, ) models.Attribute.objects.create( schema=schema1, name='field_4', long_name='Field 4', attr_type=models.AttributeType.objects.get(name='select_one'), choices=['one', 'two', 'three'], choice_labels=['Choice 1', 'Choice 2', 'Choice 3'], index=3, ) party = factories.PartyFactory.create( project=project, attrs={'field_1': 'Some value', 'field_3': ['one', 'three'], 'field_4': 'two'} ) view = JsonAttrsView() view.object = party context = view.get_context_data() assert len(context['attrs']) == 4 assert context['attrs'][0] == ('Field 1', 'Some value') assert context['attrs'][1] == ('Field 2', '—') assert context['attrs'][2] == ('Field 3', 'Choice 1, Choice 3') assert context['attrs'][3] == ('Field 4', 'Choice 2')
def test_fixture_setup(self): data = FixturesData() data.delete_test_users() data.delete_test_organizations() data.delete_test_projects() data.add_test_organizations() PolicyFactory.load_policies() # Just for test coverage... PolicyFactory.load_policies(force=True) create_attribute_types() load_tenure_relationship_types() data.add_test_users_and_roles() data.add_test_projects() data.add_test_spatial_units() data.add_huge_project() assert User.objects.count() == 20 assert Policy.objects.count() == 7 assert Organization.objects.count() == 2 assert Project.objects.count() == 9 assert SpatialUnit.objects.count() == 4007 assert SpatialRelationship.objects.count() == 2 data.delete_test_users() data.delete_test_organizations() data.delete_test_projects() assert User.objects.count() == 0 assert Organization.objects.count() == 0 assert Project.objects.count() == 0 assert SpatialUnit.objects.count() == 0 assert SpatialRelationship.objects.count() == 0
def setUp(self): super().setUp() PolicyFactory.load_policies() create_attribute_types() loadattrtypes.Command().handle(force=True) load_tenure_relationship_types(force=True) self.user = UserFactory.create() self.project = ProjectFactory.create(current_questionnaire='a1') self.questionnaire = QuestionnaireFactory.create(id_string='a1', version=0, project=self.project, id='a1') QuestionFactory.create(name='location_geometry', label='Location of Parcel', type='GS', questionnaire=self.questionnaire) content_type_party = ContentType.objects.get(app_label='party', model='party') content_type_spatial = ContentType.objects.get(app_label='spatial', model='spatialunit') content_type_tenure = ContentType.objects.get( app_label='party', model='tenurerelationship') for content_type in [ content_type_party, content_type_tenure, content_type_spatial ]: schema = Schema.objects.create( content_type=content_type, selectors=(self.project.organization.id, self.project.id, 'a1')) attr_type = AttributeType.objects.get(name='boolean') Attribute.objects.create(schema=schema, name='fname', long_name='True or False', attr_type=attr_type, index=0, required=False, omit=False) attr_type = AttributeType.objects.get(name='text') Attribute.objects.create(schema=schema, name='fname_two', long_name='Notes', attr_type=attr_type, index=1, required=False, omit=False) OrganizationRole.objects.create(user=self.user, organization=self.project.organization)
def setUp(self): super().setUp() PolicyFactory.load_policies() create_attribute_types() loadattrtypes.Command().handle(force=True) load_tenure_relationship_types(force=True) self.user = UserFactory.create() self.project = ProjectFactory.create( current_questionnaire='a1') self.questionnaire = QuestionnaireFactory.create( id_string='a1', version=0, project=self.project, id='a1') QuestionFactory.create( name='location_geometry', label='Location of Parcel', type='GS', questionnaire=self.questionnaire) content_type_party = ContentType.objects.get( app_label='party', model='party') content_type_spatial = ContentType.objects.get( app_label='spatial', model='spatialunit') content_type_tenure = ContentType.objects.get( app_label='party', model='tenurerelationship') for content_type in [content_type_party, content_type_tenure, content_type_spatial]: schema = Schema.objects.create( content_type=content_type, selectors=(self.project.organization.id, self.project.id, 'a1') ) attr_type = AttributeType.objects.get(name='boolean') Attribute.objects.create( schema=schema, name='fname', long_name='True or False', attr_type=attr_type, index=0, required=False, omit=False ) attr_type = AttributeType.objects.get(name='text') Attribute.objects.create( schema=schema, name='fname_two', long_name='Notes', attr_type=attr_type, index=1, required=False, omit=False ) OrganizationRole.objects.create( user=self.user, organization=self.project.organization)
def test_create_from_invald_form_missing_relevant_clause(self): create_attribute_types() file = self.get_file( '/questionnaires/tests/files/' 't_questionnaire_missing_relevant.xlsx', 'rb') form = self.storage.save( 'xls-forms/t_questionnaire_missing_relevant.xlsx', file.read()) file.close() with pytest.raises(InvalidQuestionnaire) as e: models.Questionnaire.objects.create_from_form( xls_form=form, project=ProjectFactory.create()) assert MISSING_RELEVANT in e.value.errors assert models.Questionnaire.objects.exists() is False assert models.QuestionGroup.objects.exists() is False assert models.Question.objects.exists() is False
def setUp(self): super().setUp() PolicyFactory.load_policies() create_attribute_types() load_tenure_relationship_types(force=True)
def run(force=False): if force: AttributeType.objects.all().delete() create_attribute_types()
def setUp(self): super().setUp() PolicyFactory.load_policies() create_attribute_types()
def test_get_context_xlang(self): models.create_attribute_types() org = factories.OrganizationFactory.create() project = factories.ProjectFactory.create(organization=org) content_type = ContentType.objects.get( app_label='tests', model='party') schema1 = models.Schema.objects.create( content_type=content_type, selectors=(org.id, project.id), default_language='en') models.Attribute.objects.create( schema=schema1, name='field_1', long_name={'en': 'Field 1', 'de': 'Feld 1'}, attr_type=models.AttributeType.objects.get(name='text'), index=0 ) models.Attribute.objects.create( schema=schema1, name='field_2', long_name={'en': 'Field 2', 'de': 'Feld 2'}, attr_type=models.AttributeType.objects.get(name='text'), index=1 ) models.Attribute.objects.create( schema=schema1, name='field_3', long_name={'en': 'Field 3', 'de': 'Feld 3'}, attr_type=models.AttributeType.objects.get(name='select_multiple'), choices=['one', 'two', 'three'], choice_labels=[{'en': 'Choice 1', 'de': 'Wahl 1'}, {'en': 'Choice 2', 'de': 'Wahl 2'}, {'en': 'Choice 3', 'de': 'Wahl 3'}], index=2, ) models.Attribute.objects.create( schema=schema1, name='field_4', long_name={'en': 'Field 4', 'de': 'Feld 4'}, attr_type=models.AttributeType.objects.get(name='select_one'), choices=['one', 'two', 'three'], choice_labels=[{'en': 'Choice 1', 'de': 'Wahl 1'}, {'en': 'Choice 2', 'de': 'Wahl 2'}, {'en': 'Choice 3', 'de': 'Wahl 3'}], index=3, ) party = factories.PartyFactory.create( project=project, attrs={'field_1': 'Some value', 'field_3': ['one', 'three'], 'field_4': 'two'} ) view = JsonAttrsView() view.object = party context = view.get_context_data() assert len(context['attrs']) == 4 field_1 = context['attrs'][0] assert field_1[0] == 'Field 1' assert field_1[1] == 'Some value' assert 'data-label-en="Field 1"' in field_1[2] assert 'data-label-de="Feld 1"' in field_1[2] field_2 = context['attrs'][1] assert field_2[0] == 'Field 2' assert field_2[1] == '—' assert 'data-label-en="Field 2"' in field_2[2] assert 'data-label-de="Feld 2"' in field_2[2] field_3 = context['attrs'][2] assert field_3[0] == 'Field 3' assert field_3[1] == 'Choice 1, Choice 3' assert 'data-label-en="Field 3"' in field_3[2] assert 'data-label-de="Feld 3"' in field_3[2] assert 'data-label-en="Choice 1, Choice 3"' in field_3[3] assert 'data-label-de="Wahl 1, Wahl 3"' in field_3[3] field_4 = context['attrs'][3] assert field_4[0] == 'Field 4' assert field_4[1] == 'Choice 2' assert 'data-label-en="Field 4"' in field_4[2] assert 'data-label-de="Feld 4"' in field_4[2] assert 'data-label-en="Choice 2"' in field_4[3] assert 'data-label-de="Wahl 2"' in field_4[3]