def test_create_org_by_verified_bceid_user(session, keycloak_mock, monkeypatch): # pylint:disable=unused-argument """Assert that an Org can be created.""" # Steps # 1. Create a pending affidavit # 2. Create org # 3. Approve Org, which will mark the affidavit as approved # 4. Same user create new org, which should be ACTIVE. user = factory_user_model_with_contact(user_info=TestUserInfo.user_bceid_tester) token_info = TestJwtClaims.get_test_user(sub=user.keycloak_guid, source=LoginSource.BCEID.value) patch_token_info(token_info, 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 task_model = TaskModel.find_by_task_for_account(org_dict['id'], status=TaskStatus.OPEN.value) assert task_model.relationship_id == org_dict['id'] assert task_model.action == TaskAction.AFFIDAVIT_REVIEW.value task_info = { 'status': TaskStatus.OPEN.value, 'relationshipStatus': TaskRelationshipStatus.ACTIVE.value, } TaskService.update_task(TaskService(task_model), task_info) org_result: OrgModel = OrgModel.find_by_org_id(org_dict['id']) assert org_result.status_code == OrgStatus.ACTIVE.value
def test_approve_org(session, keycloak_mock, monkeypatch): # pylint:disable=unused-argument """Assert that an Affidavit can be approved.""" user = factory_user_model_with_contact( user_info=TestUserInfo.user_bceid_tester) token_info = TestJwtClaims.get_test_user(sub=user.keycloak_guid, source=LoginSource.BCEID.value) patch_token_info(token_info, 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 task_model = TaskModel.find_by_task_for_account( org_dict['id'], status=TaskStatus.OPEN.value) assert task_model.relationship_id == org_dict['id'] assert task_model.action == TaskAction.AFFIDAVIT_REVIEW.value task_info = { 'status': TaskStatus.OPEN.value, 'relationshipStatus': TaskRelationshipStatus.ACTIVE.value, 'remarks': ['Test Remark'] } task = TaskService.update_task(TaskService(task_model), task_info) task_dict = task.as_dict() affidavit = AffidavitService.find_affidavit_by_org_id( task_dict['relationship_id']) assert affidavit['status'] == AffidavitStatus.APPROVED.value
def _modify_task(user): """Clone on-hold task to a new active task; handle user-based and org-based tasks.""" # find users org. ideally only one org org_list = MembershipModel.find_orgs_for_user(user.identifier) org: OrgModel = next(iter(org_list or []), None) if org: # check if there is any holding tasks # Find if the corresponding task is NEW_ACCOUNT_STAFF_REVIEW / GOVN type, clone and close it task_model: TaskModel = TaskModel.find_by_task_for_account( org.id, TaskStatus.HOLD.value) if task_model is None: # Else, find if there are any associated task of BCEID_ADMIN type, clone and close it task_model: TaskModel = TaskModel.find_by_user_and_status( org.id, TaskStatus.HOLD.value) if task_model: task_info = { 'name': org.name, 'relationshipId': task_model.relationship_id, 'relatedTo': user.identifier, 'dateSubmitted': task_model.date_submitted, 'relationshipType': task_model.relationship_type, 'type': task_model.type, 'action': task_model.action, 'status': TaskStatus.OPEN.value, 'relationship_status': TaskRelationshipStatus.PENDING_STAFF_REVIEW.value, 'account_id': task_model.account_id } new_task = TaskService.create_task(task_info=task_info, do_commit=False) # Send notification mail to staff review task from auth_api.services import Org as OrgService # pylint:disable=cyclic-import, import-outside-toplevel if task_model.relationship_type == TaskRelationshipType.USER.value: OrgService.send_staff_review_account_reminder( relationship_id=user.identifier, task_relationship_type=TaskRelationshipType.USER.value) else: OrgService.send_staff_review_account_reminder( relationship_id=org.id) remarks = [ f'User Uploaded New affidavit .Created New task id: {new_task.identifier}' ] TaskService.close_task(task_model.id, remarks)
def test_task_creation(session, keycloak_mock, monkeypatch): # pylint:disable=unused-argument """Assert that affidavit reupload creates new task.""" user = factory_user_model_with_contact() token_info = TestJwtClaims.get_test_user(sub=user.keycloak_guid, source=LoginSource.BCEID.value) patch_token_info(token_info, 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_id = org.as_dict().get('id') task_model: TaskModel = TaskModel.find_by_task_for_account( org_id, TaskStatus.OPEN.value) assert task_model is not None, 'New Open should be generated' task_model.status = TaskStatus.HOLD.value # set current task to hold.Its a staff action new_affidavit_info = TestAffidavit.get_test_affidavit_with_contact() AffidavitService.create_affidavit(affidavit_info=new_affidavit_info) assert TaskModel.find_by_id( task_model.id).status == TaskStatus.CLOSED.value assert TaskModel.find_by_task_for_account( org_id, TaskStatus.OPEN.value) is not None
def _modify_task(user): # find users org. ideally only one org org_list = MembershipModel.find_orgs_for_user(user.identifier) org: OrgModel = next(iter(org_list or []), None) if org: # check if there is any holding tasks task_model: TaskModel = TaskModel.find_by_task_for_account( org.id, TaskStatus.HOLD.value) if task_model: task_type = TaskTypePrefix.NEW_ACCOUNT_STAFF_REVIEW.value task_info = { 'name': org.name, 'relationshipId': org.id, 'relatedTo': user.identifier, 'dateSubmitted': task_model.date_submitted, 'relationshipType': TaskRelationshipType.ORG.value, 'type': task_type, 'status': TaskStatus.OPEN.value, 'relationship_status': TaskRelationshipStatus.PENDING_STAFF_REVIEW.value } new_task = TaskService.create_task(task_info=task_info, do_commit=False) # Send notification mail to staff review task from auth_api.services import Org as OrgService # pylint:disable=cyclic-import, import-outside-toplevel OrgService.send_staff_review_account_reminder( relationship_id=org.id) remark = f'User Uploaded New affidavit .Created New task id: {new_task.identifier}' TaskService.close_task(task_model.id, remark)