Exemplo n.º 1
0
def test_delete_filing_block_completed(session, client, jwt):
    """Assert that a completed filing cannot be deleted."""
    import copy
    identifier = 'CP7654321'
    business = factory_business(identifier,
                                founding_date=(datetime.utcnow() -
                                               datedelta.YEAR))
    factory_business_mailing_address(business)
    ar = copy.deepcopy(ANNUAL_REPORT)
    ar['filing']['annualReport']['annualReportDate'] = datetime.utcnow().date(
    ).isoformat()
    ar['filing']['annualReport']['annualGeneralMeetingDate'] = datetime.utcnow(
    ).date().isoformat()

    filings = factory_completed_filing(business, ar)

    rv = client.delete(f'/api/v1/businesses/{identifier}/filings/{filings.id}',
                       headers=create_header(jwt, [STAFF_ROLE], identifier))

    assert rv.status_code == HTTPStatus.FORBIDDEN
Exemplo n.º 2
0
def test_invalid_par_value(session):
    """Assert that model validates share class par value."""
    identifier = 'CP1234567'
    business = factory_business(identifier)
    share_class = ShareClass(name='Share Class 1',
                             priority=1,
                             max_share_flag=True,
                             max_shares=1000,
                             par_value_flag=True,
                             par_value=None,
                             currency='CAD',
                             special_rights_flag=False,
                             business_id=business.id)
    with pytest.raises(BusinessException) as share_class_error:
        share_class.save()
    session.rollback()

    assert share_class_error
    assert share_class_error.value.status_code == HTTPStatus.BAD_REQUEST
    assert share_class_error.value.error == f'The share class {share_class.name} must specify par value.'
Exemplo n.º 3
0
def test_get_business_ceased_directors(session, client, jwt):
    """Assert that business directors are not returned."""
    # setup
    identifier = 'CP7654321'
    business = factory_business(identifier)
    director = Director(first_name='Michael',
                        last_name='Crane',
                        middle_initial='Joe',
                        title='VP',
                        appointment_date=datetime.datetime(2012, 5, 17),
                        cessation_date=datetime.datetime(2013, 5, 17))
    business.directors.append(director)
    business.save()

    # test
    rv = client.get(f'/api/v1/businesses/{identifier}/directors',
                    headers=create_header(jwt, [STAFF_ROLE], identifier))
    # check
    assert rv.status_code == HTTPStatus.OK
    assert rv.json['directors'] == []
Exemplo n.º 4
0
def test_get_tasks_error_filings(session, client, jwt):
    """Assert that to-do list returns the error filings."""
    from legal_api.models import Filing
    from tests.unit.models import AR_FILING, factory_business_mailing_address
    # setup
    identifier = 'CP7654321'
    b = factory_business(identifier, last_ar_date=datetime(2019, 8, 13))
    factory_business_mailing_address(b)
    filing = factory_pending_filing(b, AR_FILING,
                                    datetime(2019, 8, 5, 7, 7, 58, 272362))
    filing.save()
    assert filing.status == Filing.Status.PENDING.value

    # test endpoint returned filing in tasks call
    rv = client.get(f'/api/v2/businesses/{identifier}/tasks',
                    headers=create_header(jwt, [STAFF_ROLE], identifier))
    assert rv.status_code == HTTPStatus.OK
    # assert len(rv.json['tasks']) == 3
    assert rv.json['tasks'][0]['task']['filing']['header'][
        'filingId'] == filing.id
def test_get_business_addresses_by_id(session, client, jwt):
    """Assert that business address is returned."""
    # setup
    identifier = 'CP7654321'
    business = factory_business(identifier)
    mailing_address = Address(city='Test Mailing City',
                              address_type=Address.MAILING,
                              business_id=business.id)
    office = Office(office_type='registeredOffice')
    office.addresses.append(mailing_address)
    business.offices.append(office)
    business.save()

    # test
    rv = client.get(
        f'/api/v2/businesses/{identifier}/addresses/{mailing_address.id}',
        headers=create_header(jwt, [STAFF_ROLE], identifier))
    # check
    assert rv.status_code == HTTPStatus.OK
    assert 'mailingAddress' in rv.json
