def test_traversing_merged_spatial_unit(self):
        relationship = SpatialRelationshipFactory(su1__type='BU',
                                                  su2__type='AP',
                                                  type='M')
        su1_merged_from = str(relationship.su1.relationships.all()[0])
        su2_merged_into = str(relationship.su2.relationships_set.all()[0])

        assert relationship.get_type_display() == 'is-merge-of'
        assert su1_merged_from == '<SpatialUnit: Apartment>'
        assert su2_merged_into == '<SpatialUnit: Building>'
    def test_traversing_contained_spatial_unit(self):
        relationship = SpatialRelationshipFactory(su1__type='BU',
                                                  su2__type='AP',
                                                  type='C')
        su1_contains = str(relationship.su1.relationships.all()[0])
        su2_is_contained_in = str(relationship.su2.relationships_set.all()[0])

        assert relationship.get_type_display() == 'is-contained-in'
        assert su1_contains == '<SpatialUnit: Apartment>'
        assert su2_is_contained_in == '<SpatialUnit: Building>'
Example #3
0
    def test_traversing_merged_spatial_unit(self):
        relationship = SpatialRelationshipFactory(
            su1__type='BU',
            su2__type='AP',
            type='M')
        su1_merged_from = str(relationship.su1.relationships.all()[0])
        su2_merged_into = str(relationship.su2.relationships_set.all()[0])

        assert relationship.get_type_display() == 'is-merge-of'
        assert su1_merged_from == '<SpatialUnit: Apartment>'
        assert su2_merged_into == '<SpatialUnit: Building>'
Example #4
0
    def test_traversing_contained_spatial_unit(self):
        relationship = SpatialRelationshipFactory(
            su1__type='BU',
            su2__type='AP',
            type='C')
        su1_contains = str(relationship.su1.relationships.all()[0])
        su2_is_contained_in = str(relationship.su2.relationships_set.all()[0])

        assert relationship.get_type_display() == 'is-contained-in'
        assert su1_contains == '<SpatialUnit: Apartment>'
        assert su2_is_contained_in == '<SpatialUnit: Building>'
 def test_spatial_relationship_invalid_attribute(self):
     project = ProjectFactory.create(name='TestProject')
     QuestionnaireFactory.create(project=project)
     content_type = ContentType.objects.get(app_label='spatial',
                                            model='spatialrelationship')
     create_attrs_schema(project=project,
                         dict=location_relationship_xform_group,
                         content_type=content_type,
                         errors=[])
     assert 1 == Schema.objects.all().count()
     with pytest.raises(KeyError):
         SpatialRelationshipFactory.create(project=project,
                                           attributes={
                                               'invalid_attribute': 'yes',
                                           })
 def test_project_relationship_invalid(self):
     with pytest.raises(exceptions.ProjectRelationshipError):
         project = ProjectFactory()
         SpatialRelationshipFactory(
             su1__project=project,
             su2__project=project
         )
 def test_spatial_relationship_invalid_attribute(self):
     project = ProjectFactory.create(name='TestProject')
     QuestionnaireFactory.create(project=project)
     content_type = ContentType.objects.get(
         app_label='spatial', model='spatialrelationship')
     create_attrs_schema(
         project=project, dict=location_relationship_xform_group,
         content_type=content_type, errors=[])
     assert 1 == Schema.objects.all().count()
     with pytest.raises(KeyError):
         SpatialRelationshipFactory.create(
             project=project,
             attributes={
                 'invalid_attribute': 'yes',
             }
         )
 def test_relationships_creation(self):
     relationship = SpatialRelationshipFactory(project=self.project,
                                               su1__project=self.project,
                                               su1__type='PA',
                                               su2__project=self.project,
                                               su2__type='CB')
     su2_type = str(relationship.su1.relationships.all()[0])
     assert su2_type == '<SpatialUnit: Community boundary>'
 def test_str(self):
     relationship = SpatialRelationshipFactory(project=self.project,
                                               su1__project=self.project,
                                               su1__type='PA',
                                               su2__project=self.project,
                                               su2__type='CB',
                                               type='C')
     assert str(relationship) == (
         "<SpatialRelationship: "
         "<Parcel> is-contained-in <Community boundary>>")
