Beispiel #1
0
def consume_nr(
        business: Business,
        filing: Filing,
        nr_num_path='/filing/incorporationApplication/nameRequest/nrNumber'):
    """Update the nr to a consumed state."""
    try:
        nr_num = get_str(filing.filing_json, nr_num_path)
        # skip this if none (nrNumber will not be available for numbered company)
        if nr_num:
            bootstrap = RegistrationBootstrap.find_by_identifier(
                filing.temp_reg)
            namex_svc_url = current_app.config.get('NAMEX_API')
            token = AccountService.get_bearer_token()

            # Create an entity record
            data = json.dumps({'consume': {'corpNum': business.identifier}})
            rv = requests.patch(
                url=''.join([namex_svc_url, nr_num]),
                headers={
                    **AccountService.CONTENT_TYPE_JSON, 'Authorization':
                    AccountService.BEARER + token
                },
                data=data,
                timeout=AccountService.timeout)
            if not rv.status_code == HTTPStatus.OK:
                raise QueueException

            # remove the NR from the account
            AccountService.delete_affiliation(bootstrap.account, nr_num)
    except KeyError:
        pass  # return
    except Exception:  # pylint: disable=broad-except; note out any exception, but don't fail the call
        sentry_sdk.capture_message(
            f'Queue Error: Consume NR error for filing:{filing.id}',
            level='error')
Beispiel #2
0
def consume_nr(
        business: Business,
        filing: Filing,
        nr_num_path='/filing/incorporationApplication/nameRequest/nrNumber'):
    """Update the nr to a consumed state."""
    try:
        # skip this if none (nrNumber will not be available for numbered company)
        if nr_num := get_str(filing.filing_json, nr_num_path):

            namex_svc_url = current_app.config.get('NAMEX_API')
            token = AccountService.get_bearer_token()

            # Create an entity record
            data = json.dumps({'consume': {'corpNum': business.identifier}})
            rv = requests.patch(
                url=''.join([namex_svc_url, nr_num]),
                headers={
                    **AccountService.CONTENT_TYPE_JSON, 'Authorization':
                    AccountService.BEARER + token
                },
                data=data,
                timeout=AccountService.timeout)
            if not rv.status_code == HTTPStatus.OK:
                raise QueueException

            # remove the NR from the account
            if filing.temp_reg and (bootstrap :=
                                    RegistrationBootstrap.find_by_identifier(
                                        filing.temp_reg)):
                AccountService.delete_affiliation(bootstrap.account, nr_num)
Beispiel #3
0
def update_affiliation(business: Business, filing: Filing):
    """Create an affiliation for the business and remove the bootstrap."""
    try:
        bootstrap = RegistrationBootstrap.find_by_identifier(filing.temp_reg)

        rv = AccountService.create_affiliation(
            account=bootstrap.account,
            business_registration=business.identifier,
            business_name=business.legal_name,
            corp_type_code=business.legal_type)

        if rv not in (HTTPStatus.OK, HTTPStatus.CREATED):
            deaffiliation = AccountService.delete_affiliation(
                bootstrap.account, business.identifier)
            sentry_sdk.capture_message(
                f'Queue Error: Unable to affiliate business:{business.identifier} for filing:{filing.id}',
                level='error')
        else:
            # flip the registration
            # recreate the bootstrap, but point to the new business in the name
            old_bs_affiliation = AccountService.delete_affiliation(
                bootstrap.account, bootstrap.identifier)
            new_bs_affiliation = AccountService.create_affiliation(
                account=bootstrap.account,
                business_registration=bootstrap.identifier,
                business_name=business.identifier,
                corp_type_code='TMP')
            reaffiliate = bool(
                new_bs_affiliation in (HTTPStatus.OK, HTTPStatus.CREATED)
                and old_bs_affiliation == HTTPStatus.OK)

        if rv not in (HTTPStatus.OK, HTTPStatus.CREATED) \
                or ('deaffiliation' in locals() and deaffiliation != HTTPStatus.OK)\
                or ('reaffiliate' in locals() and not reaffiliate):
            raise QueueException
    except Exception as err:  # pylint: disable=broad-except; note out any exception, but don't fail the call
        sentry_sdk.capture_message(
            f'Queue Error: Affiliation error for filing:{filing.id}, with err:{err}',
            level='error')
def bootstrap(account):
    """Create a IA filing for processing."""
    from legal_api.services.bootstrap import AccountService

    bootstrap = RegistrationBootstrapService.create_bootstrap(account=account)
    RegistrationBootstrapService.register_bootstrap(bootstrap,
                                                    bootstrap.identifier)
    identifier = bootstrap.identifier

    yield identifier

    try:
        rv = AccountService.delete_affiliation(account, identifier)
        print(rv)
    except Exception as err:
        print(err)
Beispiel #5
0
def test_account_affiliation_integration(account, app_ctx):
    """Assert that the affiliation can be created."""
    business_registration = (
        f'T{random.SystemRandom().getrandbits(0x58)}')[:10]
    r = AccountService.create_affiliation(
        account=account,
        business_registration=business_registration,
        business_name='')

    assert r == HTTPStatus.OK

    r = AccountService.update_entity(
        business_registration=business_registration,
        business_name=business_registration,
        corp_type_code='BEN')

    assert r == HTTPStatus.OK

    r = AccountService.delete_affiliation(
        account=account, business_registration=business_registration)

    # @TODO change this next sprint when affiliation service is updated.
    assert r == HTTPStatus.OK