def test_block_caller(): db_path = create_temp_telewall_db(overwrite=True) with Persistence(db_path) as p: result = p.block(TelephoneNumber('0311238899'), 'John', 'Unit-Test') assert_equals('+41311238899', result.telephone_number) assert_equals('John', result.comment) assert_equals('Unit-Test', result.source)
def test_load_from_ktipp_online(): db_path = create_temp_telewall_db(overwrite=True) importer = import_blacklist.ImportBlacklist(db_path) if run_online_tests: with Persistence(db_path) as p: assert_equals(0, len(p.get_all_blocked())) importer.load_from_ktipp() assert_equals(3170, len(p.get_all_blocked()))
def test_get_all_blocked(): db_path = create_temp_telewall_db(overwrite=True) with Persistence(db_path) as p: n1 = p.block(TelephoneNumber('0311112233'), 'John', 'Unit-Test') n2 = p.block(TelephoneNumber('0315555'), 'John', 'Unit-Test') all = p.get_all_blocked() assert_equals(2, len(all)) assert_equals(n2, all[0]) assert_equals(n1, all[1])
def test_import_local_csv(): db_path = create_temp_telewall_db(overwrite=True) importer = import_blacklist.ImportBlacklist(db_path) with Persistence(db_path) as p: assert_equals(0, len(p.get_all_blocked())) absolute_filename = os.path.join(os.path.dirname(__file__), "data", "blacklist_import_short.csv") importer.load_csv(absolute_filename, "ktipp") with Persistence(db_path) as p: assert_equals(13, len(p.get_all_blocked()))
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)
def test_unblock_caller(): db_path = create_temp_telewall_db(overwrite=True) with Persistence(db_path) as p: p.block(TelephoneNumber('0311112233'), 'John', 'Unit-Test') p.unblock(TelephoneNumber('0311112233')) assert_false(p.is_blocked(TelephoneNumber('0311112233')))
def test_is_blocked_invalid(): db_path = create_temp_telewall_db(overwrite=True) with Persistence(db_path) as p: p.is_blocked('0311112233') # should be number, not string