test.py 1.1 KB

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