Exemple #1
0
def test_delete_org_with_affiliation(session, auth_mock, keycloak_mock,
                                     monkeypatch):  # pylint:disable=unused-argument
    """Assert that an org cannot be deleted."""
    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)
    org = OrgService.create_org(TestOrgInfo.org1, user.id)
    org_id = org.as_dict()['id']

    entity_service = factory_entity_service(
        entity_info=TestEntityInfo.entity_lear_mock)
    entity_dictionary = entity_service.as_dict()
    business_identifier = entity_dictionary['business_identifier']
    AffiliationService.create_affiliation(
        org_id, business_identifier,
        TestEntityInfo.entity_lear_mock['passCode'])

    patch_token_info(TestJwtClaims.public_user_role, monkeypatch)
    patch_pay_account_delete(monkeypatch)
    OrgService.delete_org(org_id)

    assert len(
        AffiliationService.find_visible_affiliations_by_org_id(org_id)) == 0
Exemple #2
0
def test_delete_org_with_members_success(session, auth_mock, keycloak_mock,
                                         monkeypatch):  # pylint:disable=unused-argument
    """Assert that an org can be deleted."""
    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(TestJwtClaims.public_user_role, monkeypatch)
    org = OrgService.create_org(TestOrgInfo.org1, user.id)

    patch_pay_account_delete(monkeypatch)
    OrgService.delete_org(org.as_dict()['id'])
    org_inactive = OrgService.find_by_org_id(org.as_dict()['id'])
    assert org_inactive.as_dict()['org_status'] == 'INACTIVE'
Exemple #3
0
def test_delete_org_with_members(session, auth_mock, keycloak_mock, monkeypatch):  # pylint:disable=unused-argument
    """Assert that an org can be deleted."""
    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)
    org = OrgService.create_org(TestOrgInfo.org1, user.id)
    user2 = factory_user_model(user_info=TestUserInfo.user2)
    factory_membership_model(user2.id, org._model.id, member_type='COORDINATOR')
    user3 = factory_user_model(user_info=TestUserInfo.user3)
    factory_membership_model(user3.id, org._model.id, member_type='ADMIN')

    patch_token_info(TestJwtClaims.public_user_role, monkeypatch)
    patch_pay_account_delete(monkeypatch)
    org_id = org.as_dict()['id']

    OrgService.delete_org(org_id)
    assert len(MembershipService.get_members_for_org(org_id)) == 0
Exemple #4
0
def test_delete_org_removes_user_from_account_holders_group(session, auth_mock,
                                                            monkeypatch):  # pylint:disable=unused-argument
    """Assert that an Org deletion removes the user from account holders group."""
    # Create a user in keycloak
    keycloak_service = KeycloakService()
    request = KeycloakScenario.create_user_request()
    keycloak_service.add_user(request, return_if_exists=True)
    kc_user = keycloak_service.get_user_by_username(request.user_name)
    user = factory_user_model(TestUserInfo.get_user_with_kc_guid(kc_guid=kc_user.id))

    patch_token_info({'sub': user.keycloak_guid}, monkeypatch)
    patch_pay_account_delete(monkeypatch)
    org = OrgService.create_org(TestOrgInfo.org1, user_id=user.id)
    OrgService.delete_org(org.as_dict().get('id'))

    user_groups = keycloak_service.get_user_groups(user_id=kc_user.id)
    groups = []
    for group in user_groups:
        groups.append(group.get('name'))
    assert GROUP_ACCOUNT_HOLDERS not in groups