Beispiel #1
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)))
Beispiel #2
0
 def testGetDetailsString(self):
     person = self.create_person()
     city = u'Stoqlandia'
     state = u'SP'
     country = u'Brazil'
     postal_code = u'12345-678'
     location = CityLocation(city=city, state=state, country=country,
                             store=self.store)
     address = Address(person=person, city_location=location,
                       postal_code=postal_code, store=self.store)
     string = address.get_details_string()
     self.assertEquals(string, u'%s - %s - %s' % (postal_code,
                                                  city, state))
     location.city = u''
     string = address.get_details_string()
     self.assertEquals(string, u'%s' % postal_code)
     location.state = u''
     string = address.get_details_string()
     self.assertEquals(string, u'%s' % postal_code)
     address.postal_code = u''
     string = address.get_details_string()
     self.assertEquals(string, u'')
     location.city = city
     location.state = state
     string = address.get_details_string()
     self.assertEquals(string, u'%s - %s' % (city, state))
Beispiel #3
0
    def testGetOrCreate(self):
        loc = CityLocation.get_or_create(self.store, u'City', u'State',
                                         u'Country')
        self.failUnless(loc)
        self.assertEqual(loc.city, u'City')
        self.assertEqual(loc.state, u'State')
        self.assertEqual(loc.country, u'Country')

        loc2 = CityLocation.get_or_create(self.store, u'city', u'state',
                                          u'country')
        self.failUnless(loc2)
        self.assertEqual(loc2.city, u'City')
        self.assertEqual(loc2.state, u'State')
        self.assertEqual(loc2.country, u'Country')
        self.assertEqual(loc2, loc)

        location = CityLocation.get_or_create(self.store, u'São Carlos', u'SP',
                                              u'Brazil')
        for city, state, country in [(u'sao carlos', u'SP', u'Brazil'),
                                     (u'Sao carlos', u'SP', u'Brazil'),
                                     (u'São carlos', u'SP', u'Brazil'),
                                     (u'sao Carlos', u'SP', u'Brazil'),
                                     (u'sao Carlos', u'sp', u'Brazil'),
                                     (u'sao Carlos', u'sp', u'brazil'),
                                     (u'sao Carlos', u'Sp', u'brazil')]:
            self.assertEqual(
                CityLocation.get_or_create(self.store, city, state, country),
                location)
        for city, state, country in [(u'Sao', u'SP', u'Brazil'),
                                     (u'sao', u'SP', u'Brazil'),
                                     (u'Carlos', u'SP', u'Brazil'),
                                     (u'carlos', u'SP', u'Brazil')]:
            self.assertNotEqual(
                CityLocation.get_or_create(self.store, city, state, country),
                location)
Beispiel #4
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)))
Beispiel #5
0
    def process_one(self, data, fields, store):
        person = Person(
            store=store,
            name=data.name,
            phone_number=data.phone_number,
            mobile_number=data.mobile_number)

        Company(person=person,
                store=store,
                cnpj=data.cnpj,
                fancy_name=data.name,
                state_registry=data.state_registry)

        ctloc = CityLocation.get_or_create(store=store,
                                           city=data.city,
                                           state=data.state,
                                           country=data.country)
        streetnumber = data.streetnumber and int(data.streetnumber) or None
        Address(
            is_main_address=True,
            person=person,
            city_location=ctloc,
            store=store,
            street=data.street,
            streetnumber=streetnumber,
            district=data.district
        )

        supplier = Supplier(person=person, store=store)
        self.suppliers.append(supplier)
Beispiel #6
0
    def process_one(self, data, fields, store):
        person = Person(store=store,
                        name=data.name,
                        phone_number=data.phone_number,
                        fax_number=data.fax_number)

        Company(person=person,
                cnpj=data.cnpj,
                state_registry=data.state_registry,
                fancy_name=data.fancy_name,
                store=store)

        ctloc = CityLocation.get_or_create(store=store,
                                           city=data.city,
                                           state=data.state,
                                           country=data.country)
        streetnumber = data.streetnumber and int(data.streetnumber) or None
        Address(is_main_address=True,
                person=person,
                city_location=ctloc,
                store=store,
                street=data.street,
                streetnumber=streetnumber,
                district=data.district,
                postal_code=data.postal_code)

        branch = Branch(person=person, store=store)
        for user in store.find(LoginUser):
            user.add_access_to(branch)
        self.branches.append(branch)
    def process_one(self, data, fields, store):
        person = Person(
            store=store,
            name=data.name,
            phone_number=data.phone_number,
            mobile_number=data.mobile_number)

        Company(person=person,
                store=store,
                cnpj=data.cnpj,
                fancy_name=data.name,
                state_registry=data.state_registry)

        ctloc = CityLocation.get_or_create(store=store,
                                           city=data.city,
                                           state=data.state,
                                           country=data.country)
        streetnumber = data.streetnumber and int(data.streetnumber) or None
        Address(
            is_main_address=True,
            person=person,
            city_location=ctloc,
            store=store,
            street=data.street,
            streetnumber=streetnumber,
            district=data.district
        )

        dict(open_contract_date=self.parse_date(data.open_contract),
             freight_percentage=data.freight_percentage),
        Transporter(person=person, store=store)
