Beispiel #1
0
def test_put_task_org_on_hold(client, jwt, session, keycloak_mock,
                              monkeypatch):  # pylint:disable=unused-argument
    """Assert that the task can be updated."""
    # 1. Create User
    # 2. Get document signed link
    # 3. Create affidavit
    # 4. Create Org
    # 5. Update the created task and the relationship
    monkeypatch.setattr('auth_api.utils.user_context._get_token_info',
                        lambda: TestJwtClaims.public_bceid_user)
    user_with_token = TestUserInfo.user_staff_admin
    user_with_token['keycloak_guid'] = TestJwtClaims.public_user_role['sub']
    user = factory_user_model_with_contact(user_with_token)

    affidavit_info = TestAffidavit.get_test_affidavit_with_contact()
    AffidavitService.create_affidavit(affidavit_info=affidavit_info)

    org = OrgService.create_org(TestOrgInfo.org_with_mailing_address(),
                                user_id=user.id)
    org_dict = org.as_dict()
    assert org_dict['org_status'] == OrgStatus.PENDING_STAFF_REVIEW.value
    org_id = org_dict['id']

    tasks = TaskService.fetch_tasks(task_status=[TaskStatus.OPEN.value],
                                    page=1,
                                    limit=10)
    fetched_tasks = tasks['tasks']
    fetched_task = fetched_tasks[0]

    task_type_new_account = TaskTypePrefix.NEW_ACCOUNT_STAFF_REVIEW.value
    assert fetched_task['type'] == task_type_new_account

    update_task_payload = {
        'status': TaskStatus.HOLD.value,
        'relationshipStatus':
        TaskRelationshipStatus.PENDING_STAFF_REVIEW.value,
        'remark': 'AFFIDAVIT SEAL MISSING'
    }

    headers = factory_auth_header(jwt=jwt, claims=TestJwtClaims.staff_role)
    rv = client.put('/api/v1/tasks/{}'.format(fetched_task['id']),
                    data=json.dumps(update_task_payload),
                    headers=headers,
                    content_type='application/json')

    dictionary = json.loads(rv.data)
    assert rv.status_code == http_status.HTTP_200_OK
    assert dictionary['status'] == TaskStatus.HOLD.value
    assert dictionary[
        'relationshipStatus'] == TaskRelationshipStatus.PENDING_STAFF_REVIEW.value

    headers = factory_auth_header(jwt=jwt,
                                  claims=TestJwtClaims.public_user_role)
    rv = client.get('/api/v1/orgs/{}'.format(org_id),
                    headers=headers,
                    content_type='application/json')
    assert rv.status_code == http_status.HTTP_200_OK
    dictionary = json.loads(rv.data)
    assert dictionary['id'] == org_id
    assert rv.json.get('orgStatus') == OrgStatus.PENDING_STAFF_REVIEW.value
Beispiel #2
0
def test_update_task(session, keycloak_mock, monkeypatch):  # pylint:disable=unused-argument
    """Assert that a task can be updated."""
    user_with_token = TestUserInfo.user_bceid_tester
    user_with_token['keycloak_guid'] = TestJwtClaims.public_bceid_user['sub']
    user = factory_user_model_with_contact(user_with_token)

    patch_token_info(TestJwtClaims.public_bceid_user, monkeypatch)
    affidavit_info = TestAffidavit.get_test_affidavit_with_contact()
    AffidavitService.create_affidavit(affidavit_info=affidavit_info)
    org = OrgService.create_org(TestOrgInfo.org_with_mailing_address(),
                                user_id=user.id)
    org_dict = org.as_dict()
    assert org_dict['org_status'] == OrgStatus.PENDING_STAFF_REVIEW.value

    token_info = TestJwtClaims.get_test_user(sub=user.keycloak_guid,
                                             source=LoginSource.STAFF.value)
    patch_token_info(token_info, monkeypatch)

    tasks = TaskService.fetch_tasks(task_status=[TaskStatus.OPEN.value],
                                    page=1,
                                    limit=10)
    fetched_tasks = tasks['tasks']
    fetched_task = fetched_tasks[0]

    task_info = {'relationshipStatus': TaskRelationshipStatus.ACTIVE.value}
    task: TaskModel = TaskModel.find_by_task_id(fetched_task['id'])

    task = TaskService.update_task(TaskService(task), task_info=task_info)
    dictionary = task.as_dict()
    user = UserModel.find_by_id(user.id)
    assert dictionary['status'] == TaskStatus.COMPLETED.value
    assert dictionary[
        'relationship_status'] == TaskRelationshipStatus.ACTIVE.value
    assert user.verified
