From ab852f3b07bada16d94df623ba0bc73e42089aad Mon Sep 17 00:00:00 2001 From: Andrei Calistru Date: Wed, 25 Jul 2018 10:03:24 +0100 Subject: [PATCH] added endpoint prefix tests --- tests/test_api.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/test_api.py b/tests/test_api.py index 4319dd6..87681a9 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1,7 +1,8 @@ import base64 import json -from flask import Flask +from werkzeug.routing import BuildError +from flask import Flask, url_for from flask_apscheduler import APScheduler from flask_apscheduler.auth import HTTPBasicAuth from unittest import TestCase @@ -217,6 +218,30 @@ def test_invalid_api_prefix(self): self.assertEqual(response.status_code, 404) +class TestEndpointPrefix(TestCase): + def setUp(self): + self.app = Flask(__name__) + self.scheduler = APScheduler() + self.scheduler.api_enabled = True + self.scheduler.endpoint_prefix = 'api.' + self.scheduler.init_app(self.app) + self.scheduler.start() + self.client = self.app.test_client() + + def test_endpoint_prefix(self): + with self.scheduler.app.test_request_context(): + valid_url = True if url_for(self.scheduler.endpoint_prefix + 'get_scheduler_info') else False + self.assertTrue(valid_url) + + def test_invalid_endpoint_prefix(self): + with self.scheduler.app.test_request_context(): + try: + valid_url = url_for('get_scheduler_info') + except BuildError as _: + valid_url = False + self.assertFalse(valid_url) + + class TestHTTPBasicAuth(TestCase): def setUp(self): self.app = Flask(__name__)