Beispiel #8
0
    def process_one(self, data, fields, store):
        person = Person(store=store,
                        name=data.name,
                        phone_number=data.phone_number,
                        mobile_number=data.mobile_number)

        Company(person=person,
                store=store,
                cnpj=data.cnpj,
                fancy_name=data.name,
                state_registry=data.state_registry)

        ctloc = CityLocation.get_or_create(store=store,
                                           city=data.city,
                                           state=data.state,
                                           country=data.country)
        streetnumber = data.streetnumber and int(data.streetnumber) or None
        Address(is_main_address=True,
                person=person,
                city_location=ctloc,
                store=store,
                street=data.street,
                streetnumber=streetnumber,
                district=data.district)

        Transporter(person=person,
                    open_contract_date=self.parse_date(data.open_contract),
                    freight_percentage=decimal.Decimal(
                        data.freight_percentage),
                    store=store)
Beispiel #9
0
    def process_one(self, data, fields, store):
        person = Person(
            store=store,
            name=data.name,
            phone_number=data.phone_number,
            mobile_number=data.mobile_number)

        Individual(person=person,
                   store=store,
                   cpf=data.cpf,
                   rg_number=data.rg)

        ctloc = CityLocation.get_or_create(store=store,
                                           city=data.city,
                                           state=data.state,
                                           country=data.country)
        streetnumber = data.streetnumber and int(data.streetnumber) or None
        Address(
            is_main_address=True,
            person=person,
            city_location=ctloc,
            store=store,
            street=data.street,
            streetnumber=streetnumber,
            district=data.district
            )

        Client(person=person, store=store)
Beispiel #10
0
    def process_one(self, data, fields, store):
        person = Person(
            store=store,
            name=data.name,
            phone_number=data.phone_number,
            mobile_number=data.mobile_number)

        Individual(person=person,
                   store=store,
                   cpf=data.cpf,
                   rg_number=data.rg)

        ctloc = CityLocation.get_or_create(store=store,
                                           city=data.city,
                                           state=data.state,
                                           country=data.country)
        streetnumber = data.streetnumber and int(data.streetnumber) or None
        Address(
            is_main_address=True,
            person=person,
            city_location=ctloc,
            store=store,
            street=data.street,
            streetnumber=streetnumber,
            district=data.district
        )

        Client(person=person, store=store)
Beispiel #11
0
 def testGetDefault(self):
     location = CityLocation.get_default(self.store)
     self.failUnless(isinstance(location, CityLocation))
     self.assertEquals(location.city, sysparam(self.store).CITY_SUGGESTED)
     self.assertEquals(location.state, sysparam(self.store).STATE_SUGGESTED)
     self.assertEquals(location.country,
                       sysparam(self.store).COUNTRY_SUGGESTED)
Beispiel #12
0
    def process_one(self, data, fields, store):
        person = Person(
            store=store,
            name=data.name,
            phone_number=data.phone_number,
            fax_number=data.fax_number)

        Company(person=person, cnpj=data.cnpj,
                state_registry=data.state_registry,
                fancy_name=data.fancy_name,
                store=store)

        ctloc = CityLocation.get_or_create(store=store,
                                           city=data.city,
                                           state=data.state,
                                           country=data.country)
        streetnumber = data.streetnumber and int(data.streetnumber) or None
        Address(
            is_main_address=True,
            person=person,
            city_location=ctloc,
            store=store,
            street=data.street,
            streetnumber=streetnumber,
            district=data.district,
            postal_code=data.postal_code
        )

        branch = Branch(person=person, store=store)
        for user in store.find(LoginUser):
            user.add_access_to(branch)
