Exemple #1
0
    async def test_point_field_save_and_load(self):
        loc = Location(point=[30.5233, 50.45])
        await loc.save()
        ok_(loc._id is not None)

        loc2 = await Location.objects.get(id=loc._id)
        eq_(loc2.point['type'], 'Point')
        eq_(len(loc2.point['coordinates']), 2)
        almost_eq_(loc2.point['coordinates'][0], 30.5233, places=4)
        almost_eq_(loc2.point['coordinates'][1], 50.45, places=2)
        ok_(loc2.validate())
    async def test_point_field_save_and_load(self):
        loc = Location(point=[30.5233, 50.45])
        await loc.save()
        ok_(loc._id is not None)

        loc2 = await Location.objects.get(id=loc._id)
        eq_(loc2.point['type'], 'Point')
        eq_(len(loc2.point['coordinates']), 2)
        almost_eq_(loc2.point['coordinates'][0], 30.5233, places=4)
        almost_eq_(loc2.point['coordinates'][1], 50.45, places=2)
        ok_(loc2.validate())
    def test_point_field_to_son(self):
        loc = Location(
            point={
                'type': 'Point',
                'coordinates': [30.5233, 50.45]
            }
        )
        son = loc.to_son()
        ok_(isinstance(son, dict))
        ok_(isinstance(son['point'], dict))
        son = son['point']
        eq_(son['type'], 'Point')
        eq_(len(son['coordinates']), 2)
        almost_eq_(son['coordinates'][0], 30.5233, places=4)
        almost_eq_(son['coordinates'][1], 50.45, places=2)

        loc2 = Location(point=[30.5233, 50.45])
        son = loc2.to_son()
        ok_(isinstance(son, dict))
        ok_(isinstance(son['point'], dict))
        son = son['point']
        eq_(son['type'], 'Point')
        eq_(len(son['coordinates']), 2)
        almost_eq_(son['coordinates'][0], 30.5233, places=4)
        almost_eq_(son['coordinates'][1], 50.45, places=2)
    async def test_line_string_field_save_and_load(self):
        loc = Location(
            line=[
                (30.5233, 50.45),
                [31.5233, 51.45],
                [32.5233, 51.45]
            ]
        )
        await loc.save()
        ok_(loc._id is not None)

        loc2 = await Location.objects.get(id=loc._id)
        ok_(loc2.line2 is None)
        eq_(loc2.line['type'], 'LineString')
        eq_(len(loc2.line['coordinates']), 3)
        almost_eq_(loc2.line['coordinates'][0][1], 50.45, places=2)
        almost_eq_(loc2.line['coordinates'][1][0], 31.5233, places=4)
        ok_(loc2.validate())
Exemple #5
0
    async def test_polygon_field_save_and_load(self):
        loc = Location(
            polygon={
                'type': 'Polygon',
                'coordinates': [
                    [
                        [30.5233, 50.45], [30.5233, 51.45],
                        [31.5233, 51.45], [30.5233, 50.45]
                    ]
                ]
            }
        )
        await loc.save()
        ok_(loc._id is not None)

        loc2 = await Location.objects.get(id=loc._id)
        ok_(loc2.polygon2 is None)
        eq_(loc2.polygon['type'], 'Polygon')
        eq_(len(loc2.polygon['coordinates']), 1)
        almost_eq_(loc2.polygon['coordinates'][0][0][0], 30.5233, places=4)
        almost_eq_(loc2.polygon['coordinates'][0][2][1], 51.45, places=2)
        ok_(loc2.validate())
