Beispiel #1
0
def create_service(
        user=None,
        service_name="Sample service",
        service_id=None,
        restricted=False,
        service_permissions=[EMAIL_TYPE, SMS_TYPE],
        research_mode=False,
        active=True,
        email_from=None,
        prefix_sms=True,
        message_limit=1000,
        organisation_type='central'
):
    service = Service(
        name=service_name,
        message_limit=message_limit,
        restricted=restricted,
        email_from=email_from if email_from else service_name.lower().replace(' ', '.'),
        created_by=user or create_user(email='{}@digital.cabinet-office.gov.uk'.format(uuid.uuid4())),
        prefix_sms=prefix_sms,
        organisation_type=organisation_type
    )

    dao_create_service(service, service.created_by, service_id, service_permissions=service_permissions)

    service.active = active
    service.research_mode = research_mode

    return service
Beispiel #2
0
def create_service_model(user=None,
                         service_name="Test service",
                         restricted=False,
                         count_as_live=True,
                         research_mode=False,
                         active=True,
                         email_from=None,
                         prefix_sms=True,
                         message_limit=1000,
                         organisation_type='other',
                         go_live_user=None,
                         go_live_at=None,
                         crown=True,
                         organisation=None,
                         smtp_user=None):
    service = Service(
        name=service_name,
        message_limit=message_limit,
        restricted=restricted,
        email_from=email_from if email_from else service_name.lower().replace(
            ' ', '.'),
        created_by=user if user else create_user_model(),
        prefix_sms=prefix_sms,
        organisation_type=organisation_type,
        go_live_user=go_live_user,
        go_live_at=go_live_at,
        crown=crown,
        smtp_user=smtp_user,
        organisation=organisation if organisation else Organisation(
            id=uuid.uuid4(), name='sample organization'))
    service.active = active
    service.research_mode = research_mode
    service.count_as_live = count_as_live

    return service
def setup_service(db_session,
                  service_name="Sample service",
                  user=None,
                  restricted=False,
                  limit=1000,
                  email_from=None,
                  permissions=None,
                  research_mode=None):
    if user is None:
        user = create_user()
    if email_from is None:
        email_from = service_name.lower().replace(' ', '.')

    data = {
        'name': service_name,
        'message_limit': limit,
        'restricted': restricted,
        'email_from': email_from,
        'created_by': user,
        'crown': True
    }
    service = Service.query.filter_by(name=service_name).first()
    if not service:
        service = Service(**data)
        dao_create_service(service, user, service_permissions=permissions)

        if research_mode:
            service.research_mode = research_mode

    else:
        if user not in service.users:
            dao_add_user_to_service(service, user)

    return service
Beispiel #4
0
def create_service(
        user=None,
        service_name="Sample service",
        service_id=None,
        restricted=False,
        count_as_live=True,
        service_permissions=None,
        research_mode=False,
        active=True,
        email_from=None,
        prefix_sms=True,
        message_limit=1000,
        organisation_type='central',
        check_if_service_exists=False,
        go_live_user=None,
        go_live_at=None,
        crown=True,
        organisation=None,
        purchase_order_number=None,
        billing_contact_names=None,
        billing_contact_email_addresses=None,
        billing_reference=None,
):
    if check_if_service_exists:
        service = Service.query.filter_by(name=service_name).first()
    if (not check_if_service_exists) or (check_if_service_exists and not service):
        service = Service(
            name=service_name,
            message_limit=message_limit,
            restricted=restricted,
            email_from=email_from if email_from else service_name.lower().replace(' ', '.'),
            created_by=user if user else create_user(email='{}@digital.cabinet-office.gov.uk'.format(uuid.uuid4())),
            prefix_sms=prefix_sms,
            organisation_type=organisation_type,
            organisation=organisation,
            go_live_user=go_live_user,
            go_live_at=go_live_at,
            crown=crown,
            purchase_order_number=purchase_order_number,
            billing_contact_names=billing_contact_names,
            billing_contact_email_addresses=billing_contact_email_addresses,
            billing_reference=billing_reference,
        )
        dao_create_service(
            service,
            service.created_by,
            service_id,
            service_permissions=service_permissions,
        )

        service.active = active
        service.research_mode = research_mode
        service.count_as_live = count_as_live
    else:
        if user and user not in service.users:
            dao_add_user_to_service(service, user)

    return service
