def test_get_user_authorizations_for_org(session, monkeypatch):  # pylint:disable=unused-argument
    """Assert that user authorizations for entity is working."""
    user = factory_user_model()
    org = factory_org_model()
    membership = factory_membership_model(user.id, org.id)

    patch_token_info({
        'sub': str(user.keycloak_guid),
        'realm_access': {
            'roles': ['basic']
        }}, monkeypatch)
    authorization = Authorization.get_account_authorizations_for_org(org.id, ProductCode.BUSINESS.value)
    assert authorization is not None
    assert authorization.get('orgMembership', None) == membership.membership_type_code
    assert authorization.get('roles') is not None

    patch_token_info({
        'sub': str(user.keycloak_guid),
        'realm_access': {
            'roles': ['basic']
        }}, monkeypatch)
    authorization = Authorization.get_account_authorizations_for_org(org.id, ProductCode.NAMES_REQUEST.value)
    assert authorization is not None
    assert authorization.get('orgMembership', None) == membership.membership_type_code
    assert authorization.get('roles') is not None

    patch_token_info({
        'sub': str(user.keycloak_guid),
        'realm_access': {
            'roles': ['basic']
        }}, monkeypatch)
    authorization = Authorization.get_account_authorizations_for_org(org.id, ProductCode.VS.value)
    assert authorization is not None
    assert authorization.get('orgMembership') is None
    assert len(authorization.get('roles')) == 0
Esempio n. 2
0
 def get(org_id):
     """Return authorization for the user for the passed business identifier."""
     expanded: bool = request.args.get('expanded', False)
     corp_type_code = request.headers.get('Product-Code', None)
     authorisations = AuthorizationService.get_account_authorizations_for_org(g.jwt_oidc_token_info, org_id,
                                                                              corp_type_code, expanded)
     return authorisations, http_status.HTTP_200_OK