DeployURL is not updated in AppHarness tests.
Describe the bug
rx.get_config().deploy_url always returns http://localhost:3000.
To Reproduce
Create an AppHarness test.
Expected behavior
rx.get_config().deploy_url returns the correct URL for the test environment.
Specifics (please complete the following information):
- Python Version: 3.12.2
- Reflex Version: 0.4.2
- OS: arch
Just for reference: AppHarness tests currently store the correct frontend url in the frontend_url attribute of the AppHarness class but do not update rx.config accordingly. It would be awesome to have one api (f.e. rx.get_config().deploy_url) which always returns the correct url.
I.e. these two tests fail.
"""Integration tests for deploy_url."""
from __future__ import annotations
from typing import Generator
from selenium.webdriver.common.by import By
import pytest
from selenium.webdriver.remote.webdriver import WebDriver
from selenium.webdriver.support.ui import WebDriverWait
from reflex.testing import AppHarness
def DeployUrlSample():
"""Sample app for testing config deploy_url is correct (in tests)."""
import reflex as rx
class State(rx.State):
def goto_self(self):
return rx.redirect(rx.config.get_config().deploy_url)
def index():
return rx.fragment(
rx.button("GOTO SELF", on_click=State.goto_self, id="goto_self")
)
app = rx.App(state=rx.State)
app.add_page(index)
@pytest.fixture(scope="module")
def deploy_url_sample(tmp_path_factory) -> Generator[AppHarness, None, None]:
with AppHarness.create(
root=tmp_path_factory.mktemp("deploy_url_sample"),
app_source=DeployUrlSample, # type: ignore
) as harness:
yield harness
@pytest.fixture()
def driver(deploy_url_sample: AppHarness) -> Generator[WebDriver, None, None]:
assert deploy_url_sample.app_instance is not None, "app is not running"
driver = deploy_url_sample.frontend()
try:
yield driver
finally:
driver.quit()
def test_deploy_url(deploy_url_sample: AppHarness, driver: WebDriver):
import reflex as rx
assert rx.config.get_config().deploy_url != "http://localhost:3000"
assert rx.config.get_config().deploy_url == deploy_url_sample.frontend_url
driver.get(rx.config.get_config().deploy_url)
assert driver.current_url == rx.config.get_config().deploy_url
def test_deploy_url_in_app(deploy_url_sample: AppHarness, driver: WebDriver):
driver.implicitly_wait(10)
driver.find_element(By.ID, "goto_self").click()
WebDriverWait(driver, 10).until(
lambda driver: driver.current_url == deploy_url_sample.frontend_url
)
Nobody wants to do a red2green :adhesive_bandage: with given tests? What's up :smiley_cat: ? It's like a task from advent of code.
https://github.com/reflex-dev/reflex/pull/3359