Beispiel #5
0
def create_service(
    user=None,
    service_name="Sample service",
    service_id=None,
    restricted=False,
    count_as_live=True,
    service_permissions=[EMAIL_TYPE, SMS_TYPE],
    research_mode=False,
    active=True,
    email_from=None,
    prefix_sms=True,
    message_limit=1000,
    organisation_type="central",
    check_if_service_exists=False,
    go_live_user=None,
    go_live_at=None,
    crown=True,
    organisation=None,
):
    if check_if_service_exists:
        service = Service.query.filter_by(name=service_name).first()
    if (not check_if_service_exists) or (check_if_service_exists
                                         and not service):
        service = Service(
            name=service_name,
            message_limit=message_limit,
            restricted=restricted,
            email_from=email_from
            if email_from else service_name.lower().replace(" ", "."),
            created_by=user if user else create_user(
                email="{}@digital.cabinet-office.gov.uk".format(uuid.uuid4())),
            prefix_sms=prefix_sms,
            organisation_type=organisation_type,
            go_live_user=go_live_user,
            go_live_at=go_live_at,
            crown=crown,
        )
        dao_create_service(
            service,
            service.created_by,
            service_id,
            service_permissions=service_permissions,
        )

        service.active = active
        service.research_mode = research_mode
        service.count_as_live = count_as_live
    else:
        if user and user not in service.users:
            dao_add_user_to_service(service, user)

    return service
Beispiel #6
0
def sample_service(notify_db,
                   notify_db_session,
                   service_name="Sample service",
                   user=None,
                   restricted=False,
                   limit=1000,
                   email_from=None,
                   permissions=None,
                   research_mode=None):
    if user is None:
        user = create_user()
    if email_from is None:
        email_from = service_name.lower().replace(' ', '.')

    data = {
        'name': service_name,
        'message_limit': limit,
        'restricted': restricted,
        'email_from': email_from,
        'created_by': user,
        'crown': True
    }
    service = Service.query.filter_by(name=service_name).first()
    if not service:
        service = Service(**data)
        dao_create_service(service, user, service_permissions=permissions)

        if research_mode:
            service.research_mode = research_mode

    else:
        if user not in service.users:
            dao_add_user_to_service(service, user)

    if permissions and INBOUND_SMS_TYPE in permissions:
        create_inbound_number('12345', service_id=service.id)

    if permissions and INBOUND_SMS_KEYWORD_TYPE in permissions:
        create_inbound_shortnumber('12345', service_id=service.id)

    return service
Beispiel #7
0
def sample_service(
    notify_db,
    notify_db_session,
    service_name="Sample service",
    user=None,
    restricted=False,
    limit=1000,
    email_from=None,
    permissions=None,
    research_mode=None,
):
    if user is None:
        user = create_user()
    if email_from is None:
        email_from = service_name.lower().replace(" ", ".")

    data = {
        "name": service_name,
        "message_limit": limit,
        "restricted": restricted,
        "email_from": email_from,
        "created_by": user,
        "crown": True,
    }
    service = Service.query.filter_by(name=service_name).first()
    if not service:
        service = Service(**data)
        dao_create_service(service, user, service_permissions=permissions)

        if research_mode:
            service.research_mode = research_mode

    else:
        if user not in service.users:
            dao_add_user_to_service(service, user)

    if permissions and INBOUND_SMS_TYPE in permissions:
        create_inbound_number("12345", service_id=service.id)

    return service