|
23 | 23 | from http import HTTPStatus |
24 | 24 |
|
25 | 25 | import pytest |
| 26 | +from datedelta import datedelta |
26 | 27 | from unittest.mock import patch, PropertyMock |
27 | 28 | from flask import g, jsonify |
28 | 29 | from registry_schemas.example_data import ( |
|
50 | 51 | authorized, is_allowed, get_allowed, get_allowed_filings, get_allowable_actions |
51 | 52 | from legal_api.services.permissions import PermissionService |
52 | 53 | from legal_api.services.warnings.business.business_checks import WarningType |
| 54 | +from legal_api.utils.datetime import datetime |
53 | 55 | from tests import integration_authorization, not_github_ci |
54 | | -from tests.unit.models import factory_business, factory_filing, factory_incomplete_statuses, factory_completed_filing |
| 56 | +from tests.unit.models import factory_batch, factory_batch_processing, factory_business, factory_filing, factory_incomplete_statuses, factory_completed_filing |
55 | 57 | from tests.unit.services.utils import create_business, create_header, helper_create_jwt |
56 | 58 |
|
57 | 59 |
|
@@ -3306,15 +3308,24 @@ def mock_auth(one, two): # pylint: disable=unused-argument; mocks of library me |
3306 | 3308 | business = factory_business(identifier=identifier, |
3307 | 3309 | entity_type=legal_type, |
3308 | 3310 | state=state) |
3309 | | - for _ in range(num_dods): |
| 3311 | + for i in range(num_dods): |
3310 | 3312 | dod_filing_json = copy.deepcopy(FILING_TEMPLATE) |
3311 | 3313 | dod_filing_json["filing"]["header"]["name"] = "dissolution" |
3312 | 3314 | dod_filing_json["filing"]["dissolution"] = DELAY_DISSOLUTION |
3313 | | - factory_completed_filing(business, dod_filing_json) |
3314 | | - with patch.object(type(business), 'in_dissolution', new_callable=PropertyMock) as mock_in_dissolution: |
3315 | | - mock_in_dissolution.return_value = True |
3316 | | - filing_types = get_allowed_filings(business, state, legal_type, jwt) |
3317 | | - assert filing_types == expected |
| 3315 | + factory_completed_filing(business, dod_filing_json, datetime.utcnow() - datedelta(days=i)) |
| 3316 | + |
| 3317 | + batch = factory_batch() |
| 3318 | + batch_processing = factory_batch_processing( |
| 3319 | + batch_id=batch.id, |
| 3320 | + business_id=business.id, |
| 3321 | + identifier=identifier, |
| 3322 | + trigger_date=datetime.utcnow() + datedelta(days=10) |
| 3323 | + ) |
| 3324 | + batch_processing.created_date = datetime.utcnow() + datedelta(days=-10) |
| 3325 | + batch_processing.save() |
| 3326 | + |
| 3327 | + filing_types = get_allowed_filings(business, state, legal_type, jwt) |
| 3328 | + assert filing_types == expected |
3318 | 3329 |
|
3319 | 3330 |
|
3320 | 3331 | @pytest.mark.parametrize( |
@@ -3609,6 +3620,179 @@ def mock_auth(one, two): # pylint: disable=unused-argument; mocks of library me |
3609 | 3620 | assert allowed_filing_types == expected |
3610 | 3621 |
|
3611 | 3622 |
|
| 3623 | +@pytest.mark.parametrize( |
| 3624 | + 'test_name,username,roles,dods,expected', |
| 3625 | + [ |
| 3626 | + # active business - staff user |
| 3627 | + ('staff_allowed_no_dod_filings', 'staff', [STAFF_ROLE], [], |
| 3628 | + expected_lookup([FilingKey.ADMN_FRZE, |
| 3629 | + FilingKey.AR_CORPS, |
| 3630 | + FilingKey.COA_CORPS, |
| 3631 | + FilingKey.COD_CORPS, |
| 3632 | + FilingKey.CHANGE_OF_LIQUIDATORS_APPOINT, |
| 3633 | + FilingKey.CHANGE_OF_LIQUIDATORS_CEASE, |
| 3634 | + FilingKey.CHANGE_OF_LIQUIDATORS_ADDRESS, |
| 3635 | + FilingKey.CHANGE_OF_LIQUIDATORS_INTENT, |
| 3636 | + FilingKey.CHANGE_OF_LIQUIDATORS_REPORT, |
| 3637 | + FilingKey.COO_CORPS, |
| 3638 | + FilingKey.CHANGE_OF_RECEIVERS_AMEND, |
| 3639 | + FilingKey.CHANGE_OF_RECEIVERS_APPOINT, |
| 3640 | + FilingKey.CHANGE_OF_RECEIVERS_CEASE, |
| 3641 | + FilingKey.CHANGE_OF_RECEIVERS_ADDRESS, |
| 3642 | + FilingKey.CORRCTN, |
| 3643 | + FilingKey.COURT_ORDER, |
| 3644 | + FilingKey.ADM_DISS, |
| 3645 | + FilingKey.DELAY_DISS, |
| 3646 | + FilingKey.PUT_BACK_OFF, |
| 3647 | + FilingKey.REGISTRARS_NOTATION, |
| 3648 | + FilingKey.REGISTRARS_ORDER, |
| 3649 | + FilingKey.TRANSITION, |
| 3650 | + ])), |
| 3651 | + ('staff_allowed_public_user_dod_filings', |
| 3652 | + 'staff', |
| 3653 | + [STAFF_ROLE], |
| 3654 | + [{ 'date': datetime.utcnow() + datedelta(days=-3), 'user': 'public' }, { 'date': datetime.utcnow() + datedelta(days=-2), 'user': 'public' }], |
| 3655 | + expected_lookup([FilingKey.ADMN_FRZE, |
| 3656 | + FilingKey.AR_CORPS, |
| 3657 | + FilingKey.COA_CORPS, |
| 3658 | + FilingKey.COD_CORPS, |
| 3659 | + FilingKey.CHANGE_OF_LIQUIDATORS_APPOINT, |
| 3660 | + FilingKey.CHANGE_OF_LIQUIDATORS_CEASE, |
| 3661 | + FilingKey.CHANGE_OF_LIQUIDATORS_ADDRESS, |
| 3662 | + FilingKey.CHANGE_OF_LIQUIDATORS_INTENT, |
| 3663 | + FilingKey.CHANGE_OF_LIQUIDATORS_REPORT, |
| 3664 | + FilingKey.COO_CORPS, |
| 3665 | + FilingKey.CHANGE_OF_RECEIVERS_AMEND, |
| 3666 | + FilingKey.CHANGE_OF_RECEIVERS_APPOINT, |
| 3667 | + FilingKey.CHANGE_OF_RECEIVERS_CEASE, |
| 3668 | + FilingKey.CHANGE_OF_RECEIVERS_ADDRESS, |
| 3669 | + FilingKey.CORRCTN, |
| 3670 | + FilingKey.COURT_ORDER, |
| 3671 | + FilingKey.ADM_DISS, |
| 3672 | + FilingKey.DELAY_DISS, |
| 3673 | + FilingKey.PUT_BACK_OFF, |
| 3674 | + FilingKey.REGISTRARS_NOTATION, |
| 3675 | + FilingKey.REGISTRARS_ORDER, |
| 3676 | + FilingKey.TRANSITION, |
| 3677 | + ])), |
| 3678 | + ('basic_user_allowed_no_dod_filings', |
| 3679 | + 'basic_user', |
| 3680 | + [BASIC_USER], |
| 3681 | + [], |
| 3682 | + expected_lookup([FilingKey.AR_CORPS, |
| 3683 | + FilingKey.COA_CORPS, |
| 3684 | + FilingKey.COD_CORPS, |
| 3685 | + FilingKey.COO_CORPS, |
| 3686 | + FilingKey.DELAY_DISS, |
| 3687 | + FilingKey.TRANSITION, |
| 3688 | + FilingKey.TRANSPARENCY_REGISTER_ANNUAL, |
| 3689 | + FilingKey.TRANSPARENCY_REGISTER_CHANGE, |
| 3690 | + FilingKey.TRANSPARENCY_REGISTER_INITIAL])), |
| 3691 | + ('basic_user_allowed_staff_dod_filings', |
| 3692 | + 'basic_user', |
| 3693 | + [BASIC_USER], |
| 3694 | + [{ 'date': datetime.utcnow() + datedelta(days=-3), 'user': 'staff' }, { 'date': datetime.utcnow() + datedelta(days=-2), 'user': 'staff' }], |
| 3695 | + expected_lookup([FilingKey.AR_CORPS, |
| 3696 | + FilingKey.COA_CORPS, |
| 3697 | + FilingKey.COD_CORPS, |
| 3698 | + FilingKey.COO_CORPS, |
| 3699 | + FilingKey.DELAY_DISS, |
| 3700 | + FilingKey.TRANSITION, |
| 3701 | + FilingKey.TRANSPARENCY_REGISTER_ANNUAL, |
| 3702 | + FilingKey.TRANSPARENCY_REGISTER_CHANGE, |
| 3703 | + FilingKey.TRANSPARENCY_REGISTER_INITIAL])), |
| 3704 | + ('basic_user_allowed_1_public_user_dod_filings', |
| 3705 | + 'basic_user', |
| 3706 | + [BASIC_USER], |
| 3707 | + [{ 'date': datetime.utcnow() + datedelta(days=-3), 'user': 'public' }, { 'date': datetime.utcnow() + datedelta(days=-2), 'user': 'staff' }], |
| 3708 | + expected_lookup([FilingKey.AR_CORPS, |
| 3709 | + FilingKey.COA_CORPS, |
| 3710 | + FilingKey.COD_CORPS, |
| 3711 | + FilingKey.COO_CORPS, |
| 3712 | + FilingKey.DELAY_DISS, |
| 3713 | + FilingKey.TRANSITION, |
| 3714 | + FilingKey.TRANSPARENCY_REGISTER_ANNUAL, |
| 3715 | + FilingKey.TRANSPARENCY_REGISTER_CHANGE, |
| 3716 | + FilingKey.TRANSPARENCY_REGISTER_INITIAL])), |
| 3717 | + ('basic_user_not_allowed_2_public_user_dod_filings', |
| 3718 | + 'basic_user', |
| 3719 | + [BASIC_USER], |
| 3720 | + [{ 'date': datetime.utcnow() + datedelta(days=-3), 'user': 'public' }, { 'date': datetime.utcnow() + datedelta(days=-2), 'user': 'public' }], |
| 3721 | + expected_lookup([FilingKey.AR_CORPS, |
| 3722 | + FilingKey.COA_CORPS, |
| 3723 | + FilingKey.COD_CORPS, |
| 3724 | + FilingKey.COO_CORPS, |
| 3725 | + FilingKey.TRANSITION, |
| 3726 | + FilingKey.TRANSPARENCY_REGISTER_ANNUAL, |
| 3727 | + FilingKey.TRANSPARENCY_REGISTER_CHANGE, |
| 3728 | + FilingKey.TRANSPARENCY_REGISTER_INITIAL])), |
| 3729 | + ('basic_user_allowed_1_current_1_prev', |
| 3730 | + 'basic_user', |
| 3731 | + [BASIC_USER], |
| 3732 | + [{ 'date': datetime.utcnow() + datedelta(days=-3), 'user': 'public' }, { 'date': datetime.utcnow() + datedelta(days=-40), 'user': 'public' }], |
| 3733 | + expected_lookup([FilingKey.AR_CORPS, |
| 3734 | + FilingKey.COA_CORPS, |
| 3735 | + FilingKey.COD_CORPS, |
| 3736 | + FilingKey.COO_CORPS, |
| 3737 | + FilingKey.DELAY_DISS, |
| 3738 | + FilingKey.TRANSITION, |
| 3739 | + FilingKey.TRANSPARENCY_REGISTER_ANNUAL, |
| 3740 | + FilingKey.TRANSPARENCY_REGISTER_CHANGE, |
| 3741 | + FilingKey.TRANSPARENCY_REGISTER_INITIAL])), |
| 3742 | + ] |
| 3743 | +) |
| 3744 | +def test_get_allowed_filings_blocker_max_delays(monkeypatch, app, session, jwt, test_name, username, roles, dods, expected): |
| 3745 | + """Assert that get allowed returns valid filings when business is in dissolution.""" |
| 3746 | + token = helper_create_jwt(jwt, roles=roles, username=username) |
| 3747 | + headers = {'Authorization': 'Bearer ' + token, 'Account-Id': 1} |
| 3748 | + |
| 3749 | + def mock_auth(one, two): # pylint: disable=unused-argument; mocks of library methods |
| 3750 | + return headers[one] |
| 3751 | + |
| 3752 | + with app.test_request_context(): |
| 3753 | + monkeypatch.setattr('flask.request.headers.get', mock_auth) |
| 3754 | + monkeypatch.setattr( |
| 3755 | + 'legal_api.services.flags.value', |
| 3756 | + lambda flag, _user, _account_id: "changeOfLiquidators.appointLiquidator,changeOfLiquidators.ceaseLiquidator,changeOfLiquidators.changeAddressLiquidator,changeOfLiquidators.intentToLiquidate,changeOfLiquidators.liquidationReport,changeOfReceivers.amendReceiver,changeOfReceivers.appointReceiver,changeOfReceivers.ceaseReceiver,changeOfReceivers.changeAddressReceiver,dissolution.delay,transition" |
| 3757 | + if flag == 'enabled-specific-filings' else {} |
| 3758 | + ) |
| 3759 | + monkeypatch.setattr( |
| 3760 | + 'legal_api.models.User.get_or_create_user_by_jwt', |
| 3761 | + lambda _: None |
| 3762 | + ) |
| 3763 | + |
| 3764 | + identifier = 'BC7654321' |
| 3765 | + business = factory_business(identifier=identifier, entity_type=Business.LegalTypes.COMP) |
| 3766 | + delay_filing_json = { |
| 3767 | + 'filing': { |
| 3768 | + 'header': { |
| 3769 | + 'name': 'dissolution' |
| 3770 | + }, |
| 3771 | + 'dissolution': { |
| 3772 | + 'dissolutionType': 'delay', |
| 3773 | + 'delayType': 'custom' |
| 3774 | + } |
| 3775 | + } |
| 3776 | + } |
| 3777 | + for delay in dods: |
| 3778 | + filing = factory_completed_filing(business, delay_filing_json, delay['date'], None, None, 'dissolution', 'delay') |
| 3779 | + if delay['user'] == 'staff': |
| 3780 | + filing.submitter_roles = 'staff' |
| 3781 | + filing.save() |
| 3782 | + batch = factory_batch() |
| 3783 | + batch_processing = factory_batch_processing( |
| 3784 | + batch_id=batch.id, |
| 3785 | + business_id=business.id, |
| 3786 | + identifier=identifier, |
| 3787 | + trigger_date=datetime.utcnow() + datedelta(days=10) |
| 3788 | + ) |
| 3789 | + batch_processing.created_date = datetime.utcnow() + datedelta(days=-10) |
| 3790 | + batch_processing.save() |
| 3791 | + |
| 3792 | + filing_types = get_allowed_filings(business, Business.State.ACTIVE, Business.LegalTypes.COMP, jwt) |
| 3793 | + assert filing_types == expected |
| 3794 | + |
| 3795 | + |
3612 | 3796 | def create_incomplete_filing(business, |
3613 | 3797 | filing_name, |
3614 | 3798 | filing_status, |
|
0 commit comments