Example #1
0
def test_update_routing_rule(app=None, client=None):
    from wazo_router_confd.database import SessionLocal
    from wazo_router_confd.models.routing_rule import RoutingRule

    session = SessionLocal(bind=app.engine)
    session.add(
        RoutingRule(
            prefix="39",
            carrier_trunk_id=1,
            ipbx_id=1,
            did_regex=r'^(\+?1)?(8(00|44|55|66|77|88)[2-9]\d{6})$',
            route_type="pstn",
        ))
    session.commit()
    #
    response = client.put(
        "/routing_rules/1",
        json={
            'prefix': '40',
            'carrier_trunk_id': 2,
            'ipbx_id': 1,
            'did_regex': r'^(\+?1)?(8(00|44|55|66|77|88)[2-9]\d{6})$',
            'route_type': "pstn",
        },
    )
    assert response.status_code == 200
    assert response.json() == {
        "id": 1,
        "prefix": "40",
        "carrier_trunk_id": 2,
        "ipbx_id": 1,
        "did_regex": r"^(\+?1)?(8(00|44|55|66|77|88)[2-9]\d{6})$",
        "route_type": "pstn",
    }
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
def create_routing_rule(db: Session, routing_rule: schema.RoutingRuleCreate):
    db_routing_rule = RoutingRule(
        prefix=routing_rule.prefix,
        carrier_trunk_id=routing_rule.carrier_trunk_id,
        ipbx_id=routing_rule.ipbx_id,
        did_regex=routing_rule.did_regex,
        route_type=routing_rule.route_type,
    )
    db.add(db_routing_rule)
    db.commit()
    db.refresh(db_routing_rule)
    return db_routing_rule