def test_get_business_delivery_addresses_by_type(session, client, jwt):
    """Assert that business address type is returned."""
    # setup
    identifier = 'CP7654321'
    business = factory_business(identifier)
    delivery_address = Address(city='Test Delivery City',
                               address_type=Address.DELIVERY,
                               business_id=business.id)
    office = Office(office_type='registeredOffice')
    office.addresses.append(delivery_address)
    business.offices.append(office)
    business.save()

    # test
    rv = client.get(
        f'/api/v2/businesses/{identifier}/addresses?addressType={Address.JSON_DELIVERY}',
        headers=create_header(jwt, [STAFF_ROLE], identifier))
    # check
    assert rv.status_code == HTTPStatus.OK
    assert Address.JSON_DELIVERY in rv.json
def test_get_business_resolution_by_id(session, client, jwt):
    """Assert that business resolution is returned."""
    # setup
    identifier = 'CP7654321'
    business = factory_business(identifier)
    resolution_1 = Resolution(resolution_date='2020-02-02',
                              resolution_type='ORDINARY',
                              business_id=business.id)
    resolution_2 = Resolution(resolution_date='2020-03-03',
                              resolution_type='SPECIAL',
                              business_id=business.id)
    resolution_1.save()
    resolution_2.save()
    # test
    rv = client.get(
        f'/api/v1/businesses/{identifier}/resolutions/{resolution_1.id}',
        headers=create_header(jwt, [STAFF_ROLE], identifier))
    # check
    assert rv.status_code == HTTPStatus.OK
    assert rv.json['resolution']['date'] == '2020-02-02'
Exemplo n.º 8
0
def test_get_internal_filings(session, client, jwt):
    """Assert that the internal filings get endpoint returns all completed filings without colin ids."""
    from legal_api.models import Filing
    from legal_api.models.colin_event_id import ColinEventId
    from tests.unit.models import factory_error_filing, factory_pending_filing
    # setup
    identifier = 'CP7654321'
    b = factory_business(identifier)
    factory_business_mailing_address(b)

    filing1 = factory_completed_filing(b, ANNUAL_REPORT)
    filing2 = factory_completed_filing(b, ANNUAL_REPORT)
    filing3 = factory_pending_filing(b, ANNUAL_REPORT)
    filing4 = factory_filing(b, ANNUAL_REPORT)
    filing5 = factory_error_filing(b, ANNUAL_REPORT)
    filing6 = factory_completed_filing(b, CORRECTION_AR)

    assert filing1.status == Filing.Status.COMPLETED.value
    # completed with colin_event_id
    print(filing2.colin_event_ids)
    assert len(filing2.colin_event_ids) == 0
    colin_event_id = ColinEventId()
    colin_event_id.colin_event_id = 12345
    filing2.colin_event_ids.append(colin_event_id)
    filing2.save()
    assert filing2.status == Filing.Status.COMPLETED.value
    assert filing2.colin_event_ids
    # pending with no colin_event_ids
    assert filing3.status == Filing.Status.PENDING.value
    # draft with no colin_event_ids
    assert filing4.status == Filing.Status.DRAFT.value
    # error with no colin_event_ids
    assert filing5.status == Filing.Status.PAID.value
    # completed correction with no colin_event_ids
    assert filing6.status == Filing.Status.COMPLETED.value

    # test endpoint returned filing1 only (completed, no corrections, with no colin id set)
    rv = client.get(f'/api/v1/businesses/internal/filings')
    assert rv.status_code == HTTPStatus.OK
    assert len(rv.json) == 1
    assert rv.json[0]['filingId'] == filing1.id
Exemplo n.º 9
0
def test_get_colin_id(session, client, jwt):
    """Assert the internal/filings/colin_id get endpoint returns properly."""
    from legal_api.models.colin_event_id import ColinEventId
    # setup
    identifier = 'CP7654321'
    b = factory_business(identifier)
    factory_business_mailing_address(b)
    filing = factory_completed_filing(b, ANNUAL_REPORT)
    colin_event_id = ColinEventId()
    colin_event_id.colin_event_id = 1234
    filing.colin_event_ids.append(colin_event_id)
    filing.save()

    rv = client.get(
        f'/api/v1/businesses/internal/filings/colin_id/{colin_event_id.colin_event_id}'
    )
    assert rv.status_code == HTTPStatus.OK
    assert rv.json == {'colinId': colin_event_id.colin_event_id}

    rv = client.get(f'/api/v1/businesses/internal/filings/colin_id/{1}')
    assert rv.status_code == HTTPStatus.NOT_FOUND
