Exemple #1
0
def test_create_task_govm(session, keycloak_mock):  # pylint:disable=unused-argument
    """Assert that a task can be created when updating a GOVM account."""
    user = factory_user_model()
    token_info = TestJwtClaims.get_test_user(sub=user.keycloak_guid,
                                             source=LoginSource.STAFF.value,
                                             roles=['create_accounts'])
    user2 = factory_user_model(TestUserInfo.user2)
    public_token_info = TestJwtClaims.get_test_user(
        sub=user2.keycloak_guid,
        source=LoginSource.STAFF.value,
        roles=['gov_account_user'])

    org: OrgService = OrgService.create_org(TestOrgInfo.org_govm,
                                            user_id=user.id,
                                            token_info=token_info)
    assert org
    with patch.object(RestService, 'put') as mock_post:
        payment_details = TestPaymentMethodInfo.get_payment_method_input_with_revenue(
        )
        org_body = {
            'mailingAddress': TestOrgInfo.get_mailing_address(),
            **payment_details
        }
        org = OrgService.update_org(org,
                                    org_body,
                                    token_info=public_token_info)
        assert org
        dictionary = org.as_dict()
        assert dictionary['name'] == TestOrgInfo.org_govm['name']
        mock_post.assert_called()
        actual_data = mock_post.call_args.kwargs.get('data')
        expected_data = {
            'accountId':
            dictionary.get('id'),
            'accountName':
            dictionary.get('name') + '-' + dictionary.get('branch_name'),
            'paymentInfo': {
                'methodOfPayment':
                'EJV',
                'billable':
                False,
                'revenueAccount':
                payment_details.get('paymentInfo').get('revenueAccount')
            },
            'contactInfo':
            TestOrgInfo.get_mailing_address()
        }
        assert expected_data == actual_data

        # Assert the task that is created
        fetched_task = TaskService.fetch_tasks(
            task_status=TaskStatus.OPEN.value, page=1, limit=10)

        for item in fetched_task['tasks']:
            assert item['name'] == dictionary['name']
            assert item['type'] == TaskTypePrefix.GOVM_REVIEW.value
            assert item['status'] == TaskStatus.OPEN.value
            assert item['relationship_id'] == dictionary['id']
Exemple #2
0
def test_update_basic_org_assert_pay_request_is_correct(
        session, keycloak_mock):  # pylint:disable=unused-argument
    """Assert that while org updation , pay-api gets called with proper data for basic accounts."""
    user_with_token = TestUserInfo.user_test
    user_with_token['keycloak_guid'] = TestJwtClaims.public_user_role['sub']
    user = factory_user_model(user_info=user_with_token)
    org = OrgService.create_org(TestOrgInfo.org1, user_id=user.id)
    with patch.object(RestService, 'put') as mock_put:
        new_payment_method = TestPaymentMethodInfo.get_payment_method_input(
            PaymentMethod.ONLINE_BANKING)
        org = OrgService.update_org(org,
                                    new_payment_method,
                                    token_info=TestJwtClaims.public_user_role)
        assert org
        dictionary = org.as_dict()
        mock_put.assert_called()
        actual_data = mock_put.call_args.kwargs.get('data')
        expected_data = {
            'accountId': dictionary.get('id'),
            'accountName': dictionary.get('name'),
            'paymentInfo': {
                'methodOfPayment': PaymentMethod.ONLINE_BANKING.value,
                'billable': True
            }
        }
        assert expected_data == actual_data, 'updating to Online Banking works.'

        new_payment_method = TestPaymentMethodInfo.get_payment_method_input(
            PaymentMethod.DIRECT_PAY)
        org = OrgService.update_org(org,
                                    new_payment_method,
                                    token_info=TestJwtClaims.public_user_role)
        assert org
        dictionary = org.as_dict()
        mock_put.assert_called()
        actual_data = mock_put.call_args.kwargs.get('data')
        expected_data = {
            'accountId': dictionary.get('id'),
            'accountName': dictionary.get('name'),
            'paymentInfo': {
                'methodOfPayment': PaymentMethod.DIRECT_PAY.value,
                'billable': True
            }
        }
        assert expected_data == actual_data, 'updating bank  to Credit Card works.'
Exemple #3
0
def test_put_basic_org_assert_pay_request_is_govm(session, keycloak_mock,
                                                  staff_user_mock,
                                                  monkeypatch):  # pylint:disable=unused-argument
    """Assert that while org creation , pay-api gets called with proper data for basic accounts."""
    user = factory_user_model()
    staff_token_info = TestJwtClaims.get_test_user(
        sub=user.keycloak_guid,
        source=LoginSource.STAFF.value,
        roles=['create_accounts'])
    user2 = factory_user_model(TestUserInfo.user2)
    public_token_info = TestJwtClaims.get_test_user(
        sub=user2.keycloak_guid,
        source=LoginSource.STAFF.value,
        roles=['gov_account_user'])
    patch_token_info(staff_token_info, monkeypatch)
    org: OrgService = OrgService.create_org(TestOrgInfo.org_govm,
                                            user_id=user.id)
    assert org
    with patch.object(RestService, 'put') as mock_post:
        payment_details = TestPaymentMethodInfo.get_payment_method_input_with_revenue(
        )
        org_body = {
            'mailingAddress': TestOrgInfo.get_mailing_address(),
            **payment_details
        }
        patch_token_info(public_token_info, monkeypatch)
        org = OrgService.update_org(org, org_body)
        assert org
        dictionary = org.as_dict()
        assert dictionary['name'] == TestOrgInfo.org_govm['name']
        mock_post.assert_called()
        actual_data = mock_post.call_args.kwargs.get('data')
        expected_data = {
            'accountId':
            dictionary.get('id'),
            'accountName':
            dictionary.get('name') + '-' + dictionary.get('branch_name'),
            'paymentInfo': {
                'methodOfPayment':
                'EJV',
                'billable':
                False,
                'revenueAccount':
                payment_details.get('paymentInfo').get('revenueAccount')
            },
            'contactInfo':
            TestOrgInfo.get_mailing_address()
        }
        assert expected_data == actual_data
Exemple #4
0
def test_update_basic_org_assert_pay_request_activity(session, keycloak_mock, monkeypatch):
    """Assert that while org payment update touches activity log."""
    user_with_token = TestUserInfo.user_test
    user_with_token['keycloak_guid'] = TestJwtClaims.public_user_role['sub']
    user = factory_user_model(user_info=user_with_token)
    patch_token_info({'sub': user.keycloak_guid}, monkeypatch)
    # Have to patch this because the pay spec is wrong and returns 201, not 202 or 200.
    patch_pay_account_post(monkeypatch)
    org = OrgService.create_org(TestOrgInfo.org1, user_id=user.id)
    new_payment_method = TestPaymentMethodInfo.get_payment_method_input(PaymentMethod.ONLINE_BANKING)

    patch_token_info(TestJwtClaims.public_user_role, monkeypatch)

    # Have to patch this because the pay spec is wrong and returns 201, not 202 or 200.
    patch_pay_account_put(monkeypatch)
    with patch.object(ActivityLogPublisher, 'publish_activity', return_value=None) as mock_alp:
        org = OrgService.update_org(org, new_payment_method)
        mock_alp.assert_called_with(Activity(action=ActivityAction.PAYMENT_INFO_CHANGE.value,
                                             org_id=ANY, name=ANY, id=ANY,
                                             value=PaymentMethod.ONLINE_BANKING.value))