Beispiel #3
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']
Beispiel #4
0
def test_fetch_tasks(session, auth_mock):  # pylint:disable=unused-argument
    """Assert that tasks can be fetched."""
    user = factory_user_model()
    task = factory_task_service(user.id)
    dictionary = task.as_dict()
    name = dictionary['name']

    fetched_task = TaskService.fetch_tasks(task_status=[TaskStatus.OPEN.value],
                                           page=1,
                                           limit=10)

    assert fetched_task['tasks']
    for item in fetched_task['tasks']:
        assert item['name'] == name
Beispiel #5
0
    def get():
        """Fetch tasks."""
        try:
            # Search based on request arguments
            task_type = request.args.get('type', None)
            task_relationship_status = request.args.get('relationshipStatus', None)
            task_status = request.args.get('status', TaskStatus.OPEN.value)
            page = request.args.get('page', 1)
            limit = request.args.get('limit', 10)

            response, status = TaskService.fetch_tasks(task_relationship_status=task_relationship_status,
                                                       task_type=task_type, task_status=task_status,
                                                       page=page, limit=limit), http_status.HTTP_200_OK
        except BusinessException as exception:
            response, status = {'code': exception.code, 'message': exception.message}, exception.status_code

        return response, status
Beispiel #6
0
def test_put_task_product(client, jwt, session, keycloak_mock, monkeypatch):  # pylint:disable=unused-argument
    """Assert that the task can be updated."""
    # 1. Create User
    # 4. Create Product subscription
    # 5. Update the created task and the relationship

    # Post user, org and product subscription
    headers = factory_auth_header(jwt=jwt,
                                  claims=TestJwtClaims.staff_admin_role)
    user_with_token = TestUserInfo.user_staff_admin
    user_with_token['keycloak_guid'] = TestJwtClaims.public_user_role['sub']
    user = factory_user_model_with_contact(user_with_token)

    patch_token_info(
        {
            'sub': str(user_with_token['keycloak_guid']),
            'username': '******',
            'realm_access': {
                'roles': ['edit']
            }
        }, monkeypatch)

    affidavit_info = TestAffidavit.get_test_affidavit_with_contact()
    AffidavitService.create_affidavit(affidavit_info=affidavit_info)

    patch_token_info(TestJwtClaims.public_bceid_user, monkeypatch)
    org = OrgService.create_org(TestOrgInfo.org_with_mailing_address(),
                                user_id=user.id)
    org_dict = org.as_dict()

    product_which_doesnt_need_approval = TestOrgProductsInfo.org_products1
    rv_products = client.post(
        f"/api/v1/orgs/{org_dict.get('id')}/products",
        data=json.dumps(product_which_doesnt_need_approval),
        headers=headers,
        content_type='application/json')
    assert rv_products.status_code == http_status.HTTP_201_CREATED
    assert schema_utils.validate(rv_products.json,
                                 'org_product_subscriptions_response')[0]

    tasks = TaskService.fetch_tasks(task_status=[TaskStatus.OPEN.value],
                                    page=1,
                                    limit=10)
    assert len(tasks['tasks']) == 1

    product_which_needs_approval = TestOrgProductsInfo.org_products_vs
    rv_products = client.post(f"/api/v1/orgs/{org_dict.get('id')}/products",
                              data=json.dumps(product_which_needs_approval),
                              headers=headers,
                              content_type='application/json')
    assert rv_products.status_code == http_status.HTTP_201_CREATED
    assert schema_utils.validate(rv_products.json,
                                 'org_product_subscriptions_response')[0]

    tasks = TaskService.fetch_tasks(task_status=[TaskStatus.OPEN.value],
                                    page=1,
                                    limit=10)
    fetched_tasks = tasks['tasks']
    fetched_task = fetched_tasks[1]
    assert fetched_task[
        'relationship_type'] == TaskRelationshipType.PRODUCT.value

    # Assert task name
    product: ProductCodeModel = ProductCodeModel.find_by_code(
        product_which_needs_approval['subscriptions'][0].get('productCode'))
    org_name = org_dict['name']
    assert fetched_task['name'] == org_name
    assert fetched_task['type'] == product.description

    # Assert the task can be updated and the product status is changed to active
    update_task_payload = {
        'relationshipStatus': ProductSubscriptionStatus.ACTIVE.value
    }

    headers = factory_auth_header(jwt=jwt, claims=TestJwtClaims.staff_role)
    rv = client.put('/api/v1/tasks/{}'.format(fetched_task['id']),
                    data=json.dumps(update_task_payload),
                    headers=headers,
                    content_type='application/json')

    dictionary = json.loads(rv.data)
    assert rv.status_code == http_status.HTTP_200_OK
    assert dictionary['status'] == TaskStatus.COMPLETED.value
    assert dictionary[
        'relationshipStatus'] == TaskRelationshipStatus.ACTIVE.value