Exemplo n.º 10
0
def test_update_ar_with_a_missing_filing_id_fails(session, client, jwt):
    """Assert that updating a missing filing fails."""
    import copy
    identifier = 'CP7654321'
    business = factory_business(identifier,
                                founding_date=(datetime.utcnow() - datedelta.YEAR)
                                )
    factory_business_mailing_address(business)
    ar = copy.deepcopy(ANNUAL_REPORT)
    ar['filing']['annualReport']['annualReportDate'] = datetime.utcnow().date().isoformat()
    ar['filing']['annualReport']['annualGeneralMeetingDate'] = datetime.utcnow().date().isoformat()

    filings = factory_filing(business, ar)

    rv = client.put(f'/api/v1/businesses/{identifier}/filings/{filings.id+1}',
                    json=ar,
                    headers=create_header(jwt, [STAFF_ROLE], identifier)
                    )

    assert rv.status_code == HTTPStatus.NOT_FOUND
    assert rv.json['errors'][0] == {'message': f'{identifier} no filings found'}
Exemplo n.º 11
0
def test_share_quantity_when_no_max_share_for_parent(session):
    """Assert that model validates share series share quantity."""
    identifier = 'CP1234567'
    business = factory_business(identifier)
    share_class = ShareClass(name='Share Class 1',
                             priority=1,
                             max_share_flag=False,
                             max_shares=None,
                             par_value_flag=True,
                             par_value=0.852,
                             currency='CAD',
                             special_rights_flag=False,
                             business_id=business.id)
    share_series_1 = ShareSeries(name='Share Series 1',
                                 priority=1,
                                 max_share_flag=True,
                                 max_shares=1500,
                                 special_rights_flag=False)
    share_class.series.append(share_series_1)
    share_class.save()
    assert share_series_1.id
Exemplo n.º 12
0
def test_update_block_ar_update_to_a_paid_filing(session, client, jwt):
    """Assert that a valid filing can NOT be updated once it has been paid."""
    import copy
    identifier = 'CP7654321'
    business = factory_business(identifier,
                                founding_date=(datetime.utcnow() - datedelta.YEAR)
                                )
    factory_business_mailing_address(business)
    ar = copy.deepcopy(ANNUAL_REPORT)
    ar['filing']['annualReport']['annualReportDate'] = datetime.utcnow().date().isoformat()
    ar['filing']['annualReport']['annualGeneralMeetingDate'] = datetime.utcnow().date().isoformat()

    filings = factory_completed_filing(business, ar)

    rv = client.put(f'/api/v1/businesses/{identifier}/filings/{filings.id}',
                    json=ar,
                    headers=create_header(jwt, [STAFF_ROLE], identifier)
                    )

    assert rv.status_code == HTTPStatus.FORBIDDEN
    assert rv.json['errors'][0] == {'error': 'Filings cannot be changed after the invoice is created.'}
Exemplo n.º 13
0
def test_filing_court_order(client, jwt, session):
    """Assert that a valid court order filing can be posted."""
    identifier = 'BC1156638'
    b = factory_business(identifier, datetime.datetime.utcnow(), None,
                         Business.LegalTypes.COMP.value)
    factory_business_mailing_address(b)

    filing = copy.deepcopy(COURT_ORDER_FILING_TEMPLATE)
    filing['filing']['business']['identifier'] = identifier

    rv = client.post(f'/api/v1/businesses/{identifier}/filings',
                     json=filing,
                     headers=create_header(jwt, [STAFF_ROLE], None))

    assert rv.status_code == HTTPStatus.CREATED
    assert rv.json['filing']['header']['name'] == 'courtOrder'

    filing = Filing.get_filing_by_payment_token(
        rv.json['filing']['header']['paymentToken'])
    assert filing
    assert filing.status == Filing.Status.PENDING.value
Exemplo n.º 14
0
def test_get_business_delivery_addresses_by_type_missing_address(
        session, client, jwt):
    """Assert that business addresses are not returned."""
    # setup
    identifier = 'CP7654321'
    business = factory_business(identifier)
    delivery_address = Address(city='Test Delivery City',
                               address_type=Address.DELIVERY,
                               business_id=business.id)
    office = Office(office_type='registeredOffice')
    office.addresses.append(delivery_address)
    business.offices.append(office)
    business.save()

    # test
    rv = client.get(
        f'/api/v1/businesses/{identifier}/addresses?addressType={Address.JSON_MAILING}',
        headers=create_header(jwt, [STAFF_ROLE], identifier))
    # check
    assert rv.status_code == HTTPStatus.NOT_FOUND
    assert rv.json == {'message': f'{identifier} address not found'}
