def test_web_validate(self): """ Make sure that you are under Tenzor's Wi-Fi. """ d = Doorman() self.assertEqual(d.web_validate_people('Stranger'), False) return
def test_write_log(self): d = Doorman() d.main_validate('Someone not in cache') self.assertEqual(d.validating_log_id, 1) self.assertEqual(d.redis_server.exists(Doorman.LOG_LIST_NAME), True) print 'This is the log:' print d.redis_server.lindex(Doorman.LOG_LIST_NAME, 0) return
def test_redis_expire(self): """ Wait patiently... """ import time t = Doorman.WELCOMED_EXPIRE Doorman.WELCOMED_EXPIRE = 5 d = Doorman() d.redis_add_welcomed_people('China') time.sleep(2) self.assertEqual(d.redis_check_people('China'), True) d.redis_add_welcomed_people('America') time.sleep(4) self.assertEqual(d.redis_check_people('China'), None) self.assertEqual(d.redis_check_people('America'), True) Doorman.WELCOMED_EXPIRE = t return
def main(): """ Main function """ if args.verbose: logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO) else: logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.WARN) if not is_default_config(): try: doorman = Doorman(args.status, os.path.abspath(args.config_file)) doorman.run() except DoormanException, e: logging.error(e) parser.print_help()
def test_redis(self): """ Before this test it is necessary to start redis server: $ redis-server And after: $ redis-cli 127.0.0.1:6379> flushdb OK 127.0.0.1:6379> shutdown 127.0.0.1:6379> quit """ d = Doorman() d.redis_add_welcomed_people('Apple') d.redis_add_forbidden_people('Microsoft') self.assertEqual(d.redis_check_people('Apple'), True) self.assertEqual(d.redis_check_people('Microsoft'), False) self.assertEqual(d.redis_check_people('IBM'), None) return