Example #10
0
 def test_repr(self):
     project = ProjectFactory.build(slug='prj')
     su1 = SpatialUnitFactory.build(type='PA', id='abc123', project=project)
     su2 = SpatialUnitFactory.build(type='PA', id='def456', project=project)
     relationship = SpatialRelationshipFactory.build(id='abc123',
                                                     project=project,
                                                     su1=su1,
                                                     su2=su2,
                                                     type='C')
     assert repr(relationship) == ('<SpatialRelationship id=abc123'
                                   ' project=prj su1=abc123 su2=def456'
                                   ' type=C>')
Example #11
0
 def test_repr(self):
     project = ProjectFactory.build(slug='prj')
     su1 = SpatialUnitFactory.build(type='PA', id='abc123', project=project)
     su2 = SpatialUnitFactory.build(type='PA', id='def456', project=project)
     relationship = SpatialRelationshipFactory.build(
         id='abc123',
         project=project,
         su1=su1,
         su2=su2,
         type='C')
     assert repr(relationship) == ('<SpatialRelationship id=abc123'
                                   ' project=prj su1=abc123 su2=def456'
                                   ' type=C>')
Example #12
0
 def test_spatial_unit_does_not_contain_point(self):
     with pytest.raises(Exception):
         SpatialRelationshipFactory(su1__type='BU',
                                    su1__geometry='SRID=4326;POLYGON(('
                                    '-109.0461 40.2617, '
                                    '-108.6039 40.2459,'
                                    '-108.3966 40.3831, '
                                    '-108.4309 40.6108, '
                                    '-108.8841 40.7836, '
                                    '-109.0434 40.8657, '
                                    '-109.0461 40.2617))',
                                    su2__type='AP',
                                    su2__geometry='SRID=4326;POINT('
                                    '-108.0972 40.9508)',
                                    type='C')
    def test_adding_attributes(self):
        # add attribute schema
        content_type = ContentType.objects.get(
            app_label='spatial', model='spatialrelationship')
        sch = Schema.objects.create(content_type=content_type, selectors=())
        attr_type = AttributeType.objects.get(name="text")
        Attribute.objects.create(
            schema=sch, name='test', long_name='Test',
            required=False, index=1, attr_type=attr_type
        )
        relationship = SpatialRelationshipFactory(
            su1__type='BU',
            su2__type='AP',
            attributes={'test': 'Partner amusement parks.'})

        assert relationship.attributes['test'] == 'Partner amusement parks.'
Example #14
0
 def test_spatial_unit_point_contains_relationship_still_created(self):
     relationship = SpatialRelationshipFactory(
         su1__type='BU',
         su1__geometry='SRID=4326;POINT('
         '-108.7536 40.5054)',
         su2__type='AP',
         su2__geometry='SRID=4326;POLYGON(('
         '-109.0461 40.2617, '
         '-108.6039 40.2459,'
         '-108.3966 40.3831, '
         '-108.4309 40.6108, '
         '-108.8841 40.7836, '
         '-109.0434 40.8657, '
         '-109.0461 40.2617))',
         type='C')
     assert relationship is not None
Example #15
0
 def test_spatial_unit_does_not_contain_anothers_geometry(self):
     with pytest.raises(Exception):
         SpatialRelationshipFactory(su1__type='BU',
                                    su1__geometry='SRID=4326;POLYGON(('
                                    '-91.9960 34.7850, '
                                    '-91.9960 34.8016, '
                                    '-91.9785 34.8016, '
                                    '-91.9785 34.7850, '
                                    '-91.9960 34.7850))',
                                    su2__type='AP',
                                    su2__geometry='SRID=4326;POLYGON(('
                                    '11.36667 47.25000, '
                                    '11.41667 47.25000, '
                                    '11.41667 47.28333, '
                                    '11.36667 47.28333, '
                                    '11.36667 47.25000))',
                                    type='C')
