Skip to content

Commit

Permalink
Add setup for tasks card
Browse files Browse the repository at this point in the history
  • Loading branch information
uittenbroekrobbert committed Jun 3, 2024
1 parent 5507b2c commit 4f2a83e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 16 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pytest-playwright = "^0.5.0"
pytest = "^8.2.1"
coverage = "^7.5.3"
httpx = "^0.27.0"
urllib3 = "^2.2.1"

[tool.poetry.group.dev.dependencies]
ruff = "^0.4.7"
Expand Down
8 changes: 7 additions & 1 deletion tad/api/routes/root.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from fastapi import APIRouter, Request
from fastapi.responses import HTMLResponse
from fastapi.responses import FileResponse, HTMLResponse

from tad.core.config import settings
from tad.repositories.deps import templates

router = APIRouter()
Expand All @@ -9,3 +10,8 @@
@router.get("/")
async def base(request: Request) -> HTMLResponse:
return templates.TemplateResponse(request=request, name="root/index.html")


@router.get("/favicon.ico", include_in_schema=False)
async def favicon():
return FileResponse(settings.STATIC_DIR + "/favicon.ico")
6 changes: 3 additions & 3 deletions tad/site/templates/root/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}{% endblock %}</title>

<link rel="stylesheet" href="{{ url_for('static', path='/css/styles.css') }}">
<link rel="stylesheet" href="{{ url_for('static', path='/css/layout.css') }}">
<link rel="icon" type="image/x-icon" href="{{ url_for('static', path='/favicon.ico') }}">

<script src="{{ url_for('static', path='/vendor/htmx/1.9.12.min.js') }}"></script>
<script src="{{ url_for('static', path='/js/main.js') }}"></script>
<script src="{{ url_for('static', path='/vendor/htmx/js/1.9.12.min.js') }}"></script>
<script src="{{ url_for('static', path='/js/tad.js') }}"></script>

{% block head %}{% endblock %}

Expand Down
23 changes: 16 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os
import urllib
from collections.abc import Generator
from multiprocessing import Process
from time import sleep
from typing import Any
from urllib.error import URLError

import pytest
import uvicorn
Expand All @@ -21,16 +23,23 @@ class TestSettings:
HTTP_SERVER_SCHEME: str = "http://"
HTTP_SERVER_HOST: str = "127.0.0.1"
HTTP_SERVER_PORT: int = 8000
TIME_OUT: int = 10


def run_server() -> None:
uvicorn.run(app, host=TestSettings.HTTP_SERVER_HOST, port=TestSettings.HTTP_SERVER_PORT)


def wait_for_server_ready(url: str, timeout: int = 30) -> None:
# todo we can not use playwright because it gives async errors, so we need another
# wait to check the server for being up
sleep(5)
def wait_for_server_ready(server: Generator[Any, Any, Any]) -> None:
for _ in range(TestSettings.TIME_OUT):
try:
# we use urllib instead of playwright, because we only want a simple request
# not a full page with all assets
assert urllib.request.urlopen(server).getcode() == 200 # type: ignore # noqa
break
# todo (robbert) find out what exception to catch
except URLError: # server was not ready
sleep(1)


@pytest.fixture(scope="module")
Expand All @@ -42,7 +51,6 @@ def server() -> Generator[Any, Any, Any]:
server_address = (
TestSettings.HTTP_SERVER_SCHEME + TestSettings.HTTP_SERVER_HOST + ":" + str(TestSettings.HTTP_SERVER_PORT)
)
wait_for_server_ready(server_address)
yield server_address
process.terminate()
del os.environ["APP_DATABASE_FILE"]
Expand Down Expand Up @@ -77,10 +85,11 @@ def playwright():


@pytest.fixture(params=["chromium", "firefox", "webkit"])
def browser(playwright: Playwright, request: SubRequest) -> Generator[Page, Any, Any]:
def browser(playwright: Playwright, request: SubRequest, server: Generator[Any, Any, Any]) -> Generator[Page, Any, Any]:
browser = getattr(playwright, request.param).launch(headless=True)
context = browser.new_context()
context = browser.new_context(base_url=server)
page = context.new_page()
wait_for_server_ready(server)
yield page
browser.close()

Expand Down
2 changes: 1 addition & 1 deletion tests/database_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def init(self, specifications: list[dict[str, str | int]] | None = None) -> None
table = specification.pop("table")
keys = ", ".join(key for key in specification)
values = ", ".join(
str(val) if str(val).isnumeric() else str("'" + val + "'")
str(val) if str(val).isnumeric() else str("'" + val + "'") # type: ignore
for val in specification.values() # type: ignore
)
statement = f"INSERT INTO {table} ({keys}) VALUES ({values})" # noqa S608
Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/test_move_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from tests.database_test_utils import DatabaseTestUtils


def test_move_task_to_column(server: str, browser: Page, db: DatabaseTestUtils) -> None:
def test_move_task_to_column(browser: Page, db: DatabaseTestUtils) -> None:
"""
Test moving a task in the browser to another column and verify that after a reload
it is in the right column.
Expand All @@ -20,7 +20,7 @@ def test_move_task_to_column(server: str, browser: Page, db: DatabaseTestUtils)
]
)

browser.goto(f"{server}/pages/")
browser.goto("/pages/")

expect(browser.locator("#column-1 #card-1")).to_be_visible()
expect(browser.locator("#column-3")).to_be_visible()
Expand All @@ -36,7 +36,7 @@ def test_move_task_to_column(server: str, browser: Page, db: DatabaseTestUtils)
expect(card).to_be_visible()


def test_move_task_order_in_same_column(server: str, browser: Page, db: DatabaseTestUtils) -> None:
def test_move_task_order_in_same_column(browser: Page, db: DatabaseTestUtils) -> None:
"""
Test moving a task in the browser below another task and verify that after a reload
it is in the right position in the column.
Expand All @@ -50,7 +50,7 @@ def test_move_task_order_in_same_column(server: str, browser: Page, db: Database
]
)

browser.goto(f"{server}/pages/")
browser.goto("/pages/")

expect(browser.locator("#column-1 #card-1")).to_be_visible()
expect(browser.locator("#column-1")).to_be_visible()
Expand Down

0 comments on commit 4f2a83e

Please sign in to comment.