networking tests

This commit is contained in:
Abubakar Abid 2021-10-25 11:06:36 -05:00
parent 1e8cc4a333
commit bdf9c69353
2 changed files with 34 additions and 3 deletions

View File

@ -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":

View File

@ -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()