def testGetPostalNumber(self): person = self.create_person() location = self.create_city_location() address = Address(person=person, city_location=location, postal_code=u'12345-678', store=self.store) self.assertEquals(address.get_postal_code_number(), 12345678)
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
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')
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))
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)
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 test_get_postal_number(self): person = self.create_person() location = self.create_city_location() address = Address(person=person, city_location=location, postal_code=u'12345-678', store=self.store) self.assertEquals(address.get_postal_code_number(), 12345678) address.postal_code = u'13560-xxx' self.assertEquals(address.get_postal_code_number(), 13560) address.postal_code = None self.assertEquals(address.get_postal_code_number(), 0)
def test_get_address_string(self): person = self.create_person() location = self.create_city_location() street = u'Rua das Couves' streetnumber = 283 district = u'Federal' address = Address(person=person, city_location=location, street=street, streetnumber=streetnumber, district=district, store=self.store) string = address.get_address_string() self.assertEqual(string, u'%s %s, %s' % (street, streetnumber, district)) address.streetnumber = None string = address.get_address_string() self.assertEqual(string, u'%s %s, %s' % (street, u'N/A', district)) address.street = u"" string = address.get_address_string() self.assertEqual(string, u'')
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)
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)
def create_model(self, store): return Address(person=self.person, city_location=CityLocation.get_default(store), is_main_address=False, store=store)