Exemplo n.º 1
0
def factory_org_model(org_info: dict = TestOrgInfo.org1,
                      org_type_info: dict = TestOrgTypeInfo.test_type,
                      org_status_info: dict = TestOrgStatusInfo.test_status,
                      payment_type_info: dict = TestPaymentTypeInfo.test_type,
                      user_id=None):
    """Produce a templated org model."""
    org_type = OrgTypeModel.get_default_type()
    if org_type_info['code'] != TestOrgTypeInfo.implicit['code']:
        org_type = OrgTypeModel(code=org_type_info['code'], desc=org_type_info['desc'])
        org_type.save()

    org_status = OrgStatusModel(code=org_status_info['code'], desc=org_status_info['desc'])
    org_status.save()

    preferred_payment = PaymentTypeModel(code=payment_type_info['code'], desc=payment_type_info['desc'])
    preferred_payment.save()

    org = OrgModel(name=org_info['name'])
    org.org_type = org_type
    org.org_status = org_status
    org.preferred_payment = preferred_payment
    org.created_by_id = user_id
    org.save()

    return org
Exemplo n.º 2
0
def factory_membersip_model(session):
    """Produce a templated org model."""
    user = factory_user_model()
    org_type = OrgTypeModel(code='TEST', description='Test')
    session.add(org_type)
    session.commit()

    org_status = OrgStatusModel(code='TEST', description='Test')
    session.add(org_status)
    session.commit()

    preferred_payment = PaymentTypeModel(code='TEST', description='Test')
    session.add(preferred_payment)
    session.commit()
    org = OrgModel(name='Test Org')
    org.org_type = org_type
    org.org_status = OrgStatusModel.get_default_status()
    org.preferred_payment = preferred_payment
    org.save()

    membership = MembershipModel(org_id=org.id,
                                 user_id=user.id,
                                 membership_type_code=ADMIN,
                                 status=1)
    membership.save()
    return membership
Exemplo n.º 3
0
def factory_org_model(org_info: dict = TestOrgInfo.org1,
                      org_type_info: dict = None,
                      org_status_info: dict = None,
                      user_id=None,
                      bcol_info: dict = TestBCOLInfo.bcol1):
    """Produce a templated org model."""
    org_type = OrgTypeModel.get_default_type()
    if org_type_info and org_type_info['code'] != TestOrgTypeInfo.implicit[
            'code']:
        org_type = OrgTypeModel(code=org_type_info['code'],
                                description=org_type_info['desc'])
        org_type.save()

    if org_status_info is not None:
        org_status = OrgStatusModel(code=org_status_info['code'],
                                    description=org_status_info['desc'])
        org_status.save()
    else:
        org_status = OrgStatusModel.get_default_status()

    org = OrgModel(name=org_info['name'])
    org.org_type = org_type
    org.access_type = org_info.get('accessType', '')
    org.org_status = org_status
    org.created_by_id = user_id
    org.bcol_account_id = bcol_info.get('bcol_account_id', '')
    org.bcol_user_id = bcol_info.get('bcol_user_id', '')
    org.save()

    return org
Exemplo n.º 4
0
def factory_org_model(name):
    """Produce a templated org model."""
    org_type = OrgTypeModel(code='TEST', desc='Test')
    org_type.save()

    org_status = OrgStatusModel(code='TEST', desc='Test')
    org_status.save()

    preferred_payment = PaymentTypeModel(code='TEST', desc='Test')
    preferred_payment.save()

    org = OrgModel(name=name)
    org.org_type = org_type
    org.org_status = org_status
    org.preferred_payment = preferred_payment
    org.save()

    return org
Exemplo n.º 5
0
def factory_invitation_model(session, status, sent_date=datetime.now()):
    """Produce a templated invitation model."""
    user = User(username='******',
                roles='{edit, uma_authorization, staff}',
                keycloak_guid='1b20db59-19a0-4727-affe-c6f64309fd04')

    session.add(user)
    session.commit()

    org_type = OrgTypeModel(code='TEST', desc='Test')
    session.add(org_type)
    session.commit()

    org_status = OrgStatusModel(code='TEST', desc='Test')
    session.add(org_status)
    session.commit()

    preferred_payment = PaymentTypeModel(code='TEST', desc='Test')
    session.add(preferred_payment)
    session.commit()

    org = OrgModel()
    org.name = 'Test Org'
    org.org_type = org_type
    org.org_status = org_status
    org.preferred_payment = preferred_payment
    org.save()

    invitation = InvitationModel()
    invitation.recipient_email = '*****@*****.**'
    invitation.sender = user
    invitation.sent_date = sent_date
    invitation.invitation_status_code = status
    invitation.token = 'ABCD'

    invitation_membership = InvitationMembershipModel()
    invitation_membership.org_id = org.id
    invitation_membership.membership_type_code = 'USER'
    invitation.membership.append(invitation_membership)

    invitation.save()
    return invitation