Exemplo n.º 15
0
def test_alteration_success_ben_to_bc(client, jwt, session):
    """Assert that a valid BEN to BC alteration can be posted."""
    identifier = 'BC1156638'
    b = factory_business(identifier, datetime.datetime.utcnow(), None, Business.LegalTypes.BCOMP.value)
    factory_business_mailing_address(b)

    filing = copy.deepcopy(ALTERATION_FILING_TEMPLATE)
    filing['filing']['business']['identifier'] = identifier
    filing['filing']['business']['legalType'] = Business.LegalTypes.BCOMP.value
    filing['filing']['alteration']['business']['legalType'] = Business.LegalTypes.COMP.value

    rv = client.post(f'/api/v1/businesses/{identifier}/filings',
                     json=filing,
                     headers=create_header(jwt, [STAFF_ROLE], None))

    assert rv.status_code == HTTPStatus.CREATED
    assert rv.json['filing']['header']['name'] == 'alteration'

    filing = Filing.get_filing_by_payment_token(rv.json['filing']['header']['paymentToken'])
    assert filing
    assert filing.status == Filing.Status.PENDING.value
Exemplo n.º 16
0
def test_filing_comment_dump_json(session):
    """Assert the comment json serialization works correctly."""
    identifier = 'CP7654321'
    b = factory_business(identifier)
    f = factory_filing(b, ANNUAL_REPORT)
    c = factory_comment(b, f, 'a comment')

    system_timezone = datetime.datetime.now().astimezone().tzinfo
    expected_timestamp = \
        datetime.datetime(1970, 1, 1, 0, 0).replace(tzinfo=datetime.timezone.utc).astimezone(tz=system_timezone)

    assert c.json == {
        'comment': {
            'id': c.id,
            'submitterDisplayName': None,
            'comment': 'a comment',
            'filingId': f.id,
            'businessId': None,
            'timestamp': expected_timestamp.isoformat()
        }
    }
Exemplo n.º 17
0
def test_file_ar_no_agm_coop(session, client, jwt):
    """Assert that filing AR as COOP with no AGM date fails."""
    identifier = 'CP7654399'
    b = business = factory_business(
        identifier,
        founding_date=(datetime.utcnow() - datedelta.datedelta(years=2)),
        last_ar_date=datetime(datetime.utcnow().year - 1, 4, 20).date())
    factory_business_mailing_address(business)
    ar = copy.deepcopy(ANNUAL_REPORT)
    ar['filing']['annualReport']['annualReportDate'] = datetime(
        datetime.utcnow().year, 2, 20).date().isoformat()
    ar['filing']['header']['date'] = datetime.utcnow().date().isoformat()
    ar['filing']['annualReport']['annualGeneralMeetingDate'] = None
    rv = client.post(f'/api/v1/businesses/{identifier}/filings',
                     json=ar,
                     headers=create_header(jwt, [STAFF_ROLE], identifier))

    assert rv.status_code == HTTPStatus.BAD_REQUEST
    assert rv.json['errors'][0]['error'] == (
        'Annual General Meeting Date must be a '
        'valid date when submitting an Annual Report in the current year.')
Exemplo n.º 18
0
def test_get_a_businesses_most_recent_filing_of_a_type(session):
    """Assert that the most recent completed filing of a specified type is returned."""
    from legal_api.models import Filing
    from tests.unit.models import factory_completed_filing
    # setup
    identifier = 'CP7654321'
    b = factory_business(identifier)
    ar = copy.deepcopy(ANNUAL_REPORT)
    base_ar_date = datetime.datetime(2001, 8, 5, 7, 7, 58, 272362)
    filings = []
    for i in range(0, 5):
        filing_date = base_ar_date + datedelta.datedelta(years=i)
        ar['filing']['annualReport']['annualGeneralMeetingDate'] = \
            filing_date.date().isoformat()
        filing = factory_completed_filing(b, ar, filing_date)
        filings.append(filing)
    # test
    filing = Filing.get_a_businesses_most_recent_filing_of_a_type(b.id, Filing.FILINGS['annualReport']['name'])

    # assert that we get the last filing
    assert filings[4] == filing