Beispiel #13
0
    def process_one(self, data, fields, store):
        person = Person(store=store,
                        name=data.name,
                        phone_number=data.phone_number,
                        mobile_number=data.mobile_number)

        Company(person=person,
                store=store,
                cnpj=data.cnpj,
                fancy_name=data.name,
                state_registry=data.state_registry)

        ctloc = CityLocation.get_or_create(store=store,
                                           city=data.city,
                                           state=data.state,
                                           country=data.country)
        streetnumber = data.streetnumber and int(data.streetnumber) or None
        Address(is_main_address=True,
                person=person,
                city_location=ctloc,
                store=store,
                street=data.street,
                streetnumber=streetnumber,
                district=data.district)

        Supplier(person=person, store=store)
Beispiel #14
0
 def create_city_location(self, city=None, state=None, country=None):
     from stoqlib.domain.address import CityLocation
     return CityLocation.get_or_create(
         self.store,
         country=country or u'United States',
         city=city or u'Los Angeles',
         state=state or u'Californa',
     )
Beispiel #15
0
 def ensure_birth_location(self):
     changed = self.birth_location_changed()
     if changed:
         self.target.birth_location = CityLocation.get_or_create(
             city=self.city,
             state=self.state,
             country=self.country,
             store=self.store)
Beispiel #16
0
 def test_location_suggested(self):
     location = CityLocation.get_default(self.store)
     self.assertEqual(location.city,
                      self.sparam.get_string('CITY_SUGGESTED'))
     self.assertEqual(location.state,
                      self.sparam.get_string('STATE_SUGGESTED'))
     self.assertEqual(location.country,
                      self.sparam.get_string('COUNTRY_SUGGESTED'))
Beispiel #17
0
 def test_get_default(self):
     location = CityLocation.get_default(self.store)
     self.failUnless(isinstance(location, CityLocation))
     self.assertEquals(location.city, sysparam.get_string('CITY_SUGGESTED'))
     self.assertEquals(location.state,
                       sysparam.get_string('STATE_SUGGESTED'))
     self.assertEquals(location.country,
                       sysparam.get_string('COUNTRY_SUGGESTED'))
 def ensure_birth_location(self):
     changed = self.birth_location_changed()
     if changed:
         self.target.birth_location = CityLocation.get_or_create(
             city=self.city,
             state=self.state,
             country=self.country,
             store=self.store)
Beispiel #19
0
 def ensure_address(self):
     changed = self._city_location_changed()
     if changed:
         location = CityLocation.get_or_create(city=self.city,
                                               state=self.state,
                                               country=self.country,
                                               store=self.store)
         self.target.city_location = location
Beispiel #20
0
 def testIsValidModel(self):
     person = self.create_person()
     empty_location = CityLocation(store=self.store)
     empty_address = Address(store=self.store,
                             person=person,
                             city_location=empty_location)
     is_valid_model = empty_address.is_valid_model()
     assert bool(is_valid_model) is False
Beispiel #21
0
 def create_city_location(self, city=None, state=None, country=None):
     from stoqlib.domain.address import CityLocation
     return CityLocation.get_or_create(
         self.store,
         country=country or u'United States',
         city=city or u'Los Angeles',
         state=state or u'Californa',
     )
Beispiel #22
0
 def test_get_default(self):
     location = CityLocation.get_default(self.store)
     self.failUnless(isinstance(location, CityLocation))
     self.assertEquals(location.city,
                       sysparam.get_string('CITY_SUGGESTED'))
     self.assertEquals(location.state,
                       sysparam.get_string('STATE_SUGGESTED'))
     self.assertEquals(location.country,
                       sysparam.get_string('COUNTRY_SUGGESTED'))
Beispiel #23
0
 def ensure_address(self):
     changed = self._city_location_changed()
     if changed:
         location = CityLocation.get_or_create(
             city=self.city,
             state=self.state,
             country=self.country,
             store=self.store)
         self.target.city_location = location
Beispiel #24
0
    def __init__(self, target, store):
        AttributeForwarder.__init__(self, target)
        self.store = store
        if not target.birth_location:
            target.birth_location = CityLocation.get_default(store)

        self.city = target.birth_location.city
        self.state = target.birth_location.state
        self.country = target.birth_location.country
