diff --git a/README.md b/README.md index c89dbc4..4a00441 100644 --- a/README.md +++ b/README.md @@ -22,3 +22,19 @@ Run the tool using poetry: ```bash poetry run autometabuilder ``` + +## Testing + +To run the unit tests: +```bash +PYTHONPATH=src pytest tests/test_main.py tests/test_metadata.py tests/test_roadmap.py +``` + +To run the Web UI tests (Playwright): +```bash +# First install browsers if you haven't already +playwright install chromium + +# Run the UI tests +PYTHONPATH=src pytest tests/ui +``` diff --git a/prompt.yml b/prompt.yml index c970ea3..c4545eb 100644 --- a/prompt.yml +++ b/prompt.yml @@ -21,3 +21,7 @@ messages: listing upcoming work. Ensure all changes are tested, linted, and properly documented. Update ROADMAP.md as you complete tasks. model: openai/gpt-4o + +# Test Comment +# Test Comment +# Test Comment \ No newline at end of file diff --git a/src/autometabuilder/web/server.py b/src/autometabuilder/web/server.py index 3241b38..d7b2d66 100644 --- a/src/autometabuilder/web/server.py +++ b/src/autometabuilder/web/server.py @@ -73,8 +73,12 @@ def get_env_vars(): env_vars = {} for line in lines: + line = line.strip() if "=" in line and not line.startswith("#"): - key, value = line.strip().split("=", 1) + key, value = line.split("=", 1) + # Remove quotes if present + if (value.startswith("'") and value.endswith("'")) or (value.startswith('"') and value.endswith('"')): + value = value[1:-1] env_vars[key] = value return env_vars diff --git a/tests/ui/conftest.py b/tests/ui/conftest.py new file mode 100644 index 0000000..4493601 --- /dev/null +++ b/tests/ui/conftest.py @@ -0,0 +1,21 @@ +import os +import time +import multiprocessing +import pytest +import uvicorn +from autometabuilder.web.server import app + +def run_server(): + os.environ["MOCK_WEB_UI"] = "true" + os.environ["WEB_USER"] = "testuser" + os.environ["WEB_PASSWORD"] = "testpass" + uvicorn.run(app, host="127.0.0.1", port=8001, log_level="error") + +@pytest.fixture(scope="session") +def server(): + proc = multiprocessing.Process(target=run_server, daemon=True) + proc.start() + # Give the server a moment to start + time.sleep(2) + yield "http://127.0.0.1:8001" + proc.terminate() diff --git a/tests/ui/test_web_ui.py b/tests/ui/test_web_ui.py new file mode 100644 index 0000000..4a1e237 --- /dev/null +++ b/tests/ui/test_web_ui.py @@ -0,0 +1,67 @@ +import pytest +from playwright.sync_api import Page, expect + +def test_login_and_dashboard(page: Page, server: str): + # Go to the server + page.goto(server) + + # We should be prompted for basic auth + # Playwright handles basic auth via context or by encoding it in the URL + # or we can use the page.authenticate method + + # Alternative: use URL with credentials + auth_url = server.replace("http://", "http://testuser:testpass@") + page.goto(auth_url) + + # Check if we are on the dashboard + expect(page.locator("h1")).to_contain_text("AutoMetabuilder Dashboard") + expect(page.locator("text=Logged in as: testuser")).to_be_visible() + +def test_run_bot_mock(page: Page, server: str): + auth_url = server.replace("http://", "http://testuser:testpass@") + page.goto(auth_url) + + # Click run button + page.click("button:has-text('Run Bot')") + + # Status should change to "Bot Running..." + expect(page.locator(".badge.bg-warning")).to_contain_text("Bot Running") + + # Wait for it to finish (mock takes 5 seconds) + page.wait_for_timeout(6000) + + # Refresh + page.reload() + expect(page.locator(".badge.bg-success")).to_contain_text("Idle") + +def test_update_prompt(page: Page, server: str): + auth_url = server.replace("http://", "http://testuser:testpass@") + page.goto(auth_url) + + # Find prompt textarea + textarea = page.locator("textarea[name='content']").first + original_content = textarea.input_value() + + new_content = original_content + "\n# Test Comment" + textarea.fill(new_content) + + # Click update prompt + page.click("button:has-text('Save Prompt')") + + # Verify it updated + page.reload() + expect(page.locator("textarea[name='content']").first).to_have_value(new_content) + +def test_update_settings(page: Page, server: str): + auth_url = server.replace("http://", "http://testuser:testpass@") + page.goto(auth_url) + + # Add a new setting + page.fill("input[name='new_env_key']", "TEST_SETTING") + page.fill("input[name='new_env_value']", "test_value") + + page.click("button:has-text('Save Settings')") + + # Verify it appeared in the table + page.reload() + expect(page.locator("input[name='env_TEST_SETTING']")).to_have_value("test_value")