def create_routing_rule(app_auth, tenant_uuid, suffix=1):
    from wazo_router_confd.database import SessionLocal
    from wazo_router_confd.models.carrier import Carrier
    from wazo_router_confd.models.carrier_trunk import CarrierTrunk
    from wazo_router_confd.models.domain import Domain
    from wazo_router_confd.models.tenant import Tenant
    from wazo_router_confd.models.ipbx import IPBX
    from wazo_router_confd.models.routing_group import RoutingGroup
    from wazo_router_confd.models.routing_rule import RoutingRule

    session = SessionLocal(bind=app_auth.engine)
    tenant = session.query(Tenant).filter(Tenant.uuid == tenant_uuid).first()
    if tenant is None:
        tenant = Tenant(name="tenant_{}".format(suffix), uuid=tenant_uuid)
        session.add(tenant)
    domain = Domain(domain='testdomain_{}.com'.format(suffix), tenant=tenant)
    ipbx = IPBX(
        tenant=tenant,
        domain=domain,
        customer=1,
        ip_fqdn='mypbx.com',
        registered=True,
        username='******',
        password='******',
    )
    carrier = Carrier(name='carrier_{}'.format(suffix), tenant=tenant)
    carrier_trunk = CarrierTrunk(
        name='carrier_trunk_{}'.format(suffix),
        carrier=carrier,
        sip_proxy='proxy.somedomain.com',
    )
    carrier_trunk_2 = CarrierTrunk(
        name='carrier_trunk_{}_bis'.format(suffix),
        carrier=carrier,
        sip_proxy='proxy.somedomain.com',
    )
    routing_rule = RoutingRule(
        prefix="39",
        carrier_trunk=carrier_trunk,
        ipbx=ipbx,
        did_regex=r'^(\+?1)?(8(00|44|55|66|77|88)[2-9]\d{6})$',
        route_type="pstn",
    )
    routing_group = RoutingGroup(tenant=tenant, routing_rule=routing_rule)

    session.add_all([
        tenant,
        domain,
        carrier,
        carrier_trunk,
        carrier_trunk_2,
        ipbx,
        routing_rule,
        routing_group,
    ])
    session.commit()

    session.flush()

    return routing_rule, ipbx, carrier_trunk, tenant, session
Exemplo n.º 2
0
def create_routing_group(db: Session,
                         routing_group: schema.RoutingGroupCreate):
    db_routing_group = RoutingGroup(routing_rule=routing_group.routing_rule,
                                    tenant_id=routing_group.tenant_id)
    db.add(db_routing_group)
    db.commit()
    db.refresh(db_routing_group)
    return db_routing_group
Exemplo n.º 3
0
def test_get_routing_groups(app=None, client=None):
    from wazo_router_confd.database import SessionLocal
    from wazo_router_confd.models.routing_group import RoutingGroup

    session = SessionLocal(bind=app.engine)
    session.add(RoutingGroup(routing_rule=1, tenant_id=1))
    session.commit()
    #
    response = client.get("/routing_groups/")
    assert response.status_code == 200
    assert response.json() == [{"id": 1, "routing_rule": 1, "tenant_id": 1}]
Exemplo n.º 4
0
def create_routing_group(
        db: Session, principal: Principal,
        routing_group: schema.RoutingGroupCreate) -> RoutingGroup:
    routing_group.tenant_uuid = tenant_service.get_uuid(
        principal, db, routing_group.tenant_uuid)
    db_routing_group = RoutingGroup(
        routing_rule_id=routing_group.routing_rule_id,
        tenant_uuid=routing_group.tenant_uuid,
    )
    db.add(db_routing_group)
    db.commit()
    db.refresh(db_routing_group)
    return db_routing_group