Beispiel #25
0
 def testGetDefault(self):
     location = CityLocation.get_default(self.store)
     self.failUnless(isinstance(location, CityLocation))
     self.assertEquals(location.city,
                       sysparam(self.store).CITY_SUGGESTED)
     self.assertEquals(location.state,
                       sysparam(self.store).STATE_SUGGESTED)
     self.assertEquals(location.country,
                       sysparam(self.store).COUNTRY_SUGGESTED)
Beispiel #26
0
    def _create_address(self, person, street, streetnumber, postal_code):
        city = CityLocation.get_default(self.store)

        return Address(store=self.store,
                       street=street,
                       streetnumber=streetnumber,
                       postal_code=postal_code,
                       is_main_address=True,
                       person=person,
                       city_location=city)
Beispiel #27
0
    def _create_address(self, person, street, streetnumber, postal_code):
        city = CityLocation.get_default(self.store)

        return Address(store=self.store,
                       street=street,
                       streetnumber=streetnumber,
                       postal_code=postal_code,
                       is_main_address=True,
                       person=person,
                       city_location=city)
Beispiel #28
0
 def test_get_city_location_attributes(self):
     person = self.create_person()
     city = u'Acapulco'
     country = u'Brazil'
     state = u'Cracovia'
     location = CityLocation(city=city, state=state, country=country,
                             store=self.store)
     address = Address(person=person, city_location=location,
                       store=self.store)
     self.assertEquals(address.get_city(), u'Acapulco')
     self.assertEquals(address.get_country(), u'Brazil')
     self.assertEquals(address.get_state(), u'Cracovia')
Beispiel #29
0
 def testGetDetailsString(self):
     person = self.create_person()
     city = u'Stoqlandia'
     state = u'SP'
     country = u'Brazil'
     postal_code = u'12345-678'
     location = CityLocation(city=city,
                             state=state,
                             country=country,
                             store=self.store)
     address = Address(person=person,
                       city_location=location,
                       postal_code=postal_code,
                       store=self.store)
     string = address.get_details_string()
     self.assertEquals(string, u'%s - %s - %s' % (postal_code, city, state))
     location.city = u''
     string = address.get_details_string()
     self.assertEquals(string, u'%s' % postal_code)
     location.state = u''
     string = address.get_details_string()
     self.assertEquals(string, u'%s' % postal_code)
     address.postal_code = u''
     string = address.get_details_string()
     self.assertEquals(string, u'')
     location.city = city
     location.state = state
     string = address.get_details_string()
     self.assertEquals(string, u'%s - %s' % (city, state))
Beispiel #30
0
    def __init__(self, target, store):
        """
        :param model: an Individial
        :param store: a store
        """
        AttributeForwarder.__init__(self, target)
        self.store = store
        if not target.birth_location:
            target.birth_location = CityLocation.get_default(store)

        self.city = target.birth_location.city
        self.state = target.birth_location.state
        self.country = target.birth_location.country
Beispiel #31
0
    def testGetOrCreate(self):
        loc = CityLocation.get_or_create(self.store, u'City',
                                         u'State', u'Country')
        self.failUnless(loc)
        self.assertEqual(loc.city, u'City')
        self.assertEqual(loc.state, u'State')
        self.assertEqual(loc.country, u'Country')

        loc2 = CityLocation.get_or_create(self.store, u'city',
                                          u'state', u'country')
        self.failUnless(loc2)
        self.assertEqual(loc2.city, u'City')
        self.assertEqual(loc2.state, u'State')
        self.assertEqual(loc2.country, u'Country')
        self.assertEqual(loc2, loc)

        location = CityLocation.get_or_create(self.store, u'São Carlos',
                                              u'SP', u'Brazil')
        for city, state, country in [
            (u'sao carlos', u'SP', u'Brazil'),
            (u'Sao carlos', u'SP', u'Brazil'),
            (u'São carlos', u'SP', u'Brazil'),
            (u'sao Carlos', u'SP', u'Brazil'),
            (u'sao Carlos', u'sp', u'Brazil'),
            (u'sao Carlos', u'sp', u'brazil'),
            (u'sao Carlos', u'Sp', u'brazil'),
            ]:
            self.assertEqual(CityLocation.get_or_create(self.store, city,
                                                        state, country),
                             location)
        for city, state, country in [
            (u'Sao', u'SP', u'Brazil'),
            (u'sao', u'SP', u'Brazil'),
            (u'Carlos', u'SP', u'Brazil'),
            (u'carlos', u'SP', u'Brazil'),
            ]:
            self.assertNotEqual(CityLocation.get_or_create(self.store, city,
                                                           state, country),
                                location)