Exemplo n.º 6
0
def factory_org_model(name, session):
    """Produce a templated org model."""
    org_type = OrgTypeModel(code='TEST', description='Test')
    session.add(org_type)
    session.commit()

    org_status = OrgStatusModel(code='TEST', description='Test')
    session.add(org_status)
    session.commit()

    preferred_payment = PaymentTypeModel(code='TEST', description='Test')
    session.add(preferred_payment)
    session.commit()
    org = OrgModel(name=name)
    org.org_type = org_type
    org.org_status = OrgStatusModel.get_default_status()
    org.preferred_payment = preferred_payment
    org.save()

    return org
Exemplo n.º 7
0
def test_create_from_dict(session):  # pylint:disable=unused-argument
    """Assert that an Entity can be created from schema."""
    user = User(username='******',
                roles='{edit, uma_authorization, staff}',
                keycloak_guid='1b20db59-19a0-4727-affe-c6f64309fd04')

    session.add(user)
    session.commit()

    org_type = OrgTypeModel(code='TEST', desc='Test')
    session.add(org_type)
    session.commit()

    org_status = OrgStatusModel(code='TEST', desc='Test')
    session.add(org_status)
    session.commit()

    preferred_payment = PaymentTypeModel(code='TEST', desc='Test')
    session.add(preferred_payment)
    session.commit()

    org = OrgModel()
    org.name = 'Test Org'
    org.org_type = org_type
    org.org_status = org_status
    org.preferred_payment = preferred_payment
    org.save()

    invitation_info = {
        'recipientEmail': '*****@*****.**',
        'membership': [{
            'membershipType': 'USER',
            'orgId': org.id
        }]
    }
    result_invitation = InvitationModel.create_from_dict(
        invitation_info, user.id, 'STANDARD')

    assert result_invitation.id is not None
Exemplo n.º 8
0
def factory_org_model(org_info: dict = TestOrgInfo.org1,
                      org_type_info: dict = TestOrgTypeInfo.test_type,
                      org_status_info: dict = TestOrgStatusInfo.test_status,
                      payment_type_info: dict = TestPaymentTypeInfo.test_type,
                      user_id=None,
                      bcol_info: dict = TestBCOLInfo.bcol1):
    """Produce a templated org model."""
    org_type = OrgTypeModel.get_default_type()
    if org_type_info['code'] != TestOrgTypeInfo.implicit['code']:
        org_type = OrgTypeModel(code=org_type_info['code'],
                                desc=org_type_info['desc'])
        org_type.save()

    if org_status_info:
        org_status = OrgStatusModel(code=org_status_info['code'],
                                    desc=org_status_info['desc'])
        org_status.save()
    else:
        org_status = OrgStatusModel.get_default_status()

    if payment_type_info:
        preferred_payment = PaymentTypeModel(code=payment_type_info['code'],
                                             desc=payment_type_info['desc'])
        preferred_payment.save()
    else:
        preferred_payment = PaymentTypeModel.get_default_payment_type()

    org = OrgModel(name=org_info['name'])
    org.org_type = org_type
    org.access_type = org_info.get('accessType', '')
    org.org_status = org_status
    org.created_by_id = user_id
    org.bcol_account_id = bcol_info.get('bcol_account_id', '')
    org.bcol_user_id = bcol_info.get('bcol_user_id', '')
    org.save()

    org.bcol_account_id = bcol_info['bcol_account_id']

    return org
Exemplo n.º 9
0
def factory_org_service(session, name):
    """Produce a templated org service."""
    org_type = OrgTypeModel(code='TEST', desc='Test')
    session.add(org_type)
    session.commit()

    org_status = OrgStatusModel(code='TEST', desc='Test')
    session.add(org_status)
    session.commit()

    preferred_payment = PaymentTypeModel(code='TEST', desc='Test')
    session.add(preferred_payment)
    session.commit()

    org_model = OrgModel(name=name)
    org_model.org_type = org_type
    org_model.org_status = org_status
    org_model.preferred_payment = preferred_payment
    org_model.save()

    org = OrgService(org_model)

    return org