| 1 |
import sys |
| 2 |
import inc_sip as sip |
| 3 |
import inc_const as const |
| 4 |
import inc_util as util |
| 5 |
import re |
| 6 |
from inc_cfg import * |
| 7 |
|
| 8 |
|
| 9 |
cfg_file = util.load_module_from_file("cfg_file", ARGS[1]) |
| 10 |
|
| 11 |
|
| 12 |
def test_func(t): |
| 13 |
pjsua = t.process[0] |
| 14 |
|
| 15 |
dlg = sip.Dialog("127.0.0.1", pjsua.inst_param.sip_port, |
| 16 |
tcp=cfg_file.sendto_cfg.use_tcp) |
| 17 |
|
| 18 |
cfg = cfg_file.sendto_cfg |
| 19 |
|
| 20 |
if len(cfg.complete_msg) != 0: |
| 21 |
req = dlg.update_fields(cfg.complete_msg) |
| 22 |
else: |
| 23 |
req = dlg.create_invite(cfg.sdp, cfg.extra_headers, cfg.body) |
| 24 |
resp = dlg.send_request_wait(req, 10) |
| 25 |
if resp=="": |
| 26 |
raise TestError("Timed-out waiting for response") |
| 27 |
|
| 28 |
code = int(sip.get_code(resp)) |
| 29 |
if code != cfg.resp_code: |
| 30 |
dlg.hangup(code) |
| 31 |
raise TestError("Expecting code " + str(cfg.resp_code) + |
| 32 |
" got " + str(code)) |
| 33 |
|
| 34 |
for p in cfg.resp_include: |
| 35 |
if re.search(p, resp, re.M | re.I)==None: |
| 36 |
dlg.hangup(code) |
| 37 |
raise TestError("Pattern " + p + " not found") |
| 38 |
|
| 39 |
for p in cfg.resp_exclude: |
| 40 |
if re.search(p, resp, re.M | re.I)!=None: |
| 41 |
dlg.hangup(code) |
| 42 |
raise TestError("Excluded pattern " + p + " found") |
| 43 |
pjsua.sync_stdout() |
| 44 |
dlg.hangup(code) |
| 45 |
pjsua.sync_stdout() |
| 46 |
|
| 47 |
|
| 48 |
test = TestParam(cfg_file.sendto_cfg.name, |
| 49 |
[cfg_file.sendto_cfg.inst_param], |
| 50 |
test_func) |
| 51 |
|
| 52 |
|