def test_cleanup_old_call_records():
    asterisk_db = create_temp_asterisk_db(sample_data=False, overwrite=True)

    with AsteriskPersistence(asterisk_db, print_sql=False) as p:
        Config.CALL_HISTORY_KEEP_DAYS = 10
        time_ok = datetime.now() - timedelta(days=9)
        time_old = datetime.now() - timedelta(days=10, hours=2)

        record_ok = CallRecord(src='0999999', start=time_ok, end=time_ok, dcontext='incoming',
                               clid='123', channel='123', dstchannel='123', lastapp='123', lastdata='123',
                               duration='123',
                               billsec='123', disposition='123', blocked='123')
        record_old = CallRecord(src='012345', start=time_old, end=time_old, dcontext='incoming',
                                clid='123', channel='123', dstchannel='123', lastapp='123', lastdata='123',
                                duration='123',
                                billsec='123', disposition='123', blocked='123')

        p.persist(record_ok)
        p.persist(record_old)

        assert_equals(p.get_call_history_count(), 2)

        p.delete_old_call_records()
        assert_equals(p.get_call_history_count(), 1)

        list = p.get_call_history()
        assert_equals(list[0].src, '0999999')
def test_get_last_caller():
    asterisk_db = create_temp_asterisk_db(sample_data=True, overwrite=True)
    with AsteriskPersistence(asterisk_db, print_sql=True) as p:
        now = datetime.now()
        anruf = CallRecord(src='0311112233', start=now, end=now, dcontext='incoming',
                           clid='123', channel='123', dstchannel='123', lastapp='123', lastdata='123', duration='123',
                           billsec='123', disposition='123', blocked='123')
        p.persist(anruf)

        result = p.get_last_cdr_callerid()
        assert_is_not_none(result)
        assert_equals('0311112233', result.src)
def test_init_testdb_with_samples():
    asterisk_db = create_temp_asterisk_db(sample_data=True, overwrite=True)
    with AsteriskPersistence(asterisk_db, print_sql=False) as p:
        result = p.get_call_history()
        assert_is_not_none(result)
        assert len(result) >= 0
Exemple #4
0
            p.block(phone_number, comment, source)
            flash("Der Anrufer %s wurde gesperrt." % telephone_number, "success")
        else:
            flash("Der Anrufer %s ist bereits gesperrt." % telephone_number, "success")


# used for session and cookie handling, should be changed in production.
app.secret_key = "\xf7\xe3\xe1\xa7o\x91\x1fZ'\xf0\xbf\x7fY\xb8\xa0\xd4\xe6\x9bC1\xdf/\xa6\x10"


def url_for_other_page(page):
    """ url helper function for pagination.

    taken from http://flask.pocoo.org/snippets/44/, see documentation there
    :param page: page number
    :return: url for the given page number
    """
    args = request.view_args.copy()
    args["page"] = page
    return url_for(request.endpoint, **args)


app.jinja_env.globals["url_for_other_page"] = url_for_other_page

if __name__ == "__main__":
    # when executing the module directly, a temporary database is created.
    app.config["TELEWALL_DATABASE_PATH"] = create_temp_telewall_db(sample_data=True, overwrite=False)
    app.config["ASTERISK_DATABASE_PATH"] = create_temp_asterisk_db(sample_data=True, overwrite=False)
    app.debug = True
    app.run(host="127.0.0.1", port=9090)