Ejemplo n.º 1
0
def test_all_aliases(app, session):
    """Assert that aliases are altered correctly."""
    # setup
    identifier = 'BC1234567'
    alias_1 = 'A1 LTD.'
    alias_2 = 'A2 LTD.'
    alias_3 = 'A3 LTD.'
    alias_4 = 'A4 LTD.'
    business = create_business(identifier)
    business.aliases.append(Alias(alias=alias_1, type=Alias.AliasType.TRANSLATION.value))
    business.aliases.append(Alias(alias=alias_2, type=Alias.AliasType.TRANSLATION.value))
    business.save()
    business_aliases = business.aliases.all()
    assert len(business_aliases) == 2
    component = {'nameTranslations':  [
        {
            'id': str(business_aliases[0].id),
            'name': alias_3
        },
        {
            'name': alias_4
        }
    ]}

    # test
    aliases.update_aliases(business, component.get('nameTranslations'))

    # validate
    business_aliases = business.aliases.all()
    assert 2 == len(business_aliases)
    assert next((x for x in business_aliases if
                 str(x.id) == component['nameTranslations'][0]['id']), None).alias == alias_3.upper()
    assert next((x for x in business_aliases if x.alias == component['nameTranslations'][1]['name'].upper()), None)
    assert not next((x for x in business_aliases if x.alias == alias_1.upper()), None)
    assert not next((x for x in business_aliases if x.alias == alias_2.upper()), None)
Ejemplo n.º 2
0
def test_modified_aliases(app, session):
    """Assert that aliases are altered."""
    # setup
    identifier = 'BC1234567'
    old_value_1 = 'A1 LTD.'
    new_value_1 = 'SOCIÉTÉ GÉNÉRALE'
    old_value_2 = 'B1 LTD.'
    new_value_2 = 'B2 LTD.'
    business = create_business(identifier)
    business.aliases.append(Alias(alias=old_value_1, type=Alias.AliasType.TRANSLATION.value))
    business.aliases.append(Alias(alias=old_value_2, type=Alias.AliasType.TRANSLATION.value))
    business.save()
    business_aliases = business.aliases.all()
    assert len(business_aliases) == 2
    component = {'nameTranslations': [
        {
            'id': str(business_aliases[0].id),
            'name': new_value_1
        },
        {
            'id': str(business_aliases[1].id),
            'name': new_value_2
        }
    ]}

    # test
    aliases.update_aliases(business, component.get('nameTranslations'))

    # validate
    business_aliases = business.aliases.all()
    assert len(business_aliases) == 2
    for alias in component['nameTranslations']:
        business_alias = next((x for x in business_aliases if str(x.id) == alias['id']), None)
        assert business_alias.alias == alias['name'].upper()
Ejemplo n.º 3
0
def test_new_aliases(app, session):
    """Assert that the new aliases are created."""
    # setup
    identifier = 'BC1234567'
    business = create_business(identifier)
    component = {'nameTranslations': [{'name': 'MÉDIAS DE TRANSPORT INC.'}, {'name': 'CLUDIANT MEDIA INC.'}]}

    # test
    aliases.update_aliases(business, component.get('nameTranslations'))

    # validate
    new_aliases = business.aliases.all()
    assert len(component['nameTranslations']) == len(new_aliases)
Ejemplo n.º 4
0
def process(business: Business, filing: Dict):
    """Render the Alteration onto the model objects."""
    # Alter the corp type, if any
    with suppress(IndexError, KeyError, TypeError):
        business_json = dpath.util.get(filing, '/alteration/business')
        business_info.set_corp_type(business, business_json)

    # update name translations, if any
    with suppress(IndexError, KeyError, TypeError):
        business_json = dpath.util.get(filing, '/alteration/nameTranslations')
        aliases.update_aliases(business, business_json)

    # update share structure and resolutions, if any
    with suppress(IndexError, KeyError, TypeError):
        share_structure = dpath.util.get(filing, '/alteration/shareStructure')
        shares.update_share_structure(business, share_structure)
Ejemplo n.º 5
0
def test_cease_aliases(app, session):
    """Assert that aliases are removed."""
    # setup
    identifier = 'BC1234567'
    alias_1 = 'A1 LTD.'
    alias_2 = 'A2 LTD.'
    alias_3 = 'A3 LTD.'
    business = create_business(identifier)
    business.aliases.append(Alias(alias=alias_1, type=Alias.AliasType.TRANSLATION.value))
    business.aliases.append(Alias(alias=alias_2, type=Alias.AliasType.TRANSLATION.value))
    business.save()
    assert len(business.aliases.all()) == 2

    component = {'nameTranslations': [
        {'name': alias_3}
    ]}

    # test
    aliases.update_aliases(business, component.get('nameTranslations'))

    # validate
    business_aliases = business.aliases.all()
    assert 1 == len(business_aliases)
    assert business_aliases[0].alias == alias_3.upper()
Ejemplo n.º 6
0
def process(business: Business, filing_rec: Filing, filing: Dict,
            filing_meta: FilingMeta):
    # pylint: disable=too-many-locals; 1 extra
    """Process the incoming transition filing."""
    # Extract the filing information for transition application
    if not (transition_filing := filing.get('transition')):  # pylint: disable=superfluous-parens;
        raise QueueException(
            f'legal_filing:transition data missing from {filing_rec.id}')
    if not business:
        raise QueueException(
            f'Business does not exist: legal_filing:transitionApplication {filing_rec.id}'
        )

    # Initial insert of the business record
    business.restriction_ind = transition_filing.get('hasProvisions')

    if offices := transition_filing['offices']:
        update_offices(business, offices)

    if parties := transition_filing.get('parties'):
        update_parties(business, parties)

    if share_structure := transition_filing['shareStructure']:
        shares.update_share_structure(business, share_structure)

    if name_translations := transition_filing.get('nameTranslations'):
        aliases.update_aliases(business, name_translations)

    return filing_rec
Ejemplo n.º 7
0
                **{
                    'fromLegalName': business.legal_name,
                    'toLegalName': legal_name
                }
            }
        name_request.set_legal_name(business, name_request_json)

    # update court order, if any is present
    with suppress(IndexError, KeyError, TypeError):
        court_order_json = dpath.util.get(filing, '/alteration/courtOrder')
        filings.update_filing_court_order(filing_submission, court_order_json)

    # update name translations, if any
    with suppress(IndexError, KeyError, TypeError):
        alias_json = dpath.util.get(filing, '/alteration/nameTranslations')
        aliases.update_aliases(business, alias_json)

    # update share structure and resolutions, if any
    with suppress(IndexError, KeyError, TypeError):
        share_structure = dpath.util.get(filing, '/alteration/shareStructure')
        shares.update_share_structure(business, share_structure)


def post_process(business: Business, filing: Filing, correction: bool = False):
    """Post processing activities for incorporations.

    THIS SHOULD NOT ALTER THE MODEL
    """
    if not correction and name_request.has_new_nr_for_alteration(
            business, filing.filing_json):
        name_request.consume_nr(business, filing,