mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-24 10:54:04 +08:00
947d615db6
* first draft * debug * add print * working oauth * inject OAuth profile + enable OAuth when expected + some doc * add changeset * mypy * opt * open in a new tab only from iframe * msg * add changeset * Apply suggestions from code review Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * fix injection + gr.Error * allow third party cookie when possible * add button to sign in/sign out button * feedback changes * oauth as optional dependency * disable login/logout buttons locally * nothing * a bit of documentation * Add tests for Login/Logout buttons * Apply suggestions from code review Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * mention required dependencies * fix package * fix tests * fix windows tests as well * Fake profile on local debug * doc * fix tets * lint * fix test * test buttons * login button fix * lint * fix final tests --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com> Co-authored-by: Abubakar Abid <abubakar@huggingface.co> Co-authored-by: Hannah <hannahblair@users.noreply.github.com>
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
from unittest.mock import patch
|
|
|
|
import pytest
|
|
|
|
import gradio as gr
|
|
|
|
|
|
class TestClearButton:
|
|
def test_clear_event_setup_correctly(self):
|
|
with gr.Blocks() as demo:
|
|
chatbot = gr.Chatbot([("Hello", "How are you?")])
|
|
with gr.Row():
|
|
textbox = gr.Textbox(scale=3, interactive=True)
|
|
gr.ClearButton([textbox, chatbot], scale=1)
|
|
|
|
clear_event_trigger = demo.dependencies.pop()
|
|
assert not clear_event_trigger["backend_fn"]
|
|
assert clear_event_trigger["js"]
|
|
assert clear_event_trigger["outputs"] == [textbox._id, chatbot._id]
|
|
|
|
|
|
class TestOAuthButtons:
|
|
def test_login_button_warns_when_not_on_spaces(self):
|
|
with pytest.warns(UserWarning):
|
|
with gr.Blocks():
|
|
gr.LoginButton()
|
|
|
|
def test_logout_button_warns_when_not_on_spaces(self):
|
|
with pytest.warns(UserWarning):
|
|
with gr.Blocks():
|
|
gr.LogoutButton()
|
|
|
|
@patch("gradio.oauth.get_space", lambda: "fake_space")
|
|
@patch("gradio.oauth._add_oauth_routes")
|
|
def test_login_button_setup_correctly(self, mock_add_oauth_routes):
|
|
with gr.Blocks() as demo:
|
|
button = gr.LoginButton()
|
|
|
|
login_event = demo.dependencies[0]
|
|
assert login_event["trigger"] == "click"
|
|
assert not login_event["backend_fn"] # No Python code
|
|
assert login_event["js"] # But JS code instead
|
|
assert login_event["inputs"] == [button._id]
|
|
assert login_event["outputs"] == []
|