Skip to content

Commit

Permalink
Enable unit tests in GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
daya0576 committed Jun 1, 2024
1 parent 02687dc commit cd700f7
Show file tree
Hide file tree
Showing 7 changed files with 526 additions and 380 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/fly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,27 @@ on:
branches:
- main
jobs:
pre-deploy-test:
name: Unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install --no-interaction --no-ansi
- name: Test with pytest
run: poetry run pytest tests

deploy:
name: Deploy app
runs-on: ubuntu-latest
needs: pre-deploy-test
concurrency: deploy-group # optional: ensure only one action runs at a time
steps:
- uses: actions/checkout@v4
Expand Down
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ FROM python:3.12.2-slim

LABEL maintainer="Henry Zhu <[email protected]>"

COPY requirements.txt /tmp/requirements.txt
RUN pip install --no-cache-dir -r /tmp/requirements.txt

COPY . .

RUN pip install --upgrade pip \
&& pip install poetry
RUN poetry config virtualenvs.create false \
&& poetry install --no-interaction --no-ansi --without dev

CMD ["sh", "start.sh", "prd"]
2 changes: 1 addition & 1 deletion beaverhabits/frontend/index_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ def habit_list_ui(days: List[datetime.date], habits: HabitList):
checkbox.classes(right_classes)


async def index_page_ui(days: List[datetime.date], habits: HabitList):
def index_page_ui(days: List[datetime.date], habits: HabitList):
with layout():
habit_list_ui(days, habits)
4 changes: 2 additions & 2 deletions beaverhabits/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
async def demo_index_page() -> None:
days = await dummy_days(settings.INDEX_HABIT_ITEM_COUNT)
habit_list = views.get_or_create_session_habit_list(days)
await index_page_ui(days, habit_list)
index_page_ui(days, habit_list)


@ui.page("/demo/add")
Expand All @@ -55,7 +55,7 @@ async def index_page(
) -> None:
days = await dummy_days(settings.INDEX_HABIT_ITEM_COUNT)
habits = await views.get_or_create_user_habit_list(user, days)
await index_page_ui(days, habits)
index_page_ui(days, habits)


@ui.page("/gui/add")
Expand Down
377 changes: 189 additions & 188 deletions poetry.lock

Large diffs are not rendered by default.

445 changes: 271 additions & 174 deletions requirements.txt

Large diffs are not rendered by default.

52 changes: 39 additions & 13 deletions tests/test_main_page.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,53 @@
from nicegui import ui
import datetime
from nicegui.testing import Screen

from beaverhabits.configs import settings
from beaverhabits.frontend.add_page import add_page_ui
from beaverhabits.frontend.habit_page import habit_page_ui
from beaverhabits.frontend.index_page import index_page_ui
from beaverhabits.utils import dummy_days
from beaverhabits.views import (
get_or_create_session_habit_list,
dummy_habit_list,
)

# Test cases:
# https://github.com/zauberzeug/nicegui/tree/main/tests


def test_hello():
assert "Hello" == "Hello"
def dummy_today():
return datetime.date(2024, 5, 1)


def test_demo_page(screen: Screen) -> None:
@ui.page("/demo")
async def index_page() -> None:
days = dummy_days(settings.INDEX_HABIT_ITEM_COUNT)
habit_list = get_or_create_session_habit_list(days)
index_page_ui(habit_list)
def dummy_days(count):
today = dummy_today()
return [today - datetime.timedelta(days=i) for i in reversed(range(count))]


def test_index_page(screen: Screen) -> None:
days = dummy_days(7)
habits = dummy_habit_list(days)

index_page_ui(days, habits)

screen.open("/", timeout=60)
screen.should_contain("Habits")


def test_add_page(screen: Screen) -> None:
days = dummy_days(7)
habits = dummy_habit_list(days)

add_page_ui(habits)

screen.open("/", timeout=60)
screen.should_contain("Habits")


def test_habit_detail_page(screen: Screen) -> None:
days = dummy_days(7)
today = days[-1]
habits = dummy_habit_list(days)
habit = habits.habits[0]

habit_page_ui(today, habit)

screen.open("/", timeout=60)
screen.should_contain("Demo")
screen.should_contain("Order pizz")

0 comments on commit cd700f7

Please sign in to comment.