def test_func(t): pjsua = t.process[0] # Create dialog dlg = sip.Dialog("127.0.0.1", pjsua.inst_param.sip_port, tcp=cfg_file.sendto_cfg.use_tcp) #dlg = sip.Dialog("127.0.0.1", 5060, tcp=cfg_file.sendto_cfg.use_tcp) cfg = cfg_file.sendto_cfg if len(cfg.complete_msg) != 0: req = dlg.update_fields(cfg.complete_msg) else: req = dlg.create_invite(cfg.sdp, cfg.extra_headers, cfg.body) resp = dlg.send_request_wait(req, 10) if resp=="": raise TestError("Timed-out waiting for response") # Check response code code = int(sip.get_code(resp)) if code != cfg.resp_code: dlg.hangup(code) raise TestError("Expecting code " + str(cfg.resp_code) + " got " + str(code)) # Check for patterns that must exist for p in cfg.resp_include: if re.search(p, resp, re.M | re.I)==None: dlg.hangup(code) raise TestError("Pattern " + p + " not found") # Check for patterns that must not exist for p in cfg.resp_exclude: if re.search(p, resp, re.M | re.I)!=None: dlg.hangup(code) raise TestError("Excluded pattern " + p + " found") pjsua.sync_stdout() dlg.hangup(code) pjsua.sync_stdout()
def test_func(test): pjsua = test.process[0] dlg = sip.Dialog("127.0.0.1", pjsua.inst_param.sip_port, local_port=srv_port, tcp=cfg_file.recvfrom_cfg.tcp) config = pjsua.get_config(cfg_file.recvfrom_cfg.pj_config) print "Config : " + config last_cseq = 0 last_method = "" last_call_id = "" for t in cfg_file.recvfrom_cfg.transaction: # Check if transaction requires configuration if t.pj_config != "": r = re.compile(t.pj_config, re.I) if r.search(config) == None: print "Configuration : " + t.pj_config + " not found, skipping" continue # Print transaction title if t.title != "": dlg.trace(t.title) # Run command and expect patterns for c in t.cmds: if c[0] and c[0] != "": pjsua.send(c[0]) if len(c) > 1 and c[1] and c[1] != "": pjsua.expect(c[1]) # Wait for request if t.check_cseq: # Absorbs retransmissions cseq = 0 method = last_method call_id = last_call_id while cseq <= last_cseq and method == last_method and call_id == last_call_id: request, src_addr = dlg.wait_msg_from(30) if request == None or request == "": raise TestError("Timeout waiting for request") method = request.split(" ", 1)[0] cseq_hval = sip.get_header(request, "CSeq") cseq_hval = cseq_hval.split(" ")[0] cseq = int(cseq_hval) call_id = sip.get_header(request, "Call-ID") last_cseq = cseq last_method = method else: request, src_addr = dlg.wait_msg_from(30) if request == None or request == "": raise TestError("Timeout waiting for request") # Check for include patterns for pat in t.include: if re.search(pat, request, re.M | re.I) == None: if t.title: tname = " in " + t.title + " transaction" else: tname = "" raise TestError("Pattern " + pat + " not found" + tname) # Check for exclude patterns for pat in t.exclude: if re.search(pat, request, re.M | re.I) != None: if t.title: tname = " in " + t.title + " transaction" else: tname = "" raise TestError("Excluded pattern " + pat + " found" + tname) # Create response if t.resp_code != 0: response = dlg.create_response(request, t.resp_code, "Status reason") # Add headers to response for h in t.resp_hdr: response = response + h + "\r\n" # Add message body if required if t.body: response = response + t.body # Send response dlg.send_msg(response, src_addr) # Expect something to happen in pjsua if t.expect != "": pjsua.expect(t.expect) # Sync pjsua.sync_stdout()