Пример #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
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
#!/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())