diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml new file mode 100644 index 0000000..9687c82 --- /dev/null +++ b/.github/workflows/push.yaml @@ -0,0 +1,29 @@ +name: Push Workflow + +on: push + +jobs: + run_tests: + name: Run Tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Requirements + run: pip install -r door_ivr/requirements.txt + - name: Run tests + working-directory: door_ivr/tests/ + timeout-minutes: 1 + run: > + python backend_mock.py & + sleep 1 && + echo "=== TEST RUN NORMAL ===" && + ./run-test.sh agi-test.txt 2>&1 | tee agi-test-result.txt && + echo "=== TEST UNKNOWN NUMBER ===" && + ./run-test.sh agi-unknown-number.txt 2>&1 | tee agi-test-unknown-number-result.txt + - name: Compare results + working-directory: door_ivr/tests/ + run: > + echo "=== COMPARE RUN NORMAL ===" && + diff -U 3 agi-test-expected.txt agi-test-result.txt && + echo "=== COMPARE UNKNOWN NUMBER ===" && + diff -U 3 agi-test-unknown-number-expected.txt agi-test-unknown-number-result.txt diff --git a/README.md b/README.md index dc564be..bdeeb72 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ service asterisk restart ## Testing ``` -cd door_ivr/door_ivr/ +cd door_ivr/tests/ python backend_mock.py & ./run-test.sh agi-test.txt ./run-test.sh agi-unknown-number.txt diff --git a/door_ivr/tests/agi-test-expected.txt b/door_ivr/tests/agi-test-expected.txt new file mode 100644 index 0000000..800ab36 --- /dev/null +++ b/door_ivr/tests/agi-test-expected.txt @@ -0,0 +1,96 @@ +ARGS: ['../door_ivr.py', '--handler=external', '--config=../door_ivr.test.conf'] +ENV LINE: agi_callerid: 0881234567 +ENV LINE: +class AGI: self.env = {'agi_callerid': '0881234567'} + COMMAND: VERBOSE "External phone door IVR received a call from '0881234567'" 1 +VERBOSE "External phone door IVR received a call from '0881234567'" 1 + RESULT_LINE: 200 result=1 + RESULT_DICT: {'result': ('1', '')} + COMMAND: ANSWER +ANSWER + RESULT_LINE: 200 result=0 + RESULT_DICT: {'result': ('0', '')} + COMMAND: STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/welcome "0123456789" 0 +STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/welcome "0123456789" 0 + RESULT_LINE: 200 result=0 + RESULT_DICT: {'result': ('0', '')} + COMMAND: STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/enter_pin "0123456789" 0 +STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/enter_pin "0123456789" 0 + RESULT_LINE: 200 result=0 + RESULT_DICT: {'result': ('0', '')} + COMMAND: WAIT FOR DIGIT 12000 +WAIT FOR DIGIT 12000 + RESULT_LINE: 200 result=49 + RESULT_DICT: {'result': ('49', '')} + COMMAND: WAIT FOR DIGIT 4000 +WAIT FOR DIGIT 4000 + RESULT_LINE: 200 result=50 + RESULT_DICT: {'result': ('50', '')} + COMMAND: WAIT FOR DIGIT 4000 +WAIT FOR DIGIT 4000 + RESULT_LINE: 200 result=51 + RESULT_DICT: {'result': ('51', '')} + COMMAND: WAIT FOR DIGIT 4000 +WAIT FOR DIGIT 4000 + RESULT_LINE: 200 result=52 + RESULT_DICT: {'result': ('52', '')} + COMMAND: WAIT FOR DIGIT 4000 +WAIT FOR DIGIT 4000 + RESULT_LINE: 200 result=53 + RESULT_DICT: {'result': ('53', '')} + COMMAND: WAIT FOR DIGIT 4000 +WAIT FOR DIGIT 4000 + RESULT_LINE: 200 result=54 + RESULT_DICT: {'result': ('54', '')} + COMMAND: WAIT FOR DIGIT 4000 +WAIT FOR DIGIT 4000 + RESULT_LINE: 200 result=35 + RESULT_DICT: {'result': ('35', '')} + COMMAND: STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/door_prompt_1 "1239" 0 +STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/door_prompt_1 "1239" 0 + RESULT_LINE: 200 result=49 + RESULT_DICT: {'result': ('49', '')} + COMMAND: STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/door_opened_1 "" 0 +STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/door_opened_1 "" 0 + RESULT_LINE: 200 result=0 + RESULT_DICT: {'result': ('0', '')} + COMMAND: STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/door_prompt_1 "1239" 0 +STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/door_prompt_1 "1239" 0 + RESULT_LINE: 200 result=0 + RESULT_DICT: {'result': ('0', '')} + COMMAND: STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/door_prompt_2 "1239" 0 +STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/door_prompt_2 "1239" 0 + RESULT_LINE: 200 result=0 + RESULT_DICT: {'result': ('0', '')} + COMMAND: STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/door_prompt_3 "1239" 0 +STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/door_prompt_3 "1239" 0 + RESULT_LINE: 200 result=50 + RESULT_DICT: {'result': ('50', '')} + COMMAND: STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/door_opened_2 "" 0 +STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/door_opened_2 "" 0 + RESULT_LINE: 200 result=0 + RESULT_DICT: {'result': ('0', '')} + COMMAND: STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/door_prompt_1 "1239" 0 +STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/door_prompt_1 "1239" 0 + RESULT_LINE: 200 result=0 + RESULT_DICT: {'result': ('0', '')} + COMMAND: STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/door_prompt_2 "1239" 0 +STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/door_prompt_2 "1239" 0 + RESULT_LINE: 200 result=0 + RESULT_DICT: {'result': ('0', '')} + COMMAND: STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/door_prompt_3 "1239" 0 +STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/door_prompt_3 "1239" 0 + RESULT_LINE: 200 result=57 + RESULT_DICT: {'result': ('57', '')} + COMMAND: STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/door_locked "" 0 +STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/door_locked "" 0 + RESULT_LINE: 200 result=0 + RESULT_DICT: {'result': ('0', '')} + COMMAND: STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/goodbye "" 0 +STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/goodbye "" 0 + RESULT_LINE: 200 result=0 + RESULT_DICT: {'result': ('0', '')} + COMMAND: HANGUP +HANGUP + RESULT_LINE: 200 + RESULT_DICT: {'result': ('', '')} diff --git a/door_ivr/tests/agi-test-unknown-number-expected.txt b/door_ivr/tests/agi-test-unknown-number-expected.txt new file mode 100644 index 0000000..89723a2 --- /dev/null +++ b/door_ivr/tests/agi-test-unknown-number-expected.txt @@ -0,0 +1,32 @@ +ARGS: ['../door_ivr.py', '--handler=external', '--config=../door_ivr.test.conf'] +ENV LINE: agi_callerid: +359880000000 +ENV LINE: +class AGI: self.env = {'agi_callerid': '+359880000000'} + COMMAND: VERBOSE "External phone door IVR received a call from '+359880000000'" 1 +VERBOSE "External phone door IVR received a call from '+359880000000'" 1 + RESULT_LINE: 200 + RESULT_DICT: {'result': ('', '')} + COMMAND: GET VARIABLE "FALLBACK_EXTENSION" +GET VARIABLE "FALLBACK_EXTENSION" + RESULT_LINE: 200 + RESULT_DICT: {'result': ('', '')} + COMMAND: ANSWER +ANSWER + RESULT_LINE: 200 + RESULT_DICT: {'result': ('', '')} + COMMAND: STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/welcome "" 0 +STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/welcome "" 0 + RESULT_LINE: 200 result=101 + RESULT_DICT: {'result': ('101', '')} + COMMAND: STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/redirecting_to_public_phone "" 0 +STREAM FILE /home/runner/work/initlab-telephony/initlab-telephony/door_ivr/tests/initlab-telephony-assets/files/bg/redirecting_to_public_phone "" 0 + RESULT_LINE: 200 result=0 + RESULT_DICT: {'result': ('0', '')} + COMMAND: SET EXTENSION 1234 +SET EXTENSION 1234 + RESULT_LINE: 200 + RESULT_DICT: {'result': ('', '')} + COMMAND: set priority 1 +set priority 1 + RESULT_LINE: 200 + RESULT_DICT: {'result': ('', '')} diff --git a/door_ivr/tests/backend_mock.py b/door_ivr/tests/backend_mock.py index 258ca75..c59ed63 100644 --- a/door_ivr/tests/backend_mock.py +++ b/door_ivr/tests/backend_mock.py @@ -17,6 +17,10 @@ class FaunaHandler(http.server.BaseHTTPRequestHandler): + def setup(self): + self.server.allow_reuse_address = True + super().setup() + def do_GET(self): if self.path == '/api/doors': self.send_response(http.HTTPStatus.OK)