Trying to write ATS test for dial plan

Hello, I am new to Asterisk, just wrote my first module.
I have been trying all day to come up with an ATS test for my dial plan.
Can anyone advise on how to set this up ?

My dial plan

[main-menu]
exten => s,1,Answer()
same => n,Playback(welcome) ; Play a welcome message
same => n,Read(choice,enter-option,1) ; Prompt the user to enter an option

; Toggle module enablement if user presses 1
exten => 1,1,Verbose(1,Toggle module enablement)
same => n,Set(GLOBAL(APP_KNISPER_ENABLE)=${IF($[${ISNULL(${GLOBAL(APP_KNISPER_ENABLE)})} | $[${GLOBAL(APP_KNISPER_ENABLE)} = 0]]?1:0)})
same => n,Goto(main-menu,s,1)

; Set AGE variable to 60 if user presses 2
exten => 2,1,Verbose(1,Set AGE to 60)
same => n,Set(GLOBAL(APP_KNISPER_AGE)=60)
same => n,Goto(main-menu,s,1)

; Set AGE variable to 70 if user presses 3
exten => 3,1,Verbose(1,Set AGE to 70)
same => n,Set(GLOBAL(APP_KNISPER_AGE)=70)
same => n,Goto(main-menu,s,1)

; Set AGE variable to 80 if user presses 4
exten => 4,1,Verbose(1,Set AGE to 80)
same => n,Set(GLOBAL(APP_KNISPER_AGE)=80)
same => n,Goto(main-menu,s,1)

; Set AGE variable to custom value (two digits) if user presses 5
exten => 5,1,Verbose(1,Enter custom AGE value)
same => n,Read(AGE,enter-age) ; Prompt the user to enter a custom age
same => n,Set(GLOBAL(APP_KNISPER_AGE)=${AGE})
same => n,Goto(main-menu,s,1)

; Hang up if user doesn't press 1, 2, 3, 4 or 5
exten => i,1,Hangup()
exten => t,1,Hangup()
exten => e,1,Hangup()

What I would like to test:

properties:
  run: 1

test:
  - name: test_1
    dtmf: "1"
    variable: "APP_KNISPER_ENABLE"
    expected_value: "1"
  - name: test_2
    dtmf: "2"
    variable: "APP_KNISPER_AGE"
    expected_value: "60"
  - name: test_3
    dtmf: "3"
    variable: "APP_KNISPER_AGE"
    expected_value: "70"
  - name: test_4
    dtmf: "4"
    variable: "APP_KNISPER_AGE"
    expected_value: "80"
  - name: test_5
    dtmf: "5"
    custom_age_dtmf: "45"
    variable: "APP_KNISPER_AGE"
    expected_value: "45"

I have built the ATS, but I had to use Python 3.9 because of bug in 3.11.
I have created a folder in tests named knisper, and add a test-config.yaml,
and then I try to run it as follows :

./runInVenv.sh /usr/bin/python3.9 runtests.py -t tests/knisper

Error is

ValueError: tests/knisper: Missing properties section

Where did you get that test-config.yaml layout or contents? Did you use another test as a base? It is very very very incomplete. Finding a test that most closely matches what you want to do, copying that, and adjusting is usually the wisest course of action.

you can optimize by reversing what you matches on

same => n,Set(GLOBAL(APP_KNISPER_ENABLE)=${IF($[${GLOBAL(APP_KNISPER_ENABLE)} = 1]?0:1)})
1 Like

This was generated by ChatGPT. I couldn’t find a suitable sample test that tested dial plans - can anyone suggest such ?

ChatGPT is designed to create plausible sounding responses, not necessarily correct ones.

In order for this dialplan to work, you have to use Background() instead of Read()

1 Like

There are tons of tests that execute dialplan to test things. There’s even a test for testing dialplan itself, located at tests/pbx/dialplan that sends a call into the dialplan using a Local channel and does stuff in the dialplan and verifies the result.

Thanks, why won’t Read work ? Btw, I assume you mean the first instance of Read, as there are two.

Read() sets the DTMF response as a variable and doesn’t do any further actions.
Background() sends the call to the extension received in the DTMF response.

https://wiki.asterisk.org/wiki/display/AST/Asterisk+20+Application_Read
https://wiki.asterisk.org/wiki/display/AST/Asterisk+20+Application_BackGround

Thanks, very much appreciated! Here is my updated plan, if you have time to take a look.

[main-menu]
exten => s,1,Answer()
same => n,Playback(welcome) ; Play a welcome message
same => n,Background(enter-option) ; Prompt the user to enter an option

; Toggle module enablement if user presses 1
exten => 1,1,Verbose(1,Toggle module enablement)
same => n,Set(APP_KNISPER_ENABLE=${IF($[${APP_KNISPER_ENABLE} = 1]?0:1)})
same => n,Goto(main-menu,s,1)

; Set AGE variable to 60 if user presses 2
exten => 2,1,Verbose(1,Set AGE to 60)
same => n,Set(APP_KNISPER_AGE=60)
same => n,Goto(main-menu,s,1)

; Set AGE variable to 70 if user presses 3
exten => 3,1,Verbose(1,Set AGE to 70)
same => n,Set(APP_KNISPER_AGE=70)
same => n,Goto(main-menu,s,1)

; Set AGE variable to 80 if user presses 4
exten => 4,1,Verbose(1,Set AGE to 80)
same => n,Set(APP_KNISPER_AGE=80)
same => n,Goto(main-menu,s,1)

; Set AGE variable to custom value (two digits) if user presses 5
exten => 5,1,Verbose(1,Enter custom AGE value)
same => n,Read(AGE,enter-age,2) ; Prompt the user to enter a custom age
same => n,n,Playback(you-entered)
same => n,n,SayNumber(${AGE})
same => n,Set(APP_KNISPER_AGE=${AGE})
same => n,Goto(main-menu,s,1)

; Hang up if user doesn't press 1, 2, 3, 4 or 5
exten => i,1,Hangup()
exten => t,1,Hangup()
exten => e,1,Hangup()

Besides ATS, is there a recommended soft phone to test dial plan and module ? I heard that baresip can be used.

is there default hold music I can play in my dial plan ?

I added this line to my dial plan

same => n,Set(CHANNEL(musicclass)=default) ; default hold music for now

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.