Exemple #6
0
    def test_create_document_with_point_field(self):
        loc = Location(point={
            'type': 'Point',
            'coordinates': [30.5233, 50.45]
        })
        ok_(loc.point2 is None)
        eq_(loc.point['type'], 'Point')
        eq_(len(loc.point['coordinates']), 2)
        almost_eq_(loc.point['coordinates'][0], 30.5233, places=4)
        almost_eq_(loc.point['coordinates'][1], 50.45, places=2)
        ok_(loc.validate())

        loc2 = Location(point=[30.5233, 50.45])
        eq_(loc2.point['type'], 'Point')
        eq_(len(loc2.point['coordinates']), 2)
        almost_eq_(loc2.point['coordinates'][0], 30.5233, places=4)
        almost_eq_(loc2.point['coordinates'][1], 50.45, places=2)
        ok_(loc2.validate())

        loc3 = Location(point=[30.5233, 50.45])
        ok_(loc3.validate())
    def test_create_document_with_line_string_field(self):
        loc = Location(
            line={
                'type': 'LineString',
                'coordinates': [
                    (30.5233, 50.45),
                    [31.5233, 51.45],
                    [32.5233, 51.45]
                ]
            }
        )
        ok_(loc.line2 is None)
        eq_(loc.line['type'], 'LineString')
        eq_(len(loc.line['coordinates']), 3)
        almost_eq_(loc.line['coordinates'][0][1], 50.45, places=2)
        almost_eq_(loc.line['coordinates'][1][0], 31.5233, places=4)
        ok_(loc.validate())

        loc2 = Location(
            line=[
                (30.5233, 50.45),
                [31.5233, 51.45],
                [32.5233, 51.45]
            ]
        )
        ok_(loc2.line2 is None)
        eq_(loc2.line['type'], 'LineString')
        eq_(len(loc2.line['coordinates']), 3)
        almost_eq_(loc2.line['coordinates'][0][1], 50.45, places=2)
        almost_eq_(loc2.line['coordinates'][1][0], 31.5233, places=4)
        ok_(loc2.validate())

        loc3 = Location(
            line=[
                (30.5233, 50.45),
                [31.5233, 51.45],
                [32.5233, 51.45]
            ]
        )
        ok_(loc3.validate())
Exemple #8
0
    def test_create_document_with_polygon_field(self):
        loc = Location(
            polygon={
                'type': 'Polygon',
                'coordinates': [
                    [
                        [30.5233, 50.45], [30.5233, 51.45],
                        [31.5233, 51.45], [30.5233, 50.45]
                    ]
                ]
            }
        )
        ok_(loc.polygon2 is None)
        eq_(loc.polygon['type'], 'Polygon')
        eq_(len(loc.polygon['coordinates']), 1)
        almost_eq_(loc.polygon['coordinates'][0][0][0], 30.5233, places=4)
        almost_eq_(loc.polygon['coordinates'][0][2][1], 51.45, places=2)
        ok_(loc.validate())

        loc2 = Location(polygon=[
            [
                [30.5233, 50.45], [30.5233, 51.45],
                [31.5233, 51.45], [30.5233, 50.45]
            ]
        ])
        ok_(loc2.polygon2 is None)
        eq_(loc2.polygon['type'], 'Polygon')
        eq_(len(loc2.polygon['coordinates']), 1)
        almost_eq_(loc2.polygon['coordinates'][0][0][0], 30.5233, places=4)
        almost_eq_(loc2.polygon['coordinates'][0][2][1], 51.45, places=2)
        ok_(loc2.validate())

        loc3 = Location(polygon=[
            [
                [30.5233, 50.45], [30.5233, 51.45],
                [31.5233, 51.45], [30.5233, 50.45]
            ]
        ])
        ok_(loc3.validate())
    def test_create_document_with_point_field(self):
        loc = Location(
            point={
                'type': 'Point',
                'coordinates': [30.5233, 50.45]
            }
        )
        ok_(loc.point2 is None)
        eq_(loc.point['type'], 'Point')
        eq_(len(loc.point['coordinates']), 2)
        almost_eq_(loc.point['coordinates'][0], 30.5233, places=4)
        almost_eq_(loc.point['coordinates'][1], 50.45, places=2)
        ok_(loc.validate())

        loc2 = Location(point=[30.5233, 50.45])
        eq_(loc2.point['type'], 'Point')
        eq_(len(loc2.point['coordinates']), 2)
        almost_eq_(loc2.point['coordinates'][0], 30.5233, places=4)
        almost_eq_(loc2.point['coordinates'][1], 50.45, places=2)
        ok_(loc2.validate())

        loc3 = Location(point=[30.5233, 50.45])
        ok_(loc3.validate())
