def test_get_uuid_with_principal_none_and_empty_field(app): uuid = None session = SessionLocal(bind=app.engine) principal = None with pytest.raises(HTTPException): get_uuid(principal, session, uuid)
def test_get_uuid_mismatch_with_principal(app): uuid = uuid4() session = SessionLocal(bind=app.engine) session = SessionLocal(bind=app.engine) uuid_principal = str(uuid4()) principal = Principal( auth_id="auth_id", uuid="uuid", tenant_uuid=uuid_principal, tenant_uuids=[uuid_principal], token="token", ) with pytest.raises(HTTPException): get_uuid(principal, session, uuid)
def create_carrier_trunk( db: Session, principal: Principal, carrier_trunk: schema.CarrierTrunkCreate ) -> CarrierTrunk: carrier_trunk.tenant_uuid = tenant_service.get_uuid( principal, db, carrier_trunk.tenant_uuid ) db_carrier_trunk = CarrierTrunk( tenant_uuid=carrier_trunk.tenant_uuid, carrier_id=carrier_trunk.carrier_id, name=carrier_trunk.name, normalization_profile_id=carrier_trunk.normalization_profile_id, sip_proxy=carrier_trunk.sip_proxy, sip_proxy_port=carrier_trunk.sip_proxy_port, ip_address=carrier_trunk.ip_address, registered=carrier_trunk.registered, auth_username=carrier_trunk.auth_username, auth_password=password_service.hash(carrier_trunk.auth_password), realm=carrier_trunk.realm, registrar_proxy=carrier_trunk.registrar_proxy, from_domain=carrier_trunk.from_domain, expire_seconds=carrier_trunk.expire_seconds, retry_seconds=carrier_trunk.retry_seconds, ) db.add(db_carrier_trunk) db.commit() db.refresh(db_carrier_trunk) return db_carrier_trunk
def test_get_uuid_with_principal_none(app): uuid = uuid4() session = SessionLocal(bind=app.engine) principal = None res = get_uuid(principal, session, uuid) assert res == uuid
def create_domain(db: Session, principal: Principal, domain: schema.DomainCreate) -> Domain: domain.tenant_uuid = tenant_service.get_uuid(principal, db, domain.tenant_uuid) db_domain = Domain(domain=domain.domain, tenant_uuid=domain.tenant_uuid) db.add(db_domain) db.commit() db.refresh(db_domain) return db_domain
def create_carrier( db: Session, principal: Principal, carrier: schema.CarrierCreate ) -> Carrier: carrier.tenant_uuid = tenant_service.get_uuid(principal, db, carrier.tenant_uuid) db_carrier = Carrier(name=carrier.name, tenant_uuid=carrier.tenant_uuid) db.add(db_carrier) db.commit() db.refresh(db_carrier) return db_carrier
def test_get_uuid_with_principal(app): uuid = uuid4() session = SessionLocal(bind=app.engine) principal = Principal( auth_id="auth_id", uuid="uuid", tenant_uuid=str(uuid), tenant_uuids=[str(uuid)], token="token", ) res = get_uuid(principal, session, None) assert res == uuid
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
def create_did(db: Session, principal: Principal, did: schema.DIDCreate) -> DID: did.tenant_uuid = tenant_service.get_uuid(principal, db, did.tenant_uuid) db_did = DID( did_regex=did.did_regex, did_prefix=get_did_prefix_from_regex(did.did_regex), carrier_trunk_id=did.carrier_trunk_id, tenant_uuid=did.tenant_uuid, ipbx_id=did.ipbx_id, ) db.add(db_did) db.commit() db.refresh(db_did) return db_did
def create_cdr(db: Session, principal: Principal, cdr: schema.CDRCreate) -> CDR: cdr.tenant_uuid = tenant_service.get_uuid(principal, db, cdr.tenant_uuid) db_cdr = CDR( tenant_uuid=cdr.tenant_uuid, source_ip=cdr.source_ip, source_port=cdr.source_port, from_uri=cdr.from_uri, to_uri=cdr.to_uri, call_id=cdr.call_id, call_start=cdr.call_start, duration=cdr.duration, ) db.add(db_cdr) db.commit() db.refresh(db_cdr) return db_cdr
def create_normalization_profile( db: Session, principal: Principal, normalization_profile: schema.NormalizationProfileCreate, ) -> NormalizationProfile: normalization_profile.tenant_uuid = tenant_service.get_uuid( principal, db, normalization_profile.tenant_uuid) db_normalization_profile = NormalizationProfile( name=normalization_profile.name, tenant_uuid=normalization_profile.tenant_uuid, country_code=normalization_profile.country_code, area_code=normalization_profile.area_code, intl_prefix=normalization_profile.intl_prefix, ld_prefix=normalization_profile.ld_prefix, always_ld=normalization_profile.always_ld, always_intl_prefix_plus=normalization_profile.always_intl_prefix_plus, ) db.add(db_normalization_profile) db.commit() db.refresh(db_normalization_profile) return db_normalization_profile
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