Exemplo n.º 19
0
def test_get_business_alias_by_type(session, client, jwt):
    """Assert that business aliases matching the type are returned."""
    # setup
    # setup
    identifier = 'CP7654321'
    business = factory_business(identifier)
    alias1 = Alias(alias='ABC Ltd.',
                   type='TRANSLATION',
                   business_id=business.id)
    alias2 = Alias(alias='DEF Ltd.', type='DBA', business_id=business.id)
    alias1.save()
    alias2.save()

    # test
    rv = client.get(f'/api/v1/businesses/{identifier}/aliases?type=dba',
                    headers=create_header(jwt, [STAFF_ROLE], identifier))
    # check
    assert rv.status_code == HTTPStatus.OK
    assert 'aliases' in rv.json
    assert len(rv.json['aliases']) == 1
    assert rv.json['aliases'][0]['name'] == 'DEF Ltd.'
def test_patch_internal_filings(session, client, jwt):
    """Assert that the internal filings patch endpoint updates the colin_event_id."""
    from legal_api.models import Filing
    # setup
    identifier = 'CP7654321'
    b = factory_business(identifier)
    factory_business_mailing_address(b)
    filing = factory_completed_filing(b, ANNUAL_REPORT)
    colin_id = 1234

    # make request
    rv = client.patch(f'/api/v1/businesses/internal/filings/{filing.id}',
                      json={'colinId': colin_id},
                      headers=create_header(jwt, [COLIN_SVC_ROLE]))

    # test result
    filing = Filing.find_by_id(filing.id)
    assert rv.status_code == HTTPStatus.ACCEPTED
    assert filing.colin_event_id == colin_id
    assert rv.json['filing']['header']['filingId'] == filing.id
    assert rv.json['filing']['header']['colinId'] == colin_id
Exemplo n.º 21
0
def test_get_business_director_by_id(session, client, jwt):
    """Assert that business director is returned."""
    # setup
    identifier = 'CP7654321'
    business = factory_business(identifier)
    officer = {
        'firstName': 'Michael',
        'lastName': 'Crane',
        'middleInitial': 'Joe'
    }
    party_role = factory_party_role(None, None, officer,
                                    datetime.datetime(2017, 5, 17), None,
                                    PartyRole.RoleTypes.DIRECTOR)
    business.party_roles.append(party_role)
    business.save()
    # test
    rv = client.get(
        f'/api/v1/businesses/{identifier}/directors/{party_role.id}',
        headers=create_header(jwt, [STAFF_ROLE], identifier))
    # check
    assert rv.status_code == HTTPStatus.OK
Exemplo n.º 22
0
def test_alteration_filing_with_court_order(session):
    """Assert that an alteration filing with court order can be created."""
    identifier = 'BC1156638'
    b = factory_business(identifier, datetime.datetime.utcnow(), None,
                         Business.LegalTypes.COMP.value)
    factory_business_mailing_address(b)
    filing = factory_filing(b, ALTERATION_FILING_TEMPLATE)
    filing.court_order_file_number = COURT_ORDER['fileNumber']
    filing.court_order_date = COURT_ORDER['orderDate']
    filing.court_order_effect_of_order = COURT_ORDER['effectOfOrder']
    filing.filing_json = ALTERATION_FILING_TEMPLATE
    filing.save()
    assert filing.id is not None
    assert filing.json['filing']['alteration']['courtOrder'][
        'fileNumber'] == COURT_ORDER['fileNumber']
    assert filing.json['filing']['alteration']['courtOrder'][
        'orderDate'] == COURT_ORDER['orderDate']
    assert filing.json['filing']['alteration']['courtOrder'][
        'effectOfOrder'] == COURT_ORDER['effectOfOrder']

    assert registry_schemas.validate(filing.json, 'alteration')