Exemple #10
0
    def test_point_field_to_son(self):
        loc = Location(point={
            'type': 'Point',
            'coordinates': [30.5233, 50.45]
        })
        son = loc.to_son()
        ok_(isinstance(son, dict))
        ok_(isinstance(son['point'], dict))
        son = son['point']
        eq_(son['type'], 'Point')
        eq_(len(son['coordinates']), 2)
        almost_eq_(son['coordinates'][0], 30.5233, places=4)
        almost_eq_(son['coordinates'][1], 50.45, places=2)

        loc2 = Location(point=[30.5233, 50.45])
        son = loc2.to_son()
        ok_(isinstance(son, dict))
        ok_(isinstance(son['point'], dict))
        son = son['point']
        eq_(son['type'], 'Point')
        eq_(len(son['coordinates']), 2)
        almost_eq_(son['coordinates'][0], 30.5233, places=4)
        almost_eq_(son['coordinates'][1], 50.45, places=2)
    def test_line_string_field_to_son(self):
        loc = Location(
            line={
                'type': 'LineString',
                'coordinates': [
                    (30.5233, 50.45),
                    [31.5233, 51.45],
                    [32.5233, 51.45]
                ]
            }
        )
        son = loc.to_son()
        ok_(isinstance(son, dict))
        ok_(isinstance(son['line'], dict))
        son = son['line']
        eq_(son['type'], 'LineString')
        eq_(len(son['coordinates']), 3)
        almost_eq_(son['coordinates'][0][1], 50.45, places=2)
        almost_eq_(son['coordinates'][1][0], 31.5233, places=4)

        loc2 = Location(
            line=[
                (30.5233, 50.45),
                [31.5233, 51.45],
                [32.5233, 51.45]
            ]
        )

        son = loc2.to_son()
        ok_(isinstance(son, dict))
        ok_(isinstance(son['line'], dict))
        son = son['line']
        eq_(son['type'], 'LineString')
        eq_(len(son['coordinates']), 3)
        almost_eq_(son['coordinates'][0][1], 50.45, places=2)
        almost_eq_(son['coordinates'][1][0], 31.5233, places=4)
Exemple #12
0
    def test_polygon_field_to_son(self):
        loc = Location(
            polygon={
                'type': 'Polygon',
                'coordinates': [
                    [
                        [30.5233, 50.45], [30.5233, 51.45],
                        [31.5233, 51.45], [30.5233, 50.45]
                    ]
                ]
            }
        )
        son = loc.to_son()
        ok_(isinstance(son, dict))
        ok_(isinstance(son['polygon'], dict))
        son = son['polygon']
        eq_(son['type'], 'Polygon')
        eq_(len(son['coordinates']), 1)
        almost_eq_(son['coordinates'][0][0][0], 30.5233, places=4)
        almost_eq_(son['coordinates'][0][2][1], 51.45, places=2)

        loc2 = Location(polygon=[
            [
                [30.5233, 50.45], [30.5233, 51.45],
                [31.5233, 51.45], [30.5233, 50.45]
            ]
        ])

        son = loc2.to_son()
        ok_(isinstance(son, dict))
        ok_(isinstance(son['polygon'], dict))
        son = son['polygon']
        eq_(son['type'], 'Polygon')
        eq_(len(son['coordinates']), 1)
        almost_eq_(son['coordinates'][0][0][0], 30.5233, places=4)
        almost_eq_(son['coordinates'][0][2][1], 51.45, places=2)