def test_spool_no_time_no_user_permission_error(self): """Ensure that `spool` raises `NoUserPermissionError` if the user specified does not have permissions to write to the Asterisk spooling directory. """ c = CallFile(self.call, self.action, spool_dir='/', user='******') c.spool()
def test_writefile_creates_file(self): """Ensure that `writefile` actually generates a call file on the disk. """ c = CallFile(self.call, self.action, spool_dir=self.spool_dir) c.writefile() self.assertTrue( (path(c.tempdir) / path(c.filename)).abspath().exists())
def test_spool_no_time_user(self): """Ensure that `spool` works when no `time` attribute is specified, and a valid `user` attribute exists. """ c = CallFile(self.call, self.action, spool_dir=self.spool_dir, user=getuser()) c.spool()
def test_buildfile_valid_archive(self): """Ensure that `buildfile` works with a well-formed `archive` attribute. """ c = CallFile(self.call, self.action, archive=True, spool_dir=self.spool_dir) self.assertTrue('Archive: yes' in ''.join(c.buildfile()))
def test_spool_no_time_no_user_error(self): """Ensure that `spool` raises `NoUserError` if the user attribute is not a real system user. """ c = CallFile(self.call, self.action, spool_dir=self.spool_dir, user='******') c.spool()
def test_buildfile_valid_archive(self): """Ensure that `buildfile` works with a well-formed `archive` attribute. """ c = CallFile(self.call, self.action, archive=True, spool_dir=self.spool_dir) ok_('Archive: yes' in ''.join(c.buildfile()))
def test_spool_time_no_user(self): """Ensure that `spool` works when given a valid `time` parameter.""" c = CallFile(self.call, self.action, spool_dir=self.spool_dir) d = datetime.now() c.spool(d) eq_((path(c.tempdir) / path(c.filename)).abspath().atime, mktime(d.timetuple()))
def test_spool_no_time_no_user(self): """Ensure `spool` works when no `time` attribute is supplied, and no `user` attribute exists. """ c = CallFile(self.call, self.action, spool_dir=self.spool_dir) c.spool() ok_((path(c.spool_dir) / path(c.filename)).abspath().exists())
def test_buildfile_raises_validation_error(self): """Ensure `buildfile` raises `ValidationError` if the `CallFile` can't be validated. """ cf = CallFile(self.call, self.action, spool_dir='/woot') with self.assertRaises(ValidationError): cf.buildfile()
def test_spool_time_no_user_invalid_time_error(self): """Ensure that `spool` raises `InvalidTimeError` if the user doesn't specify a valid `time` parameter. """ c = CallFile(self.call, self.action, spool_dir=self.spool_dir) with self.assertRaises(InvalidTimeError): c.spool(666)
def test_spool_no_time_no_spool_permission_error(self): """Ensure that `spool` raises `NoSpoolPermissionError` if the user doesn't have permissions to write to `spool_dir`. NOTE: This test WILL fail if the user account you run this test under has write access to the / directory on your local filesystem. """ c = CallFile(self.call, self.action, spool_dir='/') c.spool()
def dialout(): call_from = request.args.get('from', '') call_to = request.args.get('to', '') cfrom = 'SIP/{}@hotvoip'.format(call_from) cto = 'SIP/{}@hotvoip'.format(call_to) c = Call(cfrom) a = Application('Dial', cto) cf = CallFile(c, a) cf.spool() return 'dialed'
def localcall(): call_from = request.args.get('from', '') call_to = request.args.get('to', '') if call_from and call_to: cfrom = 'SIP/{}'.format(call_from) logging.debug(cfrom) cto = 'SIP/{}'.format(call_to) logging.debug(cto) c = Call(cfrom) a = Application('Dial', cto) cf = CallFile(c, a) cf.spool() else: return "no call made" return "call made"
def test_attrs_stick(self): """Ensure attributes stick.""" c = CallFile('call', 'action', 'archive', 'filename', 'tempdir', 'user', 'spool_dir') eq_(c.call, 'call') eq_(c.action, 'action') eq_(c.archive, 'archive') eq_(c.filename, 'filename') eq_(c.tempdir, 'tempdir') eq_(c.user, 'user') eq_(c.spool_dir, 'spool_dir')
def send_command(self, action: str, access_code: str) -> None: """ Send control sequence via Asterisk call file """ call = Call(f"SIP/{self.extension}", wait_time=self.wait_time, retry_time=self.retry_time, max_retries=self.max_retries) seq = self._build_dtmf_sequence(action, access_code) logger.debug("Sending action '%s' (DTMF: '%s') to alarm", action, seq) action = Application("SendDTMF", seq) callfile_args = {"archive": True, "spool_dir": self.spool_dir} if self.asterisk_user: callfile_args["user"] = self.asterisk_user c = CallFile(call, action, **callfile_args) c.spool()
def call(target, callid, sound): CallFile( Call('SIP/flowroute/{}'.format(target), callerid=callid), Application( 'Playback', sound # supports many different types of audio files ), user= '******' # assuming asterisk is running as its own user (recommended) ).spool()
def test_contents(self): """Ensure that the `contents` property works.""" c = CallFile(self.call, self.action, spool_dir=self.spool_dir) ok_('channel' in c.contents and 'application' in c.contents and 'data' in c.contents)
def test_writefile_creates_file(self): """Ensure that `writefile` actually generates a call file on the disk. """ c = CallFile(self.call, self.action, spool_dir=self.spool_dir) c.writefile() ok_((path(c.tempdir) / path(c.filename)).abspath().exists())
def test_buildfile_invalid_archive(self): """Ensure `buildfile` works when `archive` is false.""" c = CallFile(self.call, self.action, spool_dir=self.spool_dir) assert_false('Archive:' in ''.join(c.buildfile()))
def test_attrs_default_spool_dir(self): """Ensure default `spool_dir` attribute works.""" c = CallFile(self.call, self.action) eq_(c.spool_dir, CallFile.DEFAULT_SPOOL_DIR)
def test_is_valid_valid_action(self): """Ensure `is_valid` works using a valid `action` attribute.""" c = CallFile(self.call, self.action, spool_dir=self.spool_dir) self.assertTrue(c.is_valid())
def test_attrs_default_filename(self): """Ensure default `filename` attribute works.""" c = CallFile(self.call, self.action) ok_(c.filename)
def test_is_valid_invalid_spool_dir(self): """Ensure `is_valid` fails given an invalid `spool_dir` attribute.""" c = CallFile(self.call, self.action, spool_dir='/woot') assert_false(c.is_valid())
def test_str(self): """Ensure `__str__` works.""" c = CallFile(self.call, self.action, spool_dir=self.spool_dir) ok_('archive' in c.__str__() and 'user' in c.__str__() and 'spool_dir' in c.__str__())
def test_is_valid_valid_spool_dir(self): """Ensure `is_valid` works using a valid `spool_dir` attribute.""" c = CallFile(self.call, self.action, spool_dir=self.spool_dir) ok_(c.is_valid())
def call(number, time=None): c = Call('SIP/flowroute/%s' % number) a = Application('Playback', 'hello-world') cf = CallFile(c, a) cf.spool(time)
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author: Joshua # @E-Mail: [email protected] # @Date: 2015-04-29 17:52:36 # @About test.py from pycall import CallFile, Call, Application call = Call('SIP/flowroute/13694182569') action = Application('Playback', 'hello-world') c = CallFile(call, action) c.spool()
def test_buildfile_is_valid(self): """Ensure `buildfile` works with well-formed attributes.""" c = CallFile(self.call, self.action, spool_dir=self.spool_dir) ok_(c.buildfile())
def test_attrs_default_tempdir(self): """Ensure default `tempdir` attribute works.""" c = CallFile(self.call, self.action) ok_(c.tempdir)
def test_is_valid_invalid_call(self): """Ensure `is_valid` fails given an invalid `call` attribute.""" c = CallFile('call', self.action, spool_dir=self.spool_dir) assert_false(c.is_valid())
def test_is_valid_valid_call_is_valid(self): """Ensure `is_valid` works when `call.is_valid()` works.""" c = CallFile(self.call, self.action, spool_dir=self.spool_dir) ok_(c.is_valid())
def test_is_valid_invalid_action(self): """Ensure `is_valid` fails given an invalid `action` attribute.""" c = CallFile(self.call, 'action', spool_dir=self.spool_dir) assert_false(c.is_valid())
def test_is_valid_invalid_call_is_valid(self): """Ensure `is_valid` fails when `call.is_valid()` fails.""" c = CallFile(Call('channel', wait_time='10'), self.action, spool_dir=self.spool_dir) assert_false(c.is_valid())
from pycall import CallFile, Call, Application call = Call('SIP/flowroute/89257651079') action = Application('Playback', 'hello-world') c = CallFile(call, action) c.spool()