Beispiel #32
0
    def __init__(self, target, store):
        """
        :param model: an Individial
        :param store: a store
        """
        AttributeForwarder.__init__(self, target)
        self.store = store
        if not target.birth_location:
            target.birth_location = CityLocation.get_default(store)

        self.city = target.birth_location.city
        self.state = target.birth_location.state
        self.country = target.birth_location.country
Beispiel #33
0
 def test_getaddress_string(self):
     person = self.create_person()
     ctloc = CityLocation(store=self.store)
     address = Address(store=self.store,
                       person=person,
                       city_location=ctloc,
                       street=u'bla',
                       streetnumber=2,
                       district=u'fed',
                       is_main_address=True)
     self.assertEquals(
         person.get_address_string(),
         _(u'%s %s, %s') %
         (address.street, address.streetnumber, address.district))
Beispiel #34
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))
Beispiel #35
0
    def process_one(self, data, fields, store):
        person = Person(
            store=store,
            name=data.name,
            phone_number=data.phone_number,
            mobile_number=data.mobile_number)

        Individual(person=person,
                   store=store,
                   cpf=data.cpf,
                   rg_number=data.rg)

        role = EmployeeRole(store=store, name=data.role)

        employee = Employee(person=person,
                            store=store,
                            role=role,
                            salary=int(data.salary),
                            registry_number=data.employee_number)

        start = self.parse_date(data.start)
        EmployeeRoleHistory(
            store=store, role=role,
            employee=employee,
            is_active=True,
            began=start,
            salary=int(data.salary))

        ctloc = CityLocation.get_or_create(store=store,
                                           city=data.city,
                                           state=data.state,
                                           country=data.country)
        streetnumber = data.streetnumber and int(data.streetnumber) or None
        Address(is_main_address=True,
                person=person,
                city_location=ctloc,
                store=store,
                street=data.street,
                streetnumber=streetnumber,
                district=data.district)

        if self.create_users:
            profile = store.find(UserProfile, name=data.profile).one()
            LoginUser(person=person, store=store, profile=profile,
                      username=data.username,
                      password=data.password)

        SalesPerson(person=person, store=store)
Beispiel #36
0
    def _create_client(self, store):
        from stoqlib.domain.address import Address, CityLocation
        from stoqlib.domain.person import Client, Person

        person = Person(name=u'Person', store=store)
        city = CityLocation.get_default(store)
        Address(store=store,
                street=u'Rua Principal',
                streetnumber=123,
                postal_code=u'12345-678',
                is_main_address=True,
                person=person,
                city_location=city)
        client = Client(person=person, store=store)
        client.credit_limit = currency("1000")
        return client
    def __init__(self, target, store, ui_form_name=None):
        """
        :param target: an Individial
        :param store: a store
        """
        # Even though we dont use ui_form_name anywhere in this class, its setup
        # is made in a way we need this argument. see persontemplate
        # attach_model_slave method
        AttributeForwarder.__init__(self, target)
        self.store = store
        if not target.birth_location:
            target.birth_location = CityLocation.get_default(store)

        self.city = target.birth_location.city
        self.state = target.birth_location.state
        self.country = target.birth_location.country
    def __init__(self, target, store, ui_form_name=None):
        """
        :param target: an Individial
        :param store: a store
        """
        # Even though we dont use ui_form_name anywhere in this class, its setup
        # is made in a way we need this argument. see persontemplate
        # attach_model_slave method
        AttributeForwarder.__init__(self, target)
        self.store = store
        if not target.birth_location:
            target.birth_location = CityLocation.get_default(store)

        self.city = target.birth_location.city
        self.state = target.birth_location.state
        self.country = target.birth_location.country