Exemplo n.º 23
0
def test_update_ar_with_colin_id_set(session, client, jwt):
    """Assert that when a filing with colinId set (as when colin updates legal api) that colin_event_id is set."""
    import copy
    identifier = 'CP7654321'
    b = factory_business(identifier)
    factory_business_mailing_address(b)

    filings = factory_filing(b, AR_FILING)

    ar = copy.deepcopy(AR_FILING)
    ar['filing']['header']['colinId'] = 1234

    rv = client.put(f'/api/v1/businesses/{identifier}/filings/{filings.id}',
                    json=ar,
                    headers=create_header(jwt, [STAFF_ROLE], identifier))

    assert rv.status_code == HTTPStatus.ACCEPTED
    assert rv.json['filing']['business'] == ar['filing']['business']
    assert rv.json['filing']['annualReport'] == ar['filing']['annualReport']
    assert not rv.json['filing']['header'].get('colinId')
    assert rv.json['filing']['header']['filingId'] == filings.id
Exemplo n.º 24
0
def test_find_alias_by_business_and_type(session):
    """Assert that the method returns correct value."""
    identifier = 'CP1234567'
    business = factory_business(identifier)
    alias1 = Alias(
        alias='ABC Ltd.',
        type='TRANSLATION',
        business_id=business.id
    )
    alias2 = Alias(
        alias='DEF Ltd.',
        type='DBA',
        business_id=business.id
    )
    alias1.save()
    alias2.save()

    res = Alias.find_by_type(business.id, 'TRANSLATION')

    assert res
    assert len(res) == 1
    assert res[0].alias == 'ABC Ltd.'
Exemplo n.º 25
0
def test_get_all_business_filings_multi_in_ledger(session, client, jwt):
    """Assert that the business info can be received in a valid JSONSchema format."""
    import copy
    from tests import add_years

    ar = copy.deepcopy(ANNUAL_REPORT)
    identifier = 'CP7654321'

    # create business
    b = factory_business(identifier)

    # add 3 filings, add a year onto the AGM date
    for i in range(0, 3):
        ar['filing']['annualReport']['annualGeneralMeetingDate'] = \
            datetime.date(add_years(datetime(2001, 8, 5, 7, 7, 58, 272362), i)).isoformat()
        factory_filing(b, ar)

    rv = client.get(f'/api/v1/businesses/{identifier}/filings',
                    headers=create_header(jwt, [STAFF_ROLE], identifier))

    assert rv.status_code == HTTPStatus.OK
    assert len(rv.json.get('filings')) == 0
Exemplo n.º 26
0
def test_update_ar_filing_to_a_business(session, client, jwt):
    """Assert that a filing can be updated if not paid."""
    import copy
    identifier = 'CP7654321'
    b = factory_business(identifier)
    factory_business_mailing_address(b)
    filings = factory_filing(b, AR_FILING)
    ar = copy.deepcopy(AR_FILING)
    ar['filing']['header']['date'] = '2001-08-05'

    rv = client.put(f'/api/v1/businesses/{identifier}/filings/{filings.id}',
                    json=ar,
                    headers=create_header(jwt, [STAFF_ROLE], identifier))

    ar['filing']['header']['submitter'] = identifier
    ar['filing']['header']['date'] = rv.json['filing']['header']['date']
    assert rv.status_code == HTTPStatus.ACCEPTED
    assert rv.json['filing']['business'] == ar['filing']['business']
    assert rv.json['filing']['annualReport'] == ar['filing']['annualReport']
    assert rv.json['filing']['header']['filingId']
    assert rv.json['filing']['header']['submitter']
    assert rv.json['filing']['header']['paymentToken']
Exemplo n.º 27
0
def test_find_resolution_by_business_and_type(session):
    """Assert that the method returns correct value."""
    identifier = 'CP1234567'
    business = factory_business(identifier)
    resolution_1 = Resolution(
        resolution_date='2020-02-02',
        resolution_type='ORDINARY',
        business_id=business.id
    )
    resolution_2 = Resolution(
        resolution_date='2020-03-03',
        resolution_type='SPECIAL',
        business_id=business.id
    )
    resolution_1.save()
    resolution_2.save()

    res = Resolution.find_by_type(business.id, 'SPECIAL')

    assert res
    assert len(res) == 1
    assert res[0].json == resolution_2.json
