本文整理汇总了Python中flask_apscheduler.APScheduler.authenticate方法的典型用法代码示例。如果您正苦于以下问题:Python APScheduler.authenticate方法的具体用法?Python APScheduler.authenticate怎么用?Python APScheduler.authenticate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_apscheduler.APScheduler
的用法示例。
在下文中一共展示了APScheduler.authenticate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestHTTPBasicAuth
# 需要导入模块: from flask_apscheduler import APScheduler [as 别名]
# 或者: from flask_apscheduler.APScheduler import authenticate [as 别名]
class TestHTTPBasicAuth(TestCase):
def setUp(self):
self.app = Flask(__name__)
self.scheduler = APScheduler()
self.scheduler.auth = HTTPBasicAuth()
self.scheduler.api_enabled = True
self.scheduler.init_app(self.app)
self.scheduler.start()
self.scheduler.authenticate(self._authenticate)
self.client = self.app.test_client()
def _authenticate(self, auth):
return auth['username'] == 'test' and auth['password'] == 'test'
def test_valid_credentials(self):
headers = {'Authorization': 'Basic ' + base64.b64encode(b'test:test').decode('ascii')}
response = self.client.get(self.scheduler.api_prefix + '', headers=headers)
self.assertEqual(response.status_code, 200)
def test_invalid_credentials(self):
headers = {'Authorization': 'Basic ' + base64.b64encode(b'guest:guest').decode('ascii')}
response = self.client.get(self.scheduler.api_prefix + '', headers=headers)
self.assertEqual(response.status_code, 401)
self.assertEqual(response.headers['WWW-Authenticate'], 'Basic realm="Authentication Required"')
def test_invalid_header_format(self):
headers = {'Authorization': 'Basic 1231234'}
response = self.client.get(self.scheduler.api_prefix + '', headers=headers)
self.assertEqual(response.status_code, 401)
self.assertEqual(response.headers['WWW-Authenticate'], 'Basic realm="Authentication Required"')
def test_missing_credentials(self):
response = self.client.get(self.scheduler.api_prefix + '')
self.assertEqual(response.status_code, 401)
self.assertEqual(response.headers['WWW-Authenticate'], 'Basic realm="Authentication Required"')