Beispiel #39
0
    def _create_client(self, store):
        from stoqlib.domain.address import Address, CityLocation
        from stoqlib.domain.person import Client, Person

        person = Person(name=u'Person', store=store)
        city = CityLocation.get_default(store)
        Address(store=store,
                street=u'Rua Principal',
                streetnumber=123,
                postal_code=u'12345-678',
                is_main_address=True,
                person=person,
                city_location=city)
        client = Client(person=person, store=store)
        client.credit_limit = currency("1000")
        return client
    def testConfirm(self, info):
        city_location = CityLocation.get_or_create(
            self.store, u"São Carlos", u"SP", u"Brazil")
        person = self.create_person()
        address = self.create_address(person=person,
                                      city_location=city_location)
        editor = AddressEditor(self.store, person, address)
        address_slave = editor.address_slave
        self.assertSensitive(editor.main_dialog, ['ok_button'])
        valid_city = address_slave.city.read()

        # Trying to confirm the editor without leaving the entry.
        # Can be reproduced by pressing ALT+O
        address_slave.city.grab_focus()
        address_slave.city.update("INVALID CITY")
        self.assertValid(address_slave, ['city'])
        self.assertSensitive(editor.main_dialog, ['ok_button'])
        self.assertFalse(editor.confirm())
        self.assertInvalid(address_slave, ['city'])
        info.assert_called_once_with("The city is not valid")

        # When city looses focus, validation should be done
        address_slave.city.update(valid_city)
        self.assertSensitive(editor.main_dialog, ['ok_button'])
        address_slave.city.grab_focus()
        address_slave.city.update("INVALID CITY")
        # FIXME: For some reason, this only works here when grabbing the focus
        # on another widget and emitting the focus-out event. On the real
        # editor, pressing TAB or even trying to click on Ok is enough
        address_slave.state.grab_focus()
        address_slave.city.emit('focus-out-event',
                                gtk.gdk.Event(gtk.gdk.FOCUS_CHANGE))
        self.assertNotSensitive(editor.main_dialog, ['ok_button'])
        self.assertInvalid(address_slave, ['city'])

        address_slave.city.update(valid_city)
        self.assertValid(address_slave, ['city'])
        self.assertSensitive(editor.main_dialog, ['ok_button'])

        path = 'stoqlib.domain.address.CityLocation.is_valid_model'
        with mock.patch(path) as is_valid_model:
            is_valid_model.return_value = False
            self.assertFalse(editor.validate_confirm())
            self.assertFalse(editor.confirm())

        self.assertTrue(editor.validate_confirm())
        self.assertTrue(editor.confirm())
Beispiel #41
0
    def testConfirm(self, info):
        city_location = CityLocation.get_or_create(self.store, u"São Carlos",
                                                   u"SP", u"Brazil")
        person = self.create_person()
        address = self.create_address(person=person,
                                      city_location=city_location)
        editor = AddressEditor(self.store, person, address)
        address_slave = editor.address_slave
        self.assertSensitive(editor.main_dialog, ['ok_button'])
        valid_city = address_slave.city.read()

        # Trying to confirm the editor without leaving the entry.
        # Can be reproduced by pressing ALT+O
        address_slave.city.grab_focus()
        address_slave.city.update("INVALID CITY")
        self.assertValid(address_slave, ['city'])
        self.assertSensitive(editor.main_dialog, ['ok_button'])
        self.assertFalse(editor.confirm())
        self.assertInvalid(address_slave, ['city'])
        info.assert_called_once_with("The city is not valid")

        # When city looses focus, validation should be done
        address_slave.city.update(valid_city)
        self.assertSensitive(editor.main_dialog, ['ok_button'])
        address_slave.city.grab_focus()
        address_slave.city.update("INVALID CITY")
        # FIXME: For some reason, this only works here when grabbing the focus
        # on another widget and emitting the focus-out event. On the real
        # editor, pressing TAB or even trying to click on Ok is enough
        address_slave.state.grab_focus()
        address_slave.city.emit('focus-out-event',
                                gtk.gdk.Event(gtk.gdk.FOCUS_CHANGE))
        self.assertNotSensitive(editor.main_dialog, ['ok_button'])
        self.assertInvalid(address_slave, ['city'])

        address_slave.city.update(valid_city)
        self.assertValid(address_slave, ['city'])
        self.assertSensitive(editor.main_dialog, ['ok_button'])

        path = 'stoqlib.domain.address.CityLocation.is_valid_model'
        with mock.patch(path) as is_valid_model:
            is_valid_model.return_value = False
            self.assertFalse(editor.validate_confirm())
            self.assertFalse(editor.confirm())

        self.assertTrue(editor.validate_confirm())
        self.assertTrue(editor.confirm())
    def create_address(cls, person, address):
        if not address.get('city_location'):
            log.error('Missing city location')
            abort(400, "Missing city location")

        city_location = CityLocation.get(
            person.store,
            country=address['city_location']['country'],
            city=address['city_location']['city'],
            state=address['city_location']['state'],
        )
        if not city_location:
            log.error('Invalid city location: %s', address['city_location'])
            abort(400, "Invalid city location")

        Address(street=address['street'],
                streetnumber=address['streetnumber'],
                district=address['district'],
                postal_code=address['postal_code'],
                complement=address.get('complement'),
                is_main_address=address['is_main_address'],
                person=person,
                city_location=city_location,
                store=person.store)
