Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeployURL is not updated in AppHarness tests. #2772

Closed
abulvenz opened this issue Mar 4, 2024 · 4 comments · Fixed by #3359
Closed

DeployURL is not updated in AppHarness tests. #2772

abulvenz opened this issue Mar 4, 2024 · 4 comments · Fixed by #3359
Labels
bug Something isn't working needs investigation

Comments

@abulvenz
Copy link
Contributor

abulvenz commented Mar 4, 2024

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
@Alek99 Alek99 added bug Something isn't working needs investigation labels Mar 6, 2024
@benedikt-bartscher
Copy link
Contributor

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.

@abulvenz
Copy link
Contributor Author

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
    )

@abulvenz
Copy link
Contributor Author

Nobody wants to do a red2green 🩹 with given tests? What's up 😺 ? It's like a task from advent of code.

@benedikt-bartscher
Copy link
Contributor

#3359

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs investigation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants