diff --git a/.github/workflows/integration_test.yml b/.github/workflows/integration_test.yml new file mode 100644 index 0000000..87c5b1d --- /dev/null +++ b/.github/workflows/integration_test.yml @@ -0,0 +1,33 @@ +name: Lila integration test + +on: + - push + - pull_request + +jobs: + lila: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + container: ubuntu:22.04 + services: + bdit_lila: + image: ghcr.io/lichess-org/lila-docker:main + options: --restart=always + steps: + - name: Setup Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install pytest + - name: Install curl + run: apt-get update && apt-get install -y curl + - name: Checkout berserk + uses: actions/checkout@v4 + - name: Run tests + run: | + ./integration/run-tests.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f16cee2..569f884 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: @@ -34,4 +34,4 @@ jobs: - name: Install dependencies run: poetry install --with dev - name: Test - run: poetry run pytest + run: poetry run pytest tests diff --git a/.github/workflows/typing.yml b/.github/workflows/typing.yml index 83f8131..629ca2f 100644 --- a/.github/workflows/typing.yml +++ b/.github/workflows/typing.yml @@ -20,7 +20,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/Makefile b/Makefile index 25716b2..c93d454 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ setup: ## setup poetry env and install dependencies poetry install --with dev test: ## run tests with pytest - poetry run pytest + poetry run pytest tests test_record: ## run tests with pytest and record http requests poetry run pytest --record-mode=once diff --git a/integration/local.sh b/integration/local.sh new file mode 100755 index 0000000..422e0e3 --- /dev/null +++ b/integration/local.sh @@ -0,0 +1,26 @@ +#!/bin/bash -e + +integration_test() { + # BDIT = Berserk Docker Image Test, trying to reduce collision + local BDIT_IMAGE=ghcr.io/lichess-org/lila-docker:main + local BDIT_LILA=bdit_lila + local BDIT_NETWORK=bdit_lila-network + local BDIT_APP=bdit_app + + cleanup_containers() { + docker rm --force $BDIT_LILA > /dev/null 2>&1 || true + docker rm --force $BDIT_APP > /dev/null 2>&1 || true + docker network rm $BDIT_NETWORK > /dev/null 2>&1 || true + } + + echo "Running integration tests" + cleanup_containers + + docker network create $BDIT_NETWORK + docker run --name $BDIT_LILA --network $BDIT_NETWORK -d $BDIT_IMAGE + docker run --name $BDIT_APP --network $BDIT_NETWORK -v "$(pwd)":/app -w /app $BDIT_IMAGE ./integration/run-tests.sh + + cleanup_containers + echo "✅ Done" +} +integration_test \ No newline at end of file diff --git a/integration/run-tests.sh b/integration/run-tests.sh new file mode 100755 index 0000000..71126e3 --- /dev/null +++ b/integration/run-tests.sh @@ -0,0 +1,15 @@ +#!/bin/bash -e + +python3 -m pip install -e . --no-cache-dir + +attempts=0 +while [ $attempts -lt 30 ]; do + if curl -s http://bdit_lila:9663 >/dev/null; then + break + fi + echo "⌛ Waiting for lila to start..." + sleep 1 + attempts=$((attempts + 1)) +done + +pytest integration diff --git a/integration/test_lila_account.py b/integration/test_lila_account.py new file mode 100644 index 0000000..47a4062 --- /dev/null +++ b/integration/test_lila_account.py @@ -0,0 +1,41 @@ +import berserk +import pytest + +BASE_URL = "http://bdit_lila:9663" + +@pytest.fixture(scope="module") +def client(): + session = berserk.TokenSession('lip_bobby') + client = berserk.Client( + session, base_url=BASE_URL) + yield client + + +def test_account_get(client): + me = client.account.get() + assert me['id'] == 'bobby' + + +def test_account_get_email(client): + assert client.account.get_email() == 'bobby@localhost' + + +def test_account_get_preferences(client): + preferences = client.account.get_preferences() + assert preferences['language'] == 'en-US' + assert preferences['prefs']['animation'] == 2 + + +def test_account_kid_mode(client): + assert client.account.get_kid_mode() == False + client.account.set_kid_mode(True) + assert client.account.get_kid_mode() == True + + +def test_account_upgrade_to_bot(): + session = berserk.TokenSession('lip_zerogames') + client = berserk.Client( + session, base_url=BASE_URL) + assert 'title' not in client.account.get() + client.account.upgrade_to_bot() + assert client.account.get()['title'] == "BOT"