Beispiel #43
0
 def testLocationSuggested(self):
     location = CityLocation.get_default(self.store)
     self.assertEqual(location.city, self.sparam.CITY_SUGGESTED)
     self.assertEqual(location.state, self.sparam.STATE_SUGGESTED)
     self.assertEqual(location.country, self.sparam.COUNTRY_SUGGESTED)
Beispiel #44
0
 def get_location(self):
     from stoqlib.domain.address import CityLocation
     return CityLocation.get_default(self.store)
Beispiel #45
0
 def validate(self, city, state=None, country=None):
     return CityLocation.exists(get_default_store(),
                                city=city,
                                state=state,
                                country=country)
Beispiel #46
0
 def test_location_suggested(self):
     location = CityLocation.get_default(self.store)
     self.assertEqual(location.city, self.sparam.get_string('CITY_SUGGESTED'))
     self.assertEqual(location.state, self.sparam.get_string('STATE_SUGGESTED'))
     self.assertEqual(location.country, self.sparam.get_string('COUNTRY_SUGGESTED'))
Beispiel #47
0
    def test_get_or_create(self):
        loc = CityLocation.get_or_create(self.store, u'City', u'State',
                                         u'Country')
        self.failUnless(loc)
        self.assertEqual(loc.city, u'City')
        self.assertEqual(loc.state, u'State')
        self.assertEqual(loc.country, u'Country')

        loc2 = CityLocation.get_or_create(self.store, u'city', u'state',
                                          u'country')
        self.failUnless(loc2)
        self.assertEqual(loc2.city, u'City')
        self.assertEqual(loc2.state, u'State')
        self.assertEqual(loc2.country, u'Country')
        self.assertEqual(loc2, loc)

        location = CityLocation.get_or_create(self.store, u'São Carlos', u'SP',
                                              u'Brazil')
        for city, state, country in [(u'sao carlos', u'SP', u'Brazil'),
                                     (u'Sao carlos', u'SP', u'Brazil'),
                                     (u'São carlos', u'SP', u'Brazil'),
                                     (u'sao Carlos', u'SP', u'Brazil'),
                                     (u'sao Carlos', u'sp', u'Brazil'),
                                     (u'sao Carlos', u'sp', u'brazil'),
                                     (u'sao Carlos', u'Sp', u'brazil')]:
            self.assertEqual(
                CityLocation.get_or_create(self.store, city, state, country),
                location)
        loc2 = CityLocation(store=self.store)
        loc2.city = u'Sao Carlos'
        loc2.state = u'SP'
        loc2.country = u'Brazil'
        loc2.city_code = 00000
        location = CityLocation.get_or_create(self.store, u'São Carlos', u'SP',
                                              u'Brazil')
        self.assertEquals(location.city_code, 3548906)
        loc3 = CityLocation(store=self.store)
        loc3.city = u'City ABC'
        loc3.state = u'SP'
        loc3.country = u'Brazil'
        loc3.city_code = None
        loc4 = CityLocation(store=self.store)
        loc4.city = u'City ABĆ'
        loc4.state = u'SP'
        loc4.country = u'Brazil'
        loc4.city_code = None
        location = CityLocation.get_or_create(self.store, u'City ABC', u'SP',
                                              u'Brazil')
        self.assertNotEquals(location, loc4)
        loc4.city_code = 13560
        location = CityLocation.get_or_create(self.store, u'City ABC', u'SP',
                                              u'Brazil')
        self.assertEquals(location, loc4)

        for city, state, country in [(u'Sao', u'SP', 'Brazil'),
                                     (u'carlos', decimal.Decimal(8), u'Brazil')
                                     ]:
            with self.assertRaises(TypeError):
                CityLocation.get_or_create(self.store, city, state, country)
