def _read(self, adr, data, prefix): '''Recursive address setting attribute dict reader. @param adr: Active address object @type adr: Address @param data: Active (subset) dict @param prefix: String value used to flatten/identify nested dictionary elements @type prefix: String @return: Active (partially filled) address ''' for k in data: setter = 'set' + k[0].upper() + k[1:] new_prefix = prefix + DEF_SEP + k if isinstance(data[k], dict): adr = self._read(adr=adr, data=data[k], prefix=new_prefix) elif isinstance(data[k], list) and new_prefix == self.PBRANCH: pstns = [] for pd in data[k]: pstns.append(Position.getInstance(pd, self)) adr.setAddressPositions(pstns) else: getattr(adr, setter)(self.filterPI(data[k]) or None) if hasattr( adr, setter) else setattr( adr, new_prefix, self.filterPI(data[k]) or None) return adr
def getmacronatedtestaddress(self,ff): a = ff.get('test_macronated_address') p = Position.getInstance( {'position':{'type':'Point','coordinates': [170.62953346606358,-45.768294405809044],'crs':{'type':'name','properties':{'name':'urn:ogc:def:crs:EPSG::4167'}}},'positionType':'Centroid','primary':True} ) a.setAddressType('Road') a.setAddressNumber('11') a.setAddressId('1787900') a.setLifecycle('Current') a.setRoadCentrelineId('9512') a.setRoadName('Pūrākaunui School') a.setRoadType('Road'), a.setSuburbLocality('Purakaunui') a.setFullAddressNumber('11') a.setFullRoadName('Pūrākaunui School Road') a.setFullAddress('11 Pūrākaunui School, Purakaunui') a._addressedObject_addressableObjectId = '1794488' a.setAddObjectType('Parcel') a.setUnitType('Unit') a.setUnitValue('f') a.setAddressPositions(p) a._codes_suburbLocalityId = '2480' a._codes_parcelId = '3073736' a._codes_meshblock = '2863900' return a
def gettestaddress(self,ff): a = ff.get('test_featuretype_address') p = Position.getInstance( {'position':{'type':'Point','coordinates': [168.38392191667,-44.8511013],'crs':{'type':'name','properties':{'name':'urn:ogc:def:crs:EPSG::4167'}}},'positionType':'Centroid','primary':True} ) a.setAddressType('Road') a.setAddressNumber('16') a.setAddressId('29') a.setLifecycle('Current') a.setRoadCentrelineId('11849') a.setRoadName('Islay') a.setRoadType('Street'), a.setSuburbLocality('Glenorchy') a.setFullAddressNumber('17') a.setFullRoadName('Islay Street') a.setFullAddress('17 Islay Street, Glenorchy') a._addressedObject_addressableObjectId = '1416143' a.setAddObjectType('Parcel') a.setUnitType('Unit') a.setUnitValue('b') a.setAddressPositions(p) a._codes_suburbLocalityId = '2104' a._codes_parcelId = '3132748' a._codes_meshblock = '3174100' return a
def _read(self,adr,data,prefix): '''Recursive address setting attribute dict reader. @param adr: Active address object @type adr: Address @param data: Active (subset) dict @param prefix: String value used to flatten/identify nested dictionary elements @type prefix: String @return: Active (partially filled) address ''' for k in data: setter = 'set'+k[0].upper()+k[1:] new_prefix = prefix+DEF_SEP+k if isinstance(data[k],dict): adr = self._read(adr=adr,data=data[k],prefix=new_prefix) elif isinstance(data[k],list) and new_prefix == self.PBRANCH: pstns = [] for pd in data[k]: pstns.append(Position.getInstance(pd,self)) adr.setAddressPositions(pstns) else: getattr(adr,setter)(self.filterPI(data[k]) or None) if hasattr(adr,setter) else setattr(adr,new_prefix,self.filterPI(data[k]) or None) return adr
def test30_checkPopulatedAddressChangeDict(self): '''Tests whether JSON object gets created correctly''' #this function has moved to addressfactory testlog.debug( 'Test_1.30 Attributes set to match JSON sample and compare') #return True for asm in self._address_setters: if asm == 'setAddressPositions': getattr(self._address, asm)([ Position(), ]) continue aval = self._generateAttrVal(asm) getattr(self._address, asm)(aval) self._address.setVersion(100) for at in (ActionType.ADD, ActionType.RETIRE, ActionType.UPDATE): jresult = AddressChangeFactory().convertAddress(self._address, at) self.assertEqual( jresult, getTestData(at), 'JSON Address constructed incorrectly {}'.format(jresult))