-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c8d1e8
commit e01b5ef
Showing
13 changed files
with
168 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: CI | ||
on: | ||
push: | ||
branches: | ||
- "*" | ||
pull_request: | ||
branches: | ||
- "*" | ||
workflow_dispatch: | ||
|
||
jobs: | ||
test: | ||
strategy: | ||
fail-fast: true | ||
matrix: | ||
python-version: ['3.8', '3.10'] | ||
os: [ubuntu-latest] | ||
runs-on: ${{matrix.os}} | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{matrix.python-version}} | ||
- name: Install Poetry | ||
run: pip install --upgrade pip && pip install poetry | ||
|
||
- name: Install Project | ||
run: poetry install | ||
|
||
- name: Look for style errors | ||
run: poetry run flake8 beerlog | ||
|
||
- name: Look for auto format errors | ||
run: poetry run black -l 79 --check --diff beerlog tests | ||
|
||
- name: Run tests | ||
run: poetry run pytest -v --junitxml=test-result.xml | ||
|
||
- name: publish junit results | ||
uses: EnricoMi/publish-unit-test-result-action@v1 | ||
if: always() | ||
with: | ||
files: test-result.xml | ||
check_name: Test Result (Python ${{matrix.python-version}}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import pytest | ||
from unittest.mock import patch | ||
from sqlmodel import create_engine | ||
from beerlog import models | ||
|
||
|
||
@pytest.fixture(autouse=True, scope="function") | ||
def each_test_uses_separate_database(request): | ||
tmpdir = request.getfixturevalue("tmpdir") | ||
test_db = tmpdir.join("beerlog.test.db") | ||
engine = create_engine(f"sqlite:///{test_db}") | ||
models.SQLModel.metadata.create_all(bind=engine) | ||
with patch("beerlog.database.engine", engine): | ||
yield |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from fastapi.testclient import TestClient | ||
|
||
from beerlog.api import api | ||
|
||
|
||
client = TestClient(api) | ||
|
||
|
||
def test_create_beer_via_api(): | ||
response = client.post( | ||
"/beers", | ||
json={ | ||
"name": "Skol", | ||
"style": "KornPA", | ||
"flavor": 1, | ||
"image": 1, | ||
"cost": 2, | ||
}, | ||
) | ||
assert response.status_code == 201 | ||
result = response.json() | ||
assert result["name"] == "Skol" | ||
assert result["id"] == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from typer.testing import CliRunner | ||
|
||
from beerlog.cli import main | ||
|
||
runner = CliRunner() | ||
|
||
|
||
def test_add_beer(): | ||
result = runner.invoke( | ||
main, ["add", "Skol", "KornPA", "--flavor=1", "--image=1", "--cost=2"] | ||
) | ||
assert result.exit_code == 0 | ||
assert "Beer added" in result.stdout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from beerlog.core import get_beers_from_database, add_beer_to_database | ||
|
||
|
||
def test_add_beer_to_database(): | ||
assert add_beer_to_database("Blue Moon", "Witbier", 10, 3, 6) | ||
|
||
|
||
def test_get_beers_from_database(): | ||
# Arrange | ||
add_beer_to_database("Blue Moon", "Witbier", 10, 3, 6) | ||
# Act | ||
results = get_beers_from_database() | ||
# Assert | ||
assert len(results) > 0 |