Exemplo n.º 28
0
def test_cancel_payment_failed_connection_pay_api(monkeypatch, session, client,
                                                  jwt):
    """Assert that cancel payment failure returns error."""
    identifier = 'CP7654321'
    business = factory_business(identifier,
                                founding_date=(datetime.utcnow() -
                                               datedelta.YEAR))
    factory_business_mailing_address(business)
    ar = copy.deepcopy(ANNUAL_REPORT)
    ar['filing']['annualReport']['annualReportDate'] = datetime.utcnow().date(
    ).isoformat()
    ar['filing']['annualReport']['annualGeneralMeetingDate'] = datetime.utcnow(
    ).date().isoformat()

    rv = client.post(f'/api/v1/businesses/{identifier}/filings',
                     json=ar,
                     headers=create_header(jwt, [STAFF_ROLE], identifier))

    # check return
    assert rv.status_code == HTTPStatus.CREATED
    assert not rv.json.get('errors')
    assert rv.json['filing']['header']['filingId']
    assert rv.json['filing']['header']['paymentToken']
    assert rv.json['filing']['header']['paymentToken'] == '153'

    filing_id = rv.json['filing']['header']['filingId']

    old_svc = current_app.config.get('PAYMENT_SVC_URL')
    current_app.config['PAYMENT_SVC_URL'] = 'http://nowhere.localdomain'

    rv = client.patch(f'/api/v1/businesses/{identifier}/filings/{filing_id}',
                      json={},
                      headers=create_header(jwt, [STAFF_ROLE], identifier))

    current_app.config['PAYMENT_SVC_URL'] = old_svc
    assert rv.status_code == HTTPStatus.INTERNAL_SERVER_ERROR
    assert rv.json.get('errors')
    assert rv.json['errors'][0][
        'message'] == 'Unable to cancel payment for the filing.'
Exemplo n.º 29
0
def test_cancel_payment_for_pending_filing(session, client, jwt):
    """Assert that a filing can be completed up to payment."""
    from legal_api.models import Filing
    identifier = 'CP7654321'
    business = factory_business(identifier,
                                founding_date=(datetime.utcnow() -
                                               datedelta.YEAR))
    factory_business_mailing_address(business)
    ar = copy.deepcopy(ANNUAL_REPORT)
    ar['filing']['annualReport']['annualReportDate'] = datetime.utcnow().date(
    ).isoformat()
    ar['filing']['annualReport']['annualGeneralMeetingDate'] = datetime.utcnow(
    ).date().isoformat()

    rv = client.post(f'/api/v1/businesses/{identifier}/filings',
                     json=ar,
                     headers=create_header(jwt, [STAFF_ROLE], identifier))

    # check return
    assert rv.status_code == HTTPStatus.CREATED
    assert not rv.json.get('errors')
    assert rv.json['filing']['header']['filingId']
    assert rv.json['filing']['header']['paymentToken']
    assert rv.json['filing']['header']['paymentToken'] == '153'

    # check stored filing
    filing = Filing.get_filing_by_payment_token(
        rv.json['filing']['header']['paymentToken'])
    assert filing
    assert filing.status == Filing.Status.PENDING.value

    filing_id = rv.json['filing']['header']['filingId']
    rv = client.patch(f'/api/v1/businesses/{identifier}/filings/{filing_id}',
                      json={},
                      headers=create_header(jwt, [STAFF_ROLE], identifier))
    assert rv.status_code == HTTPStatus.ACCEPTED
    assert not rv.json.get('errors')
    assert rv.json['filing']['header'].get('paymentToken', None) is None
    assert rv.json['filing']['header']['status'] == 'DRAFT'
Exemplo n.º 30
0
def test_update_ar_with_a_missing_business_id_fails(session, client, jwt):
    """Assert that updating to a non-existant business fails."""
    import copy
    identifier = 'CP7654321'
    business = factory_business(identifier,
                                founding_date=(datetime.utcnow() - datedelta.YEAR)
                                )
    factory_business_mailing_address(business)
    ar = copy.deepcopy(ANNUAL_REPORT)
    ar['filing']['annualReport']['annualReportDate'] = datetime.utcnow().date().isoformat()
    ar['filing']['annualReport']['annualGeneralMeetingDate'] = datetime.utcnow().date().isoformat()

    filings = factory_completed_filing(business, ar)
    identifier = 'CP0000001'

    rv = client.put(f'/api/v1/businesses/{identifier}/filings/{filings.id+1}',
                    json=ar,
                    headers=create_header(jwt, [STAFF_ROLE], identifier)
                    )

    assert rv.status_code == HTTPStatus.BAD_REQUEST
    assert rv.json['errors'][0] == {'error': 'A valid business and filing are required.'}