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 test_kamailio_routing_did_with_no_matching_ipbx(app, client): 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.did import DID session = SessionLocal(bind=app.engine) tenant = Tenant(name='fabio', uuid='5a6c0c40-b481-41bb-a41a-75d1cc25ff34') domain = Domain(domain='testdomain.com', tenant=tenant) ipbx = IPBX( tenant=tenant, domain=domain, customer=1, ip_fqdn='mypbx.com', registered=True, username='******', password='******', ) carrier = Carrier(name='carrier', tenant=tenant) carrier_trunk = CarrierTrunk(name='carrier_trunk1', carrier=carrier, sip_proxy='proxy.somedomain.com') did = DID( did_regex=r'^39[0-9]+$', did_prefix='39', tenant=tenant, ipbx=ipbx, carrier_trunk=carrier_trunk, ) session.add_all([tenant, domain, ipbx, carrier, carrier_trunk, did]) session.commit() # request_from_name = "From name" request_from_uri = "sip:[email protected]" request_from_tag = "from_tag" request_to_name = "to name" request_to_uri = "sip:[email protected]" request_to_tag = "to_tag" # response = client.post( "/1.0/kamailio/routing", json={ "event": "sip-routing", "source_ip": "10.0.0.1", "source_port": 5060, "call_id": "call-id", "from_name": request_from_name, "from_uri": request_from_uri, "from_tag": request_from_tag, "to_uri": request_to_uri, "to_name": request_to_name, "to_tag": request_to_tag, }, ) assert response.status_code == 200 assert response.json() == {"auth": None, "rtjson": {"success": False}}
def test_kamailio_cdr_failed_no_tenant(app, client): 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.did import DID session = SessionLocal(bind=app.engine) tenant = Tenant(name='fabio', uuid='5a6c0c40-b481-41bb-a41a-75d1cc25ff34') domain = Domain(domain='testdomain.com', tenant=tenant) ipbx = IPBX( tenant=tenant, domain=domain, customer=1, ip_fqdn='mypbx.com', registered=True, username='******', password='******', ) carrier = Carrier(name='carrier', tenant=tenant) carrier_trunk = CarrierTrunk( name='carrier_trunk1', carrier=carrier, sip_proxy='proxy.somedomain.com' ) did = DID( did_regex=r'^39[0-9]+$', did_prefix='39', tenant=tenant, ipbx=ipbx, carrier_trunk=carrier_trunk, ) session.add_all([tenant, domain, ipbx, carrier, carrier_trunk, did]) session.commit() # request_from_uri = "*****@*****.**" request_to_uri = "*****@*****.**" call_start = 1570752000 duration = 60 # response = client.post( "/1.0/kamailio/cdr", json={ "tenant_uuid": "5ecdf9dd-36d3-4735-a5e8-99bd297bc325", "event": "sip-routing", "source_ip": "10.0.0.1", "source_port": 5060, "call_id": "call-id", "from_uri": request_from_uri, "to_uri": request_to_uri, "call_start": call_start, "duration": duration, }, ) assert response.status_code == 200 assert response.json() == {"success": False, "cdr": None}
def test_update_ipbx(app_auth, client_auth_with_token): from wazo_router_confd.database import SessionLocal from wazo_router_confd.models.ipbx import IPBX from wazo_router_confd.models.domain import Domain from wazo_router_confd.models.tenant import Tenant tenant = Tenant(name='fabio', uuid="ffffffff-ffff-4c1c-ad1c-ffffffffffff") tenant_2 = Tenant(name='sileht', uuid='ff69a896-8025-4b0c-993e-1ee6449091c5') domain = Domain(domain='testdomain.com', tenant=tenant) domain_2 = Domain(domain='otherdomain.com', tenant=tenant_2) ipbx = IPBX( tenant=tenant, domain=domain, customer=1, ip_fqdn='mypbx.com', ip_address="10.0.0.1", registered=True, username='******', password='******', realm='realm', ) session = SessionLocal(bind=app_auth.engine) session.add_all([tenant, tenant_2, domain, domain_2, ipbx]) session.commit() # response = client_auth_with_token.put( "/1.0/ipbxs/%s" % ipbx.id, json={ 'ip_fqdn': 'mypbx2.com', 'tenant_uuid': str(tenant_2.uuid), 'domain_id': domain_2.id, 'username': '******', 'password': '******', 'registered': False, }, ) assert response.status_code == 200 assert response.json() == { "id": ipbx.id, "customer": 1, "normalization_profile_id": None, "ip_fqdn": "mypbx2.com", "port": 5060, "ip_address": "10.0.0.1", "domain_id": domain_2.id, "tenant_uuid": str(tenant_2.uuid), "registered": False, "username": "******", "realm": "realm", }
def test_kamailio_routing_with_no_matching_ipbx(app=None, client=None): from wazo_router_confd.database import SessionLocal from wazo_router_confd.models.tenant import Tenant from wazo_router_confd.models.domain import Domain from wazo_router_confd.models.ipbx import IPBX session = SessionLocal(bind=app.engine) tenant = Tenant(name='fabio') domain = Domain(domain='testdomain.com', tenant=tenant) ipbx = IPBX( customer=1, ip_fqdn='mypbx.com', domain=domain, registered=True, username='******', sha1='da39a3ee5e6b4b0d3255bfef95601890afd80709', sha1b='f10e2821bbbea527ea02200352313bc059445190', tenant=tenant, ) session.add_all([tenant, domain, ipbx]) session.commit() # request_from_name = "From name" request_from_uri = "*****@*****.**" request_from_tag = "from_tag" request_to_name = "to name" request_to_uri = "*****@*****.**" request_to_tag = "to_tag" # response = client.post( "/kamailio/routing", json={ "event": "sip-routing", "source_ip": "10.0.0.1", "source_port": 5060, "call_id": "call-id", "from_name": request_from_name, "from_uri": request_from_uri, "from_tag": request_from_tag, "to_uri": request_to_uri, "to_name": request_to_name, "to_tag": request_to_tag, }, ) assert response.status_code == 200 assert response.json() == { "version": "1.0", "routing": "serial", "routes": [] }
def create_ipbx(db: Session, ipbx: schema.IPBXCreate): db_ipbx = IPBX( tenant_id=ipbx.tenant_id, domain_id=ipbx.domain_id, customer=ipbx.customer, ip_fqdn=ipbx.ip_fqdn, port=ipbx.port, registered=ipbx.registered, username=ipbx.username, sha1=ipbx.sha1, sha1b=ipbx.sha1b, ) db.add(db_ipbx) db.commit() db.refresh(db_ipbx) return db_ipbx
def test_get_dids(app, client): 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.did import DID session = SessionLocal(bind=app.engine) tenant = Tenant(name='fabio', uuid='5a6c0c40-b481-41bb-a41a-75d1cc25ff34') domain = Domain(domain='testdomain.com', tenant=tenant) ipbx = IPBX( tenant=tenant, domain=domain, customer=1, ip_fqdn='mypbx.com', registered=True, username='******', password='******', ) carrier = Carrier(name='carrier', tenant=tenant) carrier_trunk = CarrierTrunk(name='carrier_trunk1', carrier=carrier, sip_proxy='proxy.somedomain.com') did = DID( did_regex=r'^(\+?1)?(8(00|44|55|66|77|88)[2-9]\d{6})$', tenant=tenant, ipbx=ipbx, carrier_trunk=carrier_trunk, ) session.add_all([tenant, domain, ipbx, carrier, carrier_trunk, did]) session.commit() # response = client.get("/1.0/dids") assert response.status_code == 200 assert response.json() == { "items": [{ "id": did.id, "did_regex": r"^(\+?1)?(8(00|44|55|66|77|88)[2-9]\d{6})$", "tenant_uuid": str(tenant.uuid), "ipbx_id": ipbx.id, "carrier_trunk_id": carrier_trunk.id, }] }
def test_update_ipbx(app=None, client=None): from wazo_router_confd.database import SessionLocal from wazo_router_confd.models.ipbx import IPBX from wazo_router_confd.models.domain import Domain from wazo_router_confd.models.tenant import Tenant tenant = Tenant(name='fabio') domain = Domain(domain='testdomain.com', tenant=tenant) ipbx = IPBX( tenant=tenant, domain=domain, customer=1, ip_fqdn='mypbx.com', registered=True, username='******', sha1='da39a3ee5e6b4b0d3255bfef95601890afd80709', sha1b='f10e2821bbbea527ea02200352313bc059445190', ) session = SessionLocal(bind=app.engine) session.add_all([tenant, domain, ipbx]) session.commit() # response = client.put( "/ipbx/1", json={ 'ip_fqdn': 'mypbx2.com', 'tenant_id': 2, 'domain_id': 3, 'username': '******', 'registered': False, }, ) assert response.status_code == 200 assert response.json() == { "id": 1, "customer": 1, "ip_fqdn": "mypbx2.com", "port": 5060, "domain_id": 3, "tenant_id": 2, "registered": False, "username": "******", "sha1": "da39a3ee5e6b4b0d3255bfef95601890afd80709", "sha1b": "f10e2821bbbea527ea02200352313bc059445190", }
def test_kamailio_routing_outbound_with_no_matching_ipbx(app, client): from wazo_router_confd.database import SessionLocal from wazo_router_confd.models.tenant import Tenant from wazo_router_confd.models.domain import Domain from wazo_router_confd.models.ipbx import IPBX session = SessionLocal(bind=app.engine) tenant = Tenant(name='fabio', uuid='5a6c0c40-b481-41bb-a41a-75d1cc25ff34') domain = Domain(domain='testdomain.com', tenant=tenant) ipbx = IPBX( customer=1, ip_fqdn='10.0.0.2', domain=domain, registered=True, username='******', password='******', tenant=tenant, ) session.add_all([tenant, domain, ipbx]) session.commit() # request_from_name = "From name" request_from_uri = "*****@*****.**" request_from_tag = "from_tag" request_to_name = "to name" request_to_uri = "*****@*****.**" request_to_tag = "to_tag" # response = client.post( "/1.0/kamailio/routing", json={ "event": "sip-routing", "source_ip": "10.0.0.1", "source_port": 5060, "call_id": "call-id", "from_name": request_from_name, "from_uri": request_from_uri, "from_tag": request_from_tag, "to_uri": request_to_uri, "to_name": request_to_name, "to_tag": request_to_tag, }, ) assert response.status_code == 200 assert response.json() == {"auth": None, "rtjson": {"success": False}}
def test_kamailio_auth_ip_address_username_fails(app_auth, client_auth_with_token): from wazo_router_confd.database import SessionLocal from wazo_router_confd.models.tenant import Tenant from wazo_router_confd.models.domain import Domain from wazo_router_confd.models.ipbx import IPBX from wazo_router_confd.services import password session = SessionLocal(bind=app_auth.engine) tenant = Tenant(name='fabio', uuid="ffffffff-ffff-4c1c-ad1c-ffffffffffff") domain = Domain(domain='testdomain.com', tenant=tenant) ipbx = IPBX( customer=1, ip_fqdn='mypbx.com', domain=domain, registered=True, ip_address="10.0.0.1", username='******', password_ha1=password.hash_ha1('user', domain.domain, 'password'), tenant=tenant, ) session.add_all([tenant, domain, ipbx]) session.commit() # response = client_auth_with_token.post( "/1.0/kamailio/auth", json={ "source_ip": "10.0.0.1", "username": "******", "password": "******", }, ) assert response.status_code == 200 assert response.json() == { "success": False, "tenant_uuid": None, "carrier_trunk_id": None, "ipbx_id": None, "domain": None, "username": None, "password_ha1": None, }
def test_get_ipbxs(app_auth, client_auth_with_token): from wazo_router_confd.database import SessionLocal from wazo_router_confd.models.domain import Domain from wazo_router_confd.models.tenant import Tenant from wazo_router_confd.models.ipbx import IPBX tenant = Tenant(name='fabio', uuid="ffffffff-ffff-4c1c-ad1c-ffffffffffff") domain = Domain(domain='testdomain.com', tenant=tenant) ipbx = IPBX( tenant=tenant, domain=domain, customer=1, ip_fqdn='mypbx.com', ip_address="10.0.0.1", registered=True, username='******', password='******', realm='realm', ) session = SessionLocal(bind=app_auth.engine) session.add_all([tenant, domain, ipbx]) session.commit() # response = client_auth_with_token.get("/1.0/ipbxs") assert response.status_code == 200 assert response.json() == { "items": [{ "id": ipbx.id, "customer": 1, "normalization_profile_id": None, "ip_fqdn": "mypbx.com", "port": 5060, "ip_address": "10.0.0.1", "domain_id": domain.id, "tenant_uuid": str(tenant.uuid), "registered": True, "username": "******", "realm": "realm", }] }
def test_delete_ipbx(app, client): from wazo_router_confd.database import SessionLocal from wazo_router_confd.models.ipbx import IPBX from wazo_router_confd.models.domain import Domain from wazo_router_confd.models.tenant import Tenant tenant = Tenant(name='fabio', uuid='5a6c0c40-b481-41bb-a41a-75d1cc25ff34') domain = Domain(domain='testdomain.com', tenant=tenant) ipbx = IPBX( tenant=tenant, domain=domain, customer=1, ip_fqdn='mypbx.com', registered=True, ip_address="10.0.0.1", username='******', password='******', realm='realm', ) session = SessionLocal(bind=app.engine) session.add_all([tenant, domain, ipbx]) session.commit() # response = client.delete("/1.0/ipbxs/%s" % ipbx.id) assert response.status_code == 200 assert response.json() == { "id": ipbx.id, "customer": 1, "normalization_profile_id": None, "ip_fqdn": "mypbx.com", "port": 5060, "ip_address": "10.0.0.1", "domain_id": domain.id, "tenant_uuid": str(tenant.uuid), "registered": True, "username": "******", "realm": "realm", }
def create_ipbx(db: Session, principal: Principal, ipbx: schema.IPBXCreate) -> IPBX: ipbx.tenant_uuid = tenant_service.get_uuid(principal, db, ipbx.tenant_uuid) domain = db.query(Domain).filter(Domain.id == ipbx.domain_id).first() db_ipbx = IPBX( tenant_uuid=ipbx.tenant_uuid, domain_id=ipbx.domain_id, normalization_profile_id=ipbx.normalization_profile_id, customer=ipbx.customer, ip_fqdn=ipbx.ip_fqdn, port=ipbx.port, ip_address=ipbx.ip_address, registered=ipbx.registered, username=ipbx.username, password=password_service.hash(ipbx.password), password_ha1=password_service.hash_ha1(ipbx.username, domain.domain, ipbx.password), realm=ipbx.realm, ) db.add(db_ipbx) db.commit() db.refresh(db_ipbx) return db_ipbx
def test_kamailio_routing_domain_with_single_ipbx_and_auth( app_auth, client_auth_with_token): from wazo_router_confd.database import SessionLocal from wazo_router_confd.models.tenant import Tenant from wazo_router_confd.models.domain import Domain from wazo_router_confd.models.carrier_trunk import CarrierTrunk from wazo_router_confd.models.carrier import Carrier from wazo_router_confd.models.ipbx import IPBX from wazo_router_confd.models.normalization import NormalizationProfile session = SessionLocal(bind=app_auth.engine) tenant = Tenant(name='fabio', uuid='0839cb47-5d31-4b5e-8c5b-a2481f9e212a') domain = Domain(domain='testdomain.com', tenant=tenant) normalization_profile = NormalizationProfile( tenant=tenant, name='Profile', country_code='39', area_code='040', intl_prefix='00', ld_prefix='', always_intl_prefix_plus=False, always_ld=False, ) ipbx = IPBX( customer=1, ip_fqdn='mypbx.com', ip_address='192.168.0.1', domain=domain, registered=True, username='******', password='******', normalization_profile=normalization_profile, tenant=tenant, ) carrier = Carrier(name="carrier", tenant=tenant) carrier_trunk = CarrierTrunk( name='carrier_trunk1', tenant=tenant, carrier=carrier, normalization_profile=normalization_profile, sip_proxy='proxy.somedomain.com', ip_address="10.0.0.1", ) session = SessionLocal(bind=app_auth.engine) session.add_all( [tenant, domain, normalization_profile, ipbx, carrier, carrier_trunk]) session.commit() # request_from_name = "From name" request_from_uri = "sip:[email protected]" request_from_tag = "from_tag" request_to_name = "to name" request_to_uri = "sip:[email protected]" request_to_tag = "to_tag" # response = client_auth_with_token.post( "/1.0/kamailio/routing", json={ "event": "sip-routing", "source_ip": "10.0.0.1", "source_port": 5060, "call_id": "call-id", "from_name": request_from_name, "from_uri": request_from_uri, "from_tag": request_from_tag, "to_uri": request_to_uri, "to_name": request_to_name, "to_tag": request_to_tag, "auth": True, }, ) assert response.status_code == 200 assert response.json() == { "auth": { 'tenant_uuid': str(tenant.uuid), 'carrier_trunk_id': carrier_trunk.id, 'ipbx_id': None, 'domain': None, 'username': None, 'password_ha1': None, 'success': True, }, "rtjson": { "success": True, "version": "1.0", "routing": "serial", "routes": [{ "dst_uri": "sip:%s:5060" % (ipbx.ip_fqdn), "path": "", "socket": "", "headers": { "from": { "display": request_from_name, "uri": request_from_uri }, "to": { "display": request_to_name, "uri": request_to_uri }, "extra": "P-Asserted-Identity: <sip:" + request_from_name + "@" + request_from_uri + ">\r\n", }, "branch_flags": 8, "fr_timer": 5000, "fr_inv_timer": 30000, }], }, }
def test_kamailio_routing_domain_with_single_authenticated_ipbx(app, client): from wazo_router_confd.database import SessionLocal from wazo_router_confd.models.tenant import Tenant from wazo_router_confd.models.domain import Domain from wazo_router_confd.models.ipbx import IPBX session = SessionLocal(bind=app.engine) tenant = Tenant(name='fabio', uuid='5a6c0c40-b481-41bb-a41a-75d1cc25ff34') domain = Domain(domain='testdomain.com', tenant=tenant) ipbx = IPBX( customer=1, ip_fqdn='mypbx.com', domain=domain, registered=True, username='******', password='******', realm='realm', tenant=tenant, ) session.add_all([tenant, domain, ipbx]) session.commit() # request_from_name = "From name" request_from_uri = "sip:[email protected]" request_from_tag = "from_tag" request_to_name = "to name" request_to_uri = "sip:[email protected]" request_to_tag = "to_tag" # response = client.post( "/1.0/kamailio/routing", json={ "event": "sip-routing", "source_ip": "10.0.0.1", "source_port": 5060, "call_id": "call-id", "from_name": request_from_name, "from_uri": request_from_uri, "from_tag": request_from_tag, "to_uri": request_to_uri, "to_name": request_to_name, "to_tag": request_to_tag, }, ) assert response.status_code == 200 assert response.json() == { "auth": None, "rtjson": { "success": True, "version": "1.0", "routing": "serial", "routes": [ { "dst_uri": "sip:%s:5060" % (ipbx.ip_fqdn), "path": "", "socket": "", "headers": { "from": {"display": request_from_name, "uri": request_from_uri}, "to": {"display": request_to_name, "uri": request_to_uri}, "extra": "", }, "branch_flags": 8, "fr_timer": 5000, "fr_inv_timer": 30000, } ], "auth_username": "******", "auth_password": "******", "realm": "realm", }, }
def test_kamailio_routing_outbound_with_single_ipbx(app, client): from wazo_router_confd.database import SessionLocal from wazo_router_confd.models.tenant import Tenant from wazo_router_confd.models.domain import Domain from wazo_router_confd.models.carrier import Carrier from wazo_router_confd.models.carrier_trunk import CarrierTrunk from wazo_router_confd.models.ipbx import IPBX from wazo_router_confd.models.normalization import NormalizationProfile session = SessionLocal(bind=app.engine) tenant = Tenant(name='fabio', uuid='5a6c0c40-b481-41bb-a41a-75d1cc25ff34') domain = Domain(domain='testdomain.com', tenant=tenant) normalization_profile = NormalizationProfile( tenant=tenant, name='Profile', country_code='39', area_code='040', intl_prefix='00', ld_prefix='', always_intl_prefix_plus=False, always_ld=False, ) carrier = Carrier(name='carrier1', tenant=tenant) carrier_trunk = CarrierTrunk( name='trunk1', carrier=carrier, sip_proxy='192.168.1.1', normalization_profile=normalization_profile, ) ipbx = IPBX( customer=1, ip_fqdn='10.0.0.1', domain=domain, registered=True, username='******', password='******', tenant=tenant, normalization_profile=normalization_profile, ) session.add_all( [tenant, domain, normalization_profile, ipbx, carrier, carrier_trunk]) session.commit() # request_from_name = "From name" request_from_uri = "sip:[email protected]" request_from_tag = "from_tag" request_to_name = "to name" request_to_uri = "sip:[email protected]" request_to_tag = "to_tag" # response = client.post( "/1.0/kamailio/routing", json={ "event": "sip-routing", "source_ip": "10.0.0.1", "source_port": 5060, "call_id": "call-id", "from_name": request_from_name, "from_uri": request_from_uri, "from_tag": request_from_tag, "to_uri": request_to_uri, "to_name": request_to_name, "to_tag": request_to_tag, }, ) assert response.status_code == 200 assert response.json() == { "auth": None, "rtjson": { "success": True, "version": "1.0", "routing": "serial", "routes": [{ "dst_uri": "sip:%s:%s" % (carrier_trunk.sip_proxy, carrier_trunk.sip_proxy_port), "path": "", "socket": "", "headers": { "from": { "display": request_from_name, "uri": request_from_uri }, "to": { "display": request_to_name, "uri": request_to_uri }, "extra": "", }, "branch_flags": 8, "fr_timer": 5000, "fr_inv_timer": 30000, }], }, }
def test_kamailio_routing_outbound_with_single_ipbx_and_authenticated_carrier_trunk( app, client): from wazo_router_confd.database import SessionLocal from wazo_router_confd.models.tenant import Tenant from wazo_router_confd.models.domain import Domain from wazo_router_confd.models.carrier import Carrier from wazo_router_confd.models.carrier_trunk import CarrierTrunk from wazo_router_confd.models.ipbx import IPBX session = SessionLocal(bind=app.engine) tenant = Tenant(name='fabio', uuid='5a6c0c40-b481-41bb-a41a-75d1cc25ff34') domain = Domain(domain='testdomain.com', tenant=tenant) carrier = Carrier(name='carrier1', tenant=tenant) carrier_trunk = CarrierTrunk( name='trunk1', carrier=carrier, sip_proxy='192.168.1.1', registered=True, auth_username='******', auth_password='******', realm='realm', ) ipbx = IPBX( customer=1, ip_fqdn='10.0.0.1', domain=domain, registered=True, username='******', password='******', tenant=tenant, ) session.add_all([tenant, domain, ipbx, carrier, carrier_trunk]) session.commit() # request_from_name = "From name" request_from_uri = "sip:[email protected]" request_from_tag = "from_tag" request_to_name = "to name" request_to_uri = "sip:[email protected]" request_to_tag = "to_tag" # response = client.post( "/1.0/kamailio/routing", json={ "event": "sip-routing", "source_ip": "10.0.0.1", "source_port": 5060, "call_id": "call-id", "from_name": request_from_name, "from_uri": request_from_uri, "from_tag": request_from_tag, "to_uri": request_to_uri, "to_name": request_to_name, "to_tag": request_to_tag, }, ) assert response.status_code == 200 assert response.json() == { "auth": None, "rtjson": { "success": True, "version": "1.0", "routing": "serial", "routes": [{ "dst_uri": "sip:%s:%s" % (carrier_trunk.sip_proxy, carrier_trunk.sip_proxy_port), "path": "", "socket": "", "headers": { "from": { "display": request_from_name, "uri": request_from_uri }, "to": { "display": request_to_name, "uri": request_to_uri }, "extra": "P-Asserted-Identity: <sip:" + request_from_name + "@" + request_from_uri + ">\r\n", }, "branch_flags": 8, "fr_timer": 5000, "fr_inv_timer": 30000, }], "auth_username": "******", "auth_password": "******", "realm": "realm", }, }