Beispiel #48
0
 def testLocationSuggested(self):
     location = CityLocation.get_default(self.store)
     self.assertEqual(location.city, self.sparam.CITY_SUGGESTED)
     self.assertEqual(location.state, self.sparam.STATE_SUGGESTED)
     self.assertEqual(location.country, self.sparam.COUNTRY_SUGGESTED)
Beispiel #49
0
Datei: br.py Projekt: romaia/stoq
 def validate(self, city, state=None, country=None):
     return CityLocation.exists(get_default_store(), city=city, state=state, country=country)
Beispiel #50
0
 def create_model(self, store):
     address = Address(person=self.person,
                       city_location=CityLocation.get_default(store),
                       is_main_address=self.is_main_address,
                       store=store)
     return _AddressModel(address, store)
Beispiel #51
0
 def get_location(self):
     from stoqlib.domain.address import CityLocation
     return CityLocation.get_default(self.store)
Beispiel #52
0
 def test_is_valid_model(self):
     location = self.create_city_location()
     self.assertTrue(location.is_valid_model())
     invalid_location = CityLocation(store=self.store)
     self.assertFalse(invalid_location.is_valid_model())
Beispiel #53
0
 def create_model(self, store):
     return Address(person=self.person,
                    city_location=CityLocation.get_default(store),
                    is_main_address=False,
                    store=store)
Beispiel #54
0
    def test_get_or_create(self):
        loc = CityLocation.get_or_create(self.store, u'City',
                                         u'State', u'Country')
        self.failUnless(loc)
        self.assertEqual(loc.city, u'City')
        self.assertEqual(loc.state, u'State')
        self.assertEqual(loc.country, u'Country')

        loc2 = CityLocation.get_or_create(self.store, u'city',
                                          u'state', u'country')
        self.failUnless(loc2)
        self.assertEqual(loc2.city, u'City')
        self.assertEqual(loc2.state, u'State')
        self.assertEqual(loc2.country, u'Country')
        self.assertEqual(loc2, loc)

        location = CityLocation.get_or_create(self.store, u'São Carlos',
                                              u'SP', u'Brazil')
        for city, state, country in [
                (u'sao carlos', u'SP', u'Brazil'),
                (u'Sao carlos', u'SP', u'Brazil'),
                (u'São carlos', u'SP', u'Brazil'),
                (u'sao Carlos', u'SP', u'Brazil'),
                (u'sao Carlos', u'sp', u'Brazil'),
                (u'sao Carlos', u'sp', u'brazil'),
                (u'sao Carlos', u'Sp', u'brazil')]:
            self.assertEqual(CityLocation.get_or_create(self.store, city,
                                                        state, country),
                             location)
        loc2 = CityLocation(store=self.store)
        loc2.city = u'Sao Carlos'
        loc2.state = u'SP'
        loc2.country = u'Brazil'
        loc2.city_code = 00000
        location = CityLocation.get_or_create(self.store, u'São Carlos',
                                              u'SP', u'Brazil')
        self.assertEquals(location.city_code, 3548906)
        loc3 = CityLocation(store=self.store)
        loc3.city = u'City ABC'
        loc3.state = u'SP'
        loc3.country = u'Brazil'
        loc3.city_code = None
        loc4 = CityLocation(store=self.store)
        loc4.city = u'City ABĆ'
        loc4.state = u'SP'
        loc4.country = u'Brazil'
        loc4.city_code = None
        location = CityLocation.get_or_create(self.store, u'City ABC',
                                              u'SP', u'Brazil')
        self.assertNotEquals(location, loc4)
        loc4.city_code = 13560
        location = CityLocation.get_or_create(self.store, u'City ABC',
                                              u'SP', u'Brazil')
        self.assertEquals(location, loc4)

        for city, state, country in [(u'Sao', u'SP', 'Brazil'),
                                     (u'carlos', decimal.Decimal(8), u'Brazil')]:
            with self.assertRaises(TypeError):
                CityLocation.get_or_create(self.store, city, state, country)
Beispiel #55
0
 def testIsValidModel(self):
     location = self.create_city_location()
     self.failUnless(location.is_valid_model())
     invalid_location = CityLocation(store=self.store)
     self.failIf(invalid_location.is_valid_model())
Beispiel #56
0
 def testIsValidModel(self):
     location = self.create_city_location()
     self.failUnless(location.is_valid_model())
     invalid_location = CityLocation(store=self.store)
     self.failIf(invalid_location.is_valid_model())