示例#1
0
    def synchronize(url=XML_URL_DATA_STATION):
        dom = parseString(Grabber(url).content)
        for marker in dom.getElementsByTagName('marker'):
            values = xml_station_information_wrapper(marker)
            StationInformation.update_or_create(values, surrogate=False)

        session.commit()
示例#2
0
    def test_UpdateOrCreate(self):
        self.assertEquals(StationInformation.query.count(), 0)

        values = {
            "id": 42,
            "address": "1 rue Kennedy",
            "postal_code": "94200",
            "city": "Paris",
            "lat": "42.000000000",
            "lng": "42.000000000",
            "opened": True,
            "bonus": False,
        }
        station = StationInformation.update_or_create(values, surrogate=False)
        self.assertEquals(StationInformation.query.count(), 1)
        self.assertEquals(station.postal_code, "94200")

        values["postal_code"] = "75000"
        station = StationInformation.update_or_create(values, surrogate=False)
        self.assertEquals(StationInformation.query.count(), 1)
        self.assertEquals(station.postal_code, "75000")

        values["id"] = 43
        station = StationInformation.update_or_create(values, surrogate=False)
        self.assertEquals(StationInformation.query.count(), 2)
        self.assertEquals(station.postal_code, "75000")
示例#3
0
 def acquire_informations(self):
     """Default method for acquiring informations
     of a stations, by connecting to the database"""
     try:
         return StationInformation.get(self.id)
     except AttributeError:
         db_connection()
         return StationInformation.get(self.id)
示例#4
0
 def test_repr(self):
     values = {
         "id": 42,
         "address": "1 rue Kennedy",
         "postal_code": "94200",
         "city": "Paris",
         "lat": "42.000000000",
         "lng": "42.000000000",
         "opened": True,
         "bonus": False,
     }
     station = StationInformation.update_or_create(values, surrogate=False)
     self.assertEquals(repr(station), '<StationInformation "42" (1 rue Kennedy)>')
示例#5
0
 def test_FullAddress(self):
     values = {
         "id": 42,
         "address": "1 rue Kennedy",
         "postal_code": "94200",
         "city": "Paris",
         "lat": "42.000000000",
         "lng": "42.000000000",
         "opened": True,
         "bonus": False,
     }
     station = StationInformation.update_or_create(values, surrogate=False)
     self.assertEquals(station.full_address, "1 rue Kennedy, 94200 Paris")