Example #16
0
 def test_spatial_relationship_schema(self):
     project = ProjectFactory.create(name='TestProject')
     QuestionnaireFactory.create(project=project)
     content_type = ContentType.objects.get(
         app_label='spatial', model='spatialrelationship')
     create_attrs_schema(
         project=project, dict=location_relationship_xform_group,
         content_type=content_type, errors=[])
     sur = SpatialRelationshipFactory.create(
         project=project, attributes={
             'notes': 'Some additional textual info'}
     )
     assert 1 == Schema.objects.all().count()
     schema = Schema.objects.get(content_type=content_type)
     assert schema is not None
     assert schema.selectors == [
         project.organization.pk, project.pk, project.current_questionnaire]
     assert 'notes' in sur.attributes.attributes
 def test_spatial_relationship_schema(self):
     project = ProjectFactory.create(name='TestProject')
     QuestionnaireFactory.create(project=project)
     content_type = ContentType.objects.get(
         app_label='spatial', model='spatialrelationship')
     create_attrs_schema(
         project=project, dict=location_relationship_xform_group,
         content_type=content_type, errors=[])
     sur = SpatialRelationshipFactory.create(
         project=project, attributes={
             'notes': 'Some additional textual info'}
     )
     assert 1 == Schema.objects.all().count()
     schema = Schema.objects.get(content_type=content_type)
     assert schema is not None
     assert schema.selectors == [
         project.organization.pk, project.pk, project.current_questionnaire]
     assert 'notes' in sur.attributes.attributes
Example #18
0
 def test_relationship_fails_if_contained_unit_expands_outside_parent(self):
     with pytest.raises(Exception):
         SpatialRelationshipFactory(su1__type='BU',
                                    su2__geometry='SRID=4326;POLYGON(('
                                    '-91.9947 34.7994, '
                                    '-91.9950 34.7846, '
                                    '-92.0000 34.7798, '
                                    '-92.0032 34.7644, '
                                    '-91.9174 34.7627, '
                                    '-91.9153 34.8032, '
                                    '-91.9947 34.7994))',
                                    su2__type='AP',
                                    su1__geometry='SRID=4326;POLYGON(('
                                    '-91.9320 34.7918, '
                                    '-91.9335 34.7846, '
                                    '-91.9176 34.7846, '
                                    '-91.9167 34.7915, '
                                    '-91.9320 34.7918))',
                                    type='C')
Example #19
0
 def test_spatial_unit_contains_anothers_geometry(self):
     relationship = SpatialRelationshipFactory(
         su1__type='BU',
         su1__geometry='SRID=4326;POLYGON(('
         '-91.9947 34.7994, '
         '-91.9950 34.7846, '
         '-92.0000 34.7798, '
         '-92.0032 34.7644, '
         '-91.9174 34.7627, '
         '-91.9153 34.8032, '
         '-91.9947 34.7994))',
         su2__type='AP',
         su2__geometry='SRID=4326;POLYGON(('
         '-91.9320 34.7918, '
         '-91.9335 34.7846, '
         '-91.9176 34.7846, '
         '-91.9167 34.7915, '
         '-91.9320 34.7918))',
         type='C')
     assert relationship is not None
Example #20
0
 def test_left_and_right_project_ids(self):
     with pytest.raises(exceptions.ProjectRelationshipError):
         project = ProjectFactory()
         SpatialRelationshipFactory(su1__project=project)
Example #21
0
    def test_relationship_type(self):
        relationship = SpatialRelationshipFactory(type='S')

        assert relationship.type == 'S'
        assert relationship.get_type_display() == 'is-split-of'
