def test_full_access_to_name_request(test_name, \ name_request_number, temp_request_number, user_email, user_phone, \ header_name_request_number, header_temp_request_number, header_user_email, header_user_phone, \ expected): """Assure that this contains the headers required to fully access an NR.""" from namex.utils.auth import full_access_to_name_request # setup nr = RequestDAO() nr.nrNum = name_request_number or temp_request_number nr.stateCd = State.DRAFT nr._source = ValidSources.NAMEREQUEST.value applicant = Applicant() applicant.phoneNumber = user_phone applicant.emailAddress = user_email nr.applicants.append(applicant) nr.save_to_db() builder = EnvironBuilder(method='POST', data={}, headers={ 'BCREG_NR': header_name_request_number, 'BCREG_NRL': header_temp_request_number, 'BCREG-User-Email': header_user_email, 'BCREG-User-Phone': header_user_phone }) env = builder.get_environ() req = Request(env) print(req) assert expected == full_access_to_name_request(req)
def create_applicant(cls): try: applicant = Applicant() applicant.partyId = cls.get_applicant_sequence() except Exception as err: raise MapRequestApplicantError(err, 'Error setting applicant and / or sequence.') return applicant
def test_request_add_applicant_existing(app, request, session, applicant1, applicant2): # imports for just this test from namex.models import Applicant from namex.services.nro.request_utils import add_applicant # SETUP # create an NR and add an applicant nr = Request() nr.activeUser = User('idir/bob', 'bob', 'last', 'idir', 'localhost') nr.applicants.append(Applicant(**applicant1)) session.add(nr) session.commit() # Test # Call add_applicant and then assert the new NR applicant matches our data add_applicant(nr, applicant2) session.add(nr) session.commit() appl = nr.applicants.one_or_none() nra = dict_to_json_keys(applicant2) a = appl.as_dict() if a.get('partyId'): a.pop('partyId') # check entire dict assert nra == a
def set_applicant_attributes(json_data, nr_id): # applicant, contact and address info for applicant in json_data.get('applicants', None): nrd_app = Applicant() party_id = get_applicant_sequence() nrd_app.nrId = nr_id nrd_app.partyId = party_id nrd_app.lastName = convert_to_ascii(applicant['lastName']) nrd_app.firstName = convert_to_ascii(applicant['firstName']) if applicant['middleName']: nrd_app.middleName = convert_to_ascii(applicant['middleName']) nrd_app.contact = convert_to_ascii(applicant['contact']) if applicant['middleName']: nrd_app.middleName = convert_to_ascii(applicant['middleName']) if applicant['clientFirstName']: nrd_app.clientFirstName = convert_to_ascii( applicant['clientFirstName']) if applicant['clientLastName']: nrd_app.clientLastName = convert_to_ascii( applicant['clientLastName']) if applicant['phoneNumber']: nrd_app.phoneNumber = convert_to_ascii(applicant['phoneNumber']) if applicant['faxNumber']: nrd_app.faxNumber = convert_to_ascii(applicant['faxNumber']) nrd_app.emailAddress = convert_to_ascii(applicant['emailAddress']) nrd_app.addrLine1 = convert_to_ascii(applicant['addrLine1']) if applicant['addrLine2']: nrd_app.addrLine2 = convert_to_ascii(applicant['addrLine2']) nrd_app.city = convert_to_ascii(applicant['city']) nrd_app.stateProvinceCd = applicant['stateProvinceCd'] nrd_app.postalCd = convert_to_ascii(applicant['postalCd']) nrd_app.countryTypeCd = applicant['countryTypeCd'] return nrd_app
def add_applicant(nr, nr_applicant): applicant = nr.applicants.one_or_none() if not applicant: applicant = Applicant() nr.applicants.append(applicant) applicant.lastName = nr_applicant['last_name'] applicant.firstName = nr_applicant['first_name'] applicant.middleName = nr_applicant['middle_name'] applicant.phoneNumber = nr_applicant['phone_number'] applicant.faxNumber = nr_applicant['fax_number'] applicant.emailAddress = nr_applicant['email_address'] applicant.contact = nr_applicant['contact'] applicant.clientFirstName = nr_applicant['client_first_name'] applicant.clientLastName = nr_applicant['client_last_name'] applicant.declineNotificationInd = nr_applicant['decline_notification_ind'] applicant.addrLine1 = nr_applicant['addr_line_1'] applicant.addrLine2 = nr_applicant['addr_line_2'] applicant.addrLine3 = nr_applicant['addr_line_3'] applicant.city = nr_applicant['city'] applicant.postalCd = nr_applicant['postal_cd'] applicant.stateProvinceCd = nr_applicant['state_province_cd'] applicant.countryTypeCd = nr_applicant['country_type_cd']
def map_request_applicant(applicant: Applicant, request_applicant: dict): applicant.lastName = convert_to_ascii(request_applicant.get('lastName')) applicant.firstName = convert_to_ascii(request_applicant.get('firstName')) if request_applicant.get('middleName'): applicant.middleName = convert_to_ascii(request_applicant.get('middleName')) applicant.contact = convert_to_ascii(request_applicant.get('contact')) if request_applicant.get('clientFirstName'): applicant.clientFirstName = convert_to_ascii(request_applicant.get('clientFirstName')) if request_applicant.get('clientLastName'): applicant.clientLastName = convert_to_ascii(request_applicant.get('clientLastName')) if request_applicant.get('phoneNumber'): applicant.phoneNumber = convert_to_ascii(request_applicant.get('phoneNumber')) if request_applicant.get('faxNumber'): applicant.faxNumber = convert_to_ascii(request_applicant.get('faxNumber')) applicant.emailAddress = convert_to_ascii(request_applicant.get('emailAddress')) applicant.addrLine1 = convert_to_ascii(request_applicant.get('addrLine1')) if request_applicant.get('addrLine2'): applicant.addrLine2 = convert_to_ascii(request_applicant.get('addrLine2')) if request_applicant.get('addrLine3'): applicant.addrLine3 = convert_to_ascii(request_applicant.get('addrLine3')) applicant.city = convert_to_ascii(request_applicant.get('city')) applicant.stateProvinceCd = request_applicant.get('stateProvinceCd') applicant.postalCd = convert_to_ascii(request_applicant.get('postalCd')) applicant.countryTypeCd = request_applicant.get('countryTypeCd') return applicant
def create_applicant(first_name: str, last_name: str) -> Applicant: """Create new applicant.""" applicant = Applicant(firstName=first_name, lastName=last_name) applicant.save_to_db() return applicant