Exemplo n.º 1
0
    def testGetCitiesBy(self):
        location = CityLocation.get_or_create(self.store, u'Sao Carlos',
                                              u'SP', u'Brazil')
        for state, country in [
            (u'SP', u'Brazil'),
            (u'Sp', u'brazil'),
            (u'SP', u'brazil'),
            (u'sp', u'Brazil'),
            (u'sp', u'BraZIL'),
            (None, u'Brazil'),
            (u'SP', None),
            (None, None),
            ]:
            self.assertTrue(location.city in
                            CityLocation.get_cities_by(self.store,
                                                       state=state,
                                                       country=country))
        for state, country in [
            (u'SP', u'Brazi'),
            (u'RJ', u'Brazil'),
            (u'RJ', None),
            (u'BA', None),
            (u'SP', u'Albânia'),
            ]:
            self.assertFalse(location.city in
                             CityLocation.get_cities_by(self.store,
                                                        state=state,
                                                        country=country))

        # Make sure no duplicates are returned
        CityLocation.get_or_create(self.store, u'Sao Carlos', u'SP', u'BR')
        CityLocation.get_or_create(self.store, u'Sao Carlos', u'SP', u'BR_')
        CityLocation.get_or_create(self.store, u'Sao Carlos', u'SP', u'BR__')
        cities = list(CityLocation.get_cities_by(self.store, state=u'SP'))
        self.assertEqual(len(cities), len(set(cities)))
Exemplo n.º 2
0
    def test_get_cities_by(self):
        location = CityLocation.get_or_create(self.store, u'Sao Carlos',
                                              u'SP', u'Brazil')
        for state, country in [
                (u'SP', u'Brazil'),
                (u'Sp', u'brazil'),
                (u'SP', u'brazil'),
                (u'sp', u'Brazil'),
                (u'sp', u'BraZIL'),
                (None, u'Brazil'),
                (u'SP', None),
                (None, None)]:
            self.assertTrue(location.city in
                            CityLocation.get_cities_by(self.store,
                                                       state=state,
                                                       country=country))
        for state, country in [
                (u'SP', u'Brazi'),
                (u'RJ', u'Brazil'),
                (u'RJ', None),
                (u'BA', None),
                (u'SP', u'Albânia')]:
            self.assertFalse(location.city in
                             CityLocation.get_cities_by(self.store,
                                                        state=state,
                                                        country=country))

        # Make sure no duplicates are returned
        CityLocation.get_or_create(self.store, u'Sao Carlos', u'SP', u'BR')
        CityLocation.get_or_create(self.store, u'Sao Carlos', u'SP', u'BR_')
        CityLocation.get_or_create(self.store, u'Sao Carlos', u'SP', u'BR__')
        cities = list(CityLocation.get_cities_by(self.store, state=u'SP'))
        self.assertEqual(len(cities), len(set(cities)))
Exemplo n.º 3
0
    def _prefill_cities(self, force=False):
        completion = self.city.get_completion()
        if not completion:
            # Completion wasn't set yet
            return

        if len(completion.get_model()) and not force:
            return

        self.city.prefill([])  # mimic missing .clear method
        cities = CityLocation.get_cities_by(self.store,
                                            state=self.model.state,
                                            country=self.model.country)
        self.city.prefill(list(cities))