Debian Codegraph @

misc/tools/kemi/python_mock/test.py

raw
1 #!/usr/bin/python3
2
3 import KSR
4
5 # this assumes you have your mock KSR.py in the local directory e.g. /test/
6 # and your kemi code is in ../conf/kamailio.py
7
8 sys.path.insert(0, "../conf/")
9 import kamailio as kamailio
10
11
12 #return sip:hello@world only if $ru is passed to pv.get
13 KSR._mock_data['pv']['get'] = {}
14 KSR._mock_data['pv']['get']['$ru'] = "sip:hello@world"
15 print("Got a value of: " + KSR.pv.get("$ru"))
16
17 #return maxfwd.process_maxfwd return 2 regardless of value passed
18 KSR._mock_data['maxfwd']['process_maxfwd'] = 2
19 KSR.maxfwd.process_maxfwd(10)
20 print("Got a value of: " + str(KSR.maxfwd.process_maxfwd(10)))
21
22 #set a function pointer to see if hdr.append is called
23 appendCalled = False
24 def appendHeader(param0: str):
25 global appendCalled
26 if param0.startswith("X-HDR:"):
27 appendCalled = True
28 return 1
29
30 KSR._mock_data['hdr']['append'] = appendHeader
31 KSR.hdr.append("X-HDR: my-header")
32
33 k = kamailio.kamailio()
34 k.ksr_request_route(None) # Call the kemi script, the mock implementations will be called
35
36 # Validate the results
37 if appendCalled:
38 print("hdr.append successfully called!")
39 else:
40 print("hdr.append failed to be called")