예제 #1
0
 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()
예제 #2
0
 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())
예제 #3
0
 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()
예제 #4
0
 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()))
예제 #5
0
 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()
예제 #6
0
 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()
예제 #7
0
 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()))
예제 #8
0
 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()))
예제 #9
0
 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())
예제 #10
0
 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()
예제 #11
0
 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())
예제 #12
0
    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()
예제 #13
0
    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)
예제 #14
0
    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()
예제 #15
0
    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)
예제 #16
0
 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()
예제 #17
0
    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()
예제 #18
0
    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()
예제 #19
0
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'
예제 #20
0
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"
예제 #21
0
 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')
예제 #22
0
    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()
예제 #23
0
파일: caller.py 프로젝트: hoefler02/callbot
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()
예제 #24
0
 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)
예제 #25
0
 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())
예제 #26
0
 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()))
예제 #27
0
 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)
예제 #28
0
 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())
예제 #29
0
 def test_attrs_default_filename(self):
     """Ensure default `filename` attribute works."""
     c = CallFile(self.call, self.action)
     ok_(c.filename)
예제 #30
0
 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())
예제 #31
0
 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__())
예제 #32
0
 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())
예제 #33
0
def call(number, time=None):
    c = Call('SIP/flowroute/%s' % number)
    a = Application('Playback', 'hello-world')
    cf = CallFile(c, a)
    cf.spool(time)
예제 #34
0
파일: test.py 프로젝트: fooyou/Exercise
#!/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()
예제 #35
0
 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())
예제 #36
0
 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()))
예제 #37
0
 def test_attrs_default_tempdir(self):
     """Ensure default `tempdir` attribute works."""
     c = CallFile(self.call, self.action)
     ok_(c.tempdir)
예제 #38
0
 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()))
예제 #39
0
 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())
예제 #40
0
 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())
예제 #41
0
 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())
예제 #42
0
 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__())
예제 #43
0
 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())
예제 #44
0
 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())
예제 #45
0
 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())
예제 #46
0
 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())
예제 #47
0
 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())
예제 #48
0
 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())
예제 #49
0
 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())
예제 #50
0
from pycall import CallFile, Call, Application

call = Call('SIP/flowroute/89257651079')
action = Application('Playback', 'hello-world')

c = CallFile(call, action)
c.spool()
예제 #51
0
 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())