def get(identifier): """Return a JSON object with name request information.""" try: nr_response = namex.query_nr_number(identifier) # Errors in general will just pass though, # 404 is overriden as it is giving namex-api specific messaging if nr_response.status_code == 404: return make_response( jsonify(message='{} not found.'.format(identifier)), 404) return jsonify(nr_response.json()) except Exception as err: current_app.logger.error(err) abort(500)
def get(identifier): """Return a JSON object with meta information about the Service.""" business = Business.find_by_identifier(identifier) is_nr = identifier.startswith('NR') # Check if this is a NR if is_nr: # Fetch NR Data nr_response = namex.query_nr_number(identifier) # Validate NR data validation_result = namex.validate_nr(nr_response.json()) # Return error if the NR is not consumable (invalid) if not validation_result['is_consumable']: return jsonify({ 'message': f'{identifier} is invalid', 'validation': validation_result }), HTTPStatus.FORBIDDEN if not business: # Create Incorporate using NR to-do item if is_nr: rv = [] rv.append( TaskListResource.create_incorporate_nr_todo( nr_response.json(), 1, True)) # business does not exist and not an nr so return empty task list else: rv = [] else: rv = TaskListResource.construct_task_list(business) if not rv and is_nr: paid_completed_filings = Filing.get_filings_by_status( business.id, [Filing.Status.PAID.value, Filing.Status.COMPLETED.value]) # Append NR todo if there are no tasks and PAID or COMPLETED filings if not paid_completed_filings: rv.append( TaskListResource.create_incorporate_nr_todo( nr_response.json(), 1, True)) elif rv == 'pay_connection_error': return { 'message': 'Failed to get payment details for a filing. Please try again later.' }, HTTPStatus.SERVICE_UNAVAILABLE return jsonify(tasks=rv)
def _check_and_update_nr(filing): """Check and update NR to extend expiration date as needed.""" # if this is an incorporation filing for a name request if filing.filing_type == Filing.FILINGS[ 'incorporationApplication'].get('name'): nr_number = filing.json['filing']['incorporationApplication'][ 'nameRequest'].get('nrNumber', None) effective_date = filing.json['filing']['header'].get( 'effectiveDate', None) if effective_date: effective_date = datetime.datetime.fromisoformat( effective_date) if nr_number: nr_response = namex.query_nr_number(nr_number) # If there is an effective date, check if we need to extend the NR expiration if effective_date and namex.is_date_past_expiration( nr_response.json(), effective_date): namex.update_nr_as_future_effective( nr_response.json(), effective_date)
def test_name_request_update_expiration(app, client): """Assert that nr expiration can be updated.""" with app.app_context(): nr_original = namex.query_nr_number('NR 2772704') effective_date = LegislationDatetime.tomorrow_midnight() # expecting a buffer in the date to make sure future effective filings have time to process effective_date = (effective_date + datedelta.datedelta(days=1)).astimezone(pytz.timezone('GMT')) expected_date_string = effective_date.strftime(namex.DATE_FORMAT) nr_response = namex.update_nr_as_future_effective(nr_original.json(), LegislationDatetime.tomorrow_midnight()) json = nr_response.json() # check if expiration is extended assert json['expirationDate'] == expected_date_string # revert to original json nr_response = namex.update_nr(nr_original.json()) assert nr_response.json()['expirationDate'] == nr_original.json()['expirationDate']
def company_name_validation(filing): """Validate share structure.""" msg = [] nr_path: Final = '/filing/alteration/nameRequest/nrNumber' if nr_number := get_str(filing, nr_path): # ensure NR is approved or conditionally approved nr_response = namex.query_nr_number(nr_number) validation_result = namex.validate_nr(nr_response) if not nr_response['requestTypeCd'] in ('CCR', 'CCP', 'BEC'): msg.append({ 'error': babel( 'Alteration only available for Change of Name Name requests.' ), 'path': nr_path }) if not validation_result['is_approved']: msg.append({ 'error': babel('Alteration of Name Request is not approved.'), 'path': nr_path }) # ensure NR request has the same legal name legal_name_path: Final = '/filing/alteration/nameRequest/legalName' legal_name = get_str(filing, legal_name_path) nr_name = namex.get_approved_name(nr_response) if nr_name != legal_name: msg.append({ 'error': babel( 'Alteration of Name Request has a different legal name.'), 'path': legal_name_path })