def test_record_to_dict_sets_id_correctly(self):
        handle = "SG_abcdefghijklmnopqrstuv"
        record_id = "this is my record #1. my first record. and it is mine"
        rec = Feature(coordinates=(D("11.03"), D("10.03")), simplegeohandle=handle, properties={"record_id": record_id})
        dic = rec.to_dict()
        self.failUnlessEqual(dic.get("id"), handle)
        self.failUnlessEqual(dic.get("properties", {}).get("record_id"), record_id)

        rec = Feature(coordinates=(D("11.03"), D("10.03")), simplegeohandle=handle, properties={"record_id": None})
        dic = rec.to_dict()
        self.failUnlessEqual(dic.get("id"), handle)
        self.failUnlessEqual(dic.get("properties", {}).get("record_id"), None)

        rec = Feature(coordinates=(D("11.03"), D("10.03")), simplegeohandle=handle, properties={"record_id": None})
        dic = rec.to_dict()
        self.failUnlessEqual(dic.get("id"), handle)
        self.failUnlessEqual(dic.get("properties", {}).get("record_id"), None)

        rec = Feature(coordinates=(D("11.03"), D("10.03")), simplegeohandle=None, properties={"record_id": None})
        dic = rec.to_dict()
        self.failUnlessEqual(dic.get("id"), None)
        self.failUnlessEqual(dic.get("properties", {}).get("record_id"), None)
    def test_record_to_dict_sets_id_correctly(self):
        handle = 'SG_abcdefghijklmnopqrstuv'
        record_id = 'this is my record #1. my first record. and it is mine'
        rec = Feature(coordinates=(D('11.03'), D('10.03')), simplegeohandle=handle, properties={'record_id': record_id})
        dic = rec.to_dict()
        self.failUnlessEqual(dic.get('id'), handle)
        self.failUnlessEqual(dic.get('properties', {}).get('record_id'), record_id)

        rec = Feature(coordinates=(D('11.03'), D('10.03')), simplegeohandle=handle, properties={'record_id': None})
        dic = rec.to_dict()
        self.failUnlessEqual(dic.get('id'), handle)
        self.failUnlessEqual(dic.get('properties', {}).get('record_id'), None)

        rec = Feature(coordinates=(D('11.03'), D('10.03')), simplegeohandle=handle, properties={'record_id': None})
        dic = rec.to_dict()
        self.failUnlessEqual(dic.get('id'), handle)
        self.failUnlessEqual(dic.get('properties', {}).get('record_id'), None)

        rec = Feature(coordinates=(D('11.03'), D('10.03')), simplegeohandle=None, properties={'record_id': None})
        dic = rec.to_dict()
        self.failUnlessEqual(dic.get('id'), None)
        self.failUnlessEqual(dic.get('properties', {}).get('record_id'), None)
    def test_record_constructor(self):
        self.failUnlessRaises(AssertionError, Feature, D("11.0"), D("10.0"), properties={"record_id": "my_id"})

        # lat exceeds bound
        self.failUnlessRaises(AssertionError, Feature, (D("91.0"), D("10.1")), properties={"record_id": "my_id"})

        # lon exceeds bound
        self.failUnlessRaises(AssertionError, Feature, (D("10.1"), D("180.1")), properties={"record_id": "my_id"})

        record = Feature(coordinates=(D("11.0"), D("10.0")), properties={"record_id": "my_id"})
        self.failUnlessEqual(record.properties.get("record_id"), "my_id")
        self.failUnlessEqual(record.id, None)
        self.failUnlessEqual(record.geomtype, "Point")
        self.failUnlessEqual(record.coordinates[0], D("11.0"))
        self.failUnlessEqual(record.coordinates[1], D("10.0"))

        record = Feature(coordinates=(D("11.0"), D("10.0")), simplegeohandle="SG_abcdefghijklmnopqrstuv")
        self.failUnlessEqual(record.properties.get("record_id"), None)
        self.failUnlessEqual(record.id, "SG_abcdefghijklmnopqrstuv")

        record = Feature(
            coordinates=(D("11.0"), D("10.0")),
            properties={"record_id": "my_id"},
            simplegeohandle="SG_abcdefghijklmnopqrstuv",
        )
        self.failUnlessEqual(record.properties.get("record_id"), "my_id")
        self.failUnlessEqual(record.id, "SG_abcdefghijklmnopqrstuv")

        record = Feature(coordinates=(D("11.0"), D("10.0")))
        self.failUnlessEqual(record.properties.get("record_id"), None)
        self.failUnlessEqual(record.id, None)

        record = Feature((D("11.0"), D("10.0")), properties={"record_id": "my_id"})
        self.failUnlessEqual(record.properties.get("record_id"), "my_id")

        record = Feature((11.0, 10.0), properties={"record_id": "my_id"})
        self.failUnlessEqual(record.geomtype, "Point")
        self.failUnlessEqual(record.coordinates[0], 11.0)
        self.failUnlessEqual(record.coordinates[1], 10.0)
        self.failUnlessEqual(record.properties.get("record_id"), "my_id")

        record = Feature([[(11.0, 179.9), (12, -179.9)]], geomtype="Polygon")
        self.failUnlessEqual(record.geomtype, "Polygon")
        self.failUnlessEqual(len(record.coordinates[0]), 2)
        self.failUnlessEqual(record.coordinates[0][0], (11.0, 179.9))

        jsondict = record.to_dict()
        self.failUnlessEqual(jsondict["geometry"]["coordinates"][0][0], (179.9, 11.0))
    def test_record_constructor(self):
        self.failUnlessRaises(TypeError, Feature, D('11.0'), D('10.0'), properties={'record_id': 'my_id'})

        # lat exceeds bound
        self.failUnlessRaises(TypeError, Feature, (D('91.0'), D('10.1')), properties={'record_id': 'my_id'})

        # lon exceeds bound
        self.failUnlessRaises(TypeError, Feature, (D('10.1'), D('180.1')), properties={'record_id': 'my_id'}, strict_lon_validation=True)

        record = Feature(coordinates=(D('11.0'), D('10.0')), properties={'record_id': 'my_id'})
        self.failUnlessEqual(record.properties.get('record_id'), 'my_id')
        self.failUnlessEqual(record.id, None)
        self.failUnlessEqual(record.geomtype, 'Point')
        self.failUnlessEqual(record.coordinates[0], D('11.0'))
        self.failUnlessEqual(record.coordinates[1], D('10.0'))

        record = Feature(coordinates=(D('11.0'), D('10.0')), simplegeohandle='SG_abcdefghijklmnopqrstuv')
        self.failUnlessEqual(record.properties.get('record_id'), None)
        self.failUnlessEqual(record.id, 'SG_abcdefghijklmnopqrstuv')

        record = Feature(coordinates=(D('11.0'), D('10.0')), properties={'record_id': 'my_id'}, simplegeohandle='SG_abcdefghijklmnopqrstuv')
        self.failUnlessEqual(record.properties.get('record_id'), 'my_id')
        self.failUnlessEqual(record.id, 'SG_abcdefghijklmnopqrstuv')

        record = Feature(coordinates=(D('11.0'), D('10.0')))
        self.failUnlessEqual(record.properties.get('record_id'), None)
        self.failUnlessEqual(record.id, None)

        record = Feature((D('11.0'), D('10.0')), properties={'record_id': 'my_id'})
        self.failUnlessEqual(record.properties.get('record_id'), 'my_id')

        record = Feature((11.0, 10.0), properties={'record_id': 'my_id'})
        self.failUnlessEqual(record.geomtype, 'Point')
        self.failUnlessEqual(record.coordinates[0], 11.0)
        self.failUnlessEqual(record.coordinates[1], 10.0)
        self.failUnlessEqual(record.properties.get('record_id'), 'my_id')

        record = Feature([[(11.0, 179.9), (12, -179.9)]], geomtype='Polygon')
        self.failUnlessEqual(record.geomtype, 'Polygon')
        self.failUnlessEqual(len(record.coordinates[0]), 2)
        self.failUnlessEqual(record.coordinates[0][0], (11.0, 179.9))

        jsondict = record.to_dict()
        self.failUnlessEqual(jsondict['geometry']['coordinates'][0][0], (179.9, 11.))