Example #22
0
    def add_test_spatial_units(self):
        project = models.Project.objects.get(
            name__contains='Pekapuran Laut Test Project')

        # add attribute schema
        content_type = ContentType.objects.get(app_label='spatial',
                                               model='spatialunit')
        sch = Schema.objects.create(content_type=content_type,
                                    selectors=(project.organization.pk,
                                               project.pk))
        attr_type = AttributeType.objects.get(name="text")
        Attribute.objects.create(schema=sch,
                                 name='name',
                                 long_name='Name',
                                 required=False,
                                 index=1,
                                 attr_type=attr_type)

        su1 = SpatialUnitFactory(geometry=GEOSGeometry(
            '{"type": "Polygon",'
            '"coordinates": [['
            '[-245.3920519351959, -3.3337982265513184],'
            '[-245.39097905158997,  -3.333284113800722],'
            '[-245.39072155952454, -3.3345908165153215],'
            '[-245.39169788360596, -3.3351691925723728],'
            '[-245.3920519351959, -3.3337982265513184]]]'
            '}'),
                                 project=project,
                                 type='BU',
                                 attributes={'name': 'Building Unit (Test)'})

        su2 = SpatialUnitFactory(geometry=GEOSGeometry(
            '{"type": "Polygon",'
            '"coordinates": [['
            '[-245.39200901985168,  -3.333808937230755],'
            '[-245.39147257804868, -3.3335304595272377],'
            '[-245.391343832016, -3.3340338614721934],'
            '[-245.39186954498288, -3.3342480749876575],'
            '[-245.39200901985168,  -3.333808937230755]]'
            ']}'),
                                 project=project,
                                 type='AP',
                                 attributes={"name": "Apartment Unit (Test)"})

        SpatialRelationshipFactory(su1=su1, su2=su2, type='C', project=project)

        su3 = SpatialUnitFactory(geometry=GEOSGeometry(
            '{"type": "Polygon",'
            '"coordinates": [['
            '[-245.39088249206543,  -3.333262692430284],'
            '[-245.39021730422974, -3.3330699000753414],'
            '[-245.39001345634458,  -3.334312339033184],'
            '[-245.39063572883606,  -3.334580105844384],'
            '[-245.39088249206543,  -3.333262692430284]]'
            ']}'),
                                 project=project,
                                 type='PA',
                                 attributes={
                                     'name': 'Parcel (Test)',
                                 })

        su4 = SpatialUnitFactory(geometry=GEOSGeometry(
            '{"type": "Point",'
            '"coordinates": ['
            '-245.39034605026242, -3.333294824485769]}'),
                                 project=project,
                                 type='PA')

        SpatialRelationshipFactory(su1=su3, su2=su4, type='C', project=project)

        SpatialUnitFactory(geometry=GEOSGeometry(
            '{"type": "LineString",'
            '"coordinates": ['
            '[-245.3934037685394, -3.334258785662196],'
            '[-245.39109706878662, -3.3331984283161726],'
            '[-245.3895306587219, -3.3328342649235454]]}'),
                           project=project,
                           type='RW')

        SpatialUnitFactory(geometry=GEOSGeometry(
            '{"type": "Point",'
            '"coordinates": ['
            '-245.39366126060483, -3.334130257559935]}'),
                           project=project,
                           type='MI',
                           attributes={"name": 'Uncontained Point (Test)'})

        SpatialUnitFactory(
            geometry=GEOSGeometry('{"type": "Point",'
                                  '"coordinates": ['
                                  '-4.9383544921875,'
                                  '7.833452408875349'
                                  ']}'),
            project=models.Project.objects.get(name='Kibera Test Project'),
            type='MI',
            attributes={})
Example #23
0
    def test_relationship_type(self):
        relationship = SpatialRelationshipFactory(type='S')

        assert relationship.type == 'S'
        assert relationship.get_type_display() == 'is-split-of'