mirror of
https://github.com/gradio-app/gradio.git
synced 2025-02-23 11:39:17 +08:00
networking tests
This commit is contained in:
parent
1e8cc4a333
commit
bdf9c69353
@ -140,6 +140,7 @@ def static_resource(path):
|
||||
return send_file(os.path.join(STATIC_PATH_LIB, path))
|
||||
|
||||
|
||||
# TODO(@aliabid94): this throws a 500 error if app.auth is None (should probalbly just redirect to '/')
|
||||
@app.route('/login', methods=["GET", "POST"])
|
||||
def login():
|
||||
if request.method == "GET":
|
||||
|
@ -50,20 +50,50 @@ class TestPort(unittest.TestCase):
|
||||
except OSError:
|
||||
warnings.warn("Unable to test, no ports available")
|
||||
|
||||
|
||||
class TestFlaskRoutes(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.io =gr.Interface(lambda x: x, "text", "text")
|
||||
self.io = gr.Interface(lambda x: x, "text", "text")
|
||||
self.app, _, _ = self.io.launch(prevent_thread_lock=True)
|
||||
self.client = self.app.test_client()
|
||||
|
||||
def test_get_routes(self):
|
||||
def test_get_main_route(self):
|
||||
response = self.client.get('/')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
response = self.client.get('/')
|
||||
|
||||
def test_get_config_route(self):
|
||||
response = self.client.get('/config/')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_get_static_route(self):
|
||||
response = self.client.get('/static/bundle.css')
|
||||
self.assertEqual(response.status_code, 302) # This should redirect to static files.
|
||||
|
||||
def tearDown(self) -> None:
|
||||
self.io.close()
|
||||
gr.reset_all()
|
||||
|
||||
|
||||
class TestAuthenticatedFlaskRoutes(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.io = gr.Interface(lambda x: x, "text", "text")
|
||||
self.app, _, _ = self.io.launch(auth=("test", "correct_password"), prevent_thread_lock=True)
|
||||
self.client = self.app.test_client()
|
||||
|
||||
def test_get_login_route(self):
|
||||
response = self.client.get('/login')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_post_login(self):
|
||||
response = self.client.post('/login', data=dict(username="test", password="correct_password"))
|
||||
self.assertEqual(response.status_code, 302)
|
||||
response = self.client.post('/login', data=dict(username="test", password="incorrect_password"))
|
||||
self.assertEqual(response.status_code, 401)
|
||||
|
||||
def tearDown(self) -> None:
|
||||
self.io.close()
|
||||
gr.reset_all()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user