From 4d6baa9d79d2f86794b13d5545c8507116b7f8b1 Mon Sep 17 00:00:00 2001 From: Joel Borges Junior Date: Mon, 25 Apr 2022 23:05:44 -0300 Subject: [PATCH 01/11] Python Week dia 1 --- .idea/.gitignore | 0 .idea/inspectionProfiles/profiles_settings.xml | 6 ++++++ .idea/misc.xml | 4 ++++ .idea/modules.xml | 8 ++++++++ .idea/python-week-2022.iml | 10 ++++++++++ .idea/vcs.xml | 6 ++++++ beerlog.db | Bin 0 -> 12288 bytes 7 files changed, 34 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/python-week-2022.iml create mode 100644 .idea/vcs.xml create mode 100644 beerlog.db diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..6bf8019 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..4913035 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/python-week-2022.iml b/.idea/python-week-2022.iml new file mode 100644 index 0000000..d143596 --- /dev/null +++ b/.idea/python-week-2022.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/beerlog.db b/beerlog.db new file mode 100644 index 0000000000000000000000000000000000000000..0b8124afe5b0ef2557d374ea27604a8aee568011 GIT binary patch literal 12288 zcmeI#&r8EF6bJC66J-T|9mcNDn*;IUQ4s4EwAytVJ9Veg*-QfM3SE(T6#qj1BNJJ1 zLcMt!-$0tAuL*gdp5Fakpi4#5yvX8`PS_sfoShRf#vIcdrdQ3bH>!mh`O5sSsl$#R zueVLq+4*F<`{scL0SG_<0uX=z1Rwwb2tWV=5cm&)GiS4X(BeZqOVmOy#uKHAu}`L#)B@r$aBJm>SWHc-T-lwY|} zV%I&Ba^&}gy~wTf`<@)pjTn6=>vn8yZi;?12tWV=5P$##AOHafKmY;|fB*#6SirTp fq5favKaA8M009U<00Izz00bZa0SG_<0*rkD`JG&^ literal 0 HcmV?d00001 From 6733ba8c82f99949b6678449bb9b10e8125c28ca Mon Sep 17 00:00:00 2001 From: Joel Borges Junior Date: Wed, 27 Apr 2022 00:15:07 -0300 Subject: [PATCH 02/11] Python Week dia 2 --- beerlog/api.py | 0 beerlog/serializers.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 beerlog/api.py create mode 100644 beerlog/serializers.py diff --git a/beerlog/api.py b/beerlog/api.py new file mode 100644 index 0000000..e69de29 diff --git a/beerlog/serializers.py b/beerlog/serializers.py new file mode 100644 index 0000000..e69de29 From a3562b8f8c732675450b35019c6be7535247eb9a Mon Sep 17 00:00:00 2001 From: Joel Borges Junior Date: Thu, 28 Apr 2022 00:43:38 -0300 Subject: [PATCH 03/11] Python Week dia 3 --- .github/workflows/main.yaml | 45 +++ .idea/dbnavigator.xml | 553 +++++++++++++++++++++++++++++++++++ .idea/encodings.xml | 6 + .idea/workspace.xml | 83 ++++++ beerlog.db | Bin 12288 -> 12288 bytes beerlog/__main__.py | 2 +- beerlog/api.py | 26 ++ beerlog/cli.py | 40 ++- beerlog/config.py | 2 +- beerlog/core.py | 28 ++ beerlog/database.py | 20 ++ beerlog/models.py | 28 ++ beerlog/serializers.py | 32 ++ beerlog/settings.toml | 4 + conftest.py | 14 + poetry.lock | 115 +++++++- pyproject.toml | 2 + tests/test_core.py | 11 + tests/test_functional_api.py | 22 ++ tests/test_functional_cli.py | 12 + 20 files changed, 1039 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/main.yaml create mode 100644 .idea/dbnavigator.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/workspace.xml create mode 100644 tests/test_core.py create mode 100644 tests/test_functional_api.py create mode 100644 tests/test_functional_cli.py diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 0000000..6a99017 --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,45 @@ + name: Tests BeerLog + 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/setup-python@v2 + - uses: actions/checkout@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 erros + run: poetry run black -l 79 --check --diff beerlog tests + + - name: Run tests + run: poety 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}}) diff --git a/.idea/dbnavigator.xml b/.idea/dbnavigator.xml new file mode 100644 index 0000000..a15ef2a --- /dev/null +++ b/.idea/dbnavigator.xml @@ -0,0 +1,553 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
\ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..cb461bc --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..ad8eb52 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1650933361535 + + + + + + + + + \ No newline at end of file diff --git a/beerlog.db b/beerlog.db index 0b8124afe5b0ef2557d374ea27604a8aee568011..733c526744ddd145786b80ba74153989637d0fef 100644 GIT binary patch delta 433 zcmZXQze>YE0LCwWO&oF+5h*GL7ZFLk+~txc;85#Qa4591^wiUq#-=tF$My}>M-Y4g zk-mb157Eh~larH!mxv+LR^Bph~jO25^t2~*e5fnN&pPJd zLge|e=ea=;QQxabg4-y#)=g^HI{Z9qu!P&ygzK9AgF2YzzaSj@$VDg!BfJOz(BTZg kPxt}f;T*ofnYj5CZfS}n>3ZIpmba?rttffRvZ9#g7yQ~ bool: + with get_session() as session: + beer = Beer( + name=name, style=style, flavor=flavor, image=image, cost=cost + ) + session.add(beer) + session.commit() + return True + + +def get_beers_from_database() -> List[Beer]: + with get_session() as session: + sql = select(Beer) + return list(session.exec(sql)) diff --git a/beerlog/database.py b/beerlog/database.py index e69de29..6d6d230 100644 --- a/beerlog/database.py +++ b/beerlog/database.py @@ -0,0 +1,20 @@ +import warnings + +from sqlalchemy.exc import SAWarning +from sqlmodel import Session, create_engine +from sqlmodel.sql.expression import Select, SelectOfScalar + +from beerlog import models +from beerlog.config import settings + +warnings.filterwarnings("ignore", category=SAWarning) +SelectOfScalar.inherit_cache = True +Select.inherit_cache = True + +engine = create_engine(settings.database.url) + +models.SQLModel.metadata.create_all(engine) + + +def get_session(): + return Session(engine) diff --git a/beerlog/models.py b/beerlog/models.py index e69de29..68a4d75 100644 --- a/beerlog/models.py +++ b/beerlog/models.py @@ -0,0 +1,28 @@ +from datetime import datetime +from statistics import mean +from typing import Optional + +from pydantic import validator +from sqlmodel import Field, SQLModel + + +class Beer(SQLModel, table=True): + id: Optional[int] = Field(primary_key=True, default=None, index=True) + name: str + style: str + flavor: int + image: int + cost: int + rate: int = 0 + date: datetime = Field(default_factory=datetime.now) + + @validator("flavor", "image", "cost") + def validate_ratings(cls, v, field): + if v < 1 or v > 10: + raise RuntimeError(f"{field.name} must be between 1 and 10.") + return v + + @validator("rate", always=True) + def calcalute_rate(cls, v, values): + rate = mean([values["flavor"], values["image"], values["cost"]]) + return int(rate) diff --git a/beerlog/serializers.py b/beerlog/serializers.py index e69de29..65f09ee 100644 --- a/beerlog/serializers.py +++ b/beerlog/serializers.py @@ -0,0 +1,32 @@ +from datetime import datetime + +from fastapi import HTTPException, status +from pydantic import BaseModel, validator + + +class BeerOut(BaseModel): + id: int + name: str + style: str + flavor: int + image: int + cost: int + rate: int + date: datetime + + +class BeerIn(BaseModel): + name: str + style: str + flavor: int + image: int + cost: int + + @validator("flavor", "image", "cost") + def validate_ratings(cls, v, field): + if v < 1 or v > 10: + raise HTTPException( + detail=f"{field.name} must be between 1 and 10", + status_code=status.HTTP_400_BAD_REQUEST, + ) + return v diff --git a/beerlog/settings.toml b/beerlog/settings.toml index 34d5fcb..1753de8 100644 --- a/beerlog/settings.toml +++ b/beerlog/settings.toml @@ -1 +1,5 @@ name = "beerlog" + +[database] +url = "sqlite:///beerlog.db" + diff --git a/conftest.py b/conftest.py index e69de29..c9a3851 100644 --- a/conftest.py +++ b/conftest.py @@ -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 diff --git a/poetry.lock b/poetry.lock index 185de7b..b1887ef 100644 --- a/poetry.lock +++ b/poetry.lock @@ -23,6 +23,17 @@ category = "dev" optional = false python-versions = "*" +[[package]] +name = "asgiref" +version = "3.5.0" +description = "ASGI specs, helper code, and adapters" +category = "main" +optional = false +python-versions = ">=3.7" + +[package.extras] +tests = ["pytest", "pytest-asyncio", "mypy (>=0.800)"] + [[package]] name = "asttokens" version = "2.0.5" @@ -67,6 +78,25 @@ d = ["aiohttp (>=3.7.4)"] jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"] uvloop = ["uvloop (>=0.15.2)"] +[[package]] +name = "certifi" +version = "2021.10.8" +description = "Python package for providing Mozilla's CA Bundle." +category = "main" +optional = false +python-versions = "*" + +[[package]] +name = "charset-normalizer" +version = "2.0.12" +description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet." +category = "main" +optional = false +python-versions = ">=3.5.0" + +[package.extras] +unicode_backport = ["unicodedata2"] + [[package]] name = "click" version = "8.1.2" @@ -173,6 +203,14 @@ python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*" [package.extras] docs = ["sphinx"] +[[package]] +name = "h11" +version = "0.13.0" +description = "A pure-Python, bring-your-own-I/O implementation of HTTP/1.1" +category = "main" +optional = false +python-versions = ">=3.6" + [[package]] name = "idna" version = "3.3" @@ -378,6 +416,24 @@ category = "main" optional = false python-versions = ">=3.5" +[[package]] +name = "requests" +version = "2.27.1" +description = "Python HTTP for Humans." +category = "main" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*" + +[package.dependencies] +certifi = ">=2017.4.17" +charset-normalizer = {version = ">=2.0.0,<2.1.0", markers = "python_version >= \"3\""} +idna = {version = ">=2.5,<4", markers = "python_version >= \"3\""} +urllib3 = ">=1.21.1,<1.27" + +[package.extras] +socks = ["PySocks (>=1.5.6,!=1.5.7)", "win-inet-pton"] +use_chardet_on_py3 = ["chardet (>=3.0.2,<5)"] + [[package]] name = "rich" version = "12.2.0" @@ -540,6 +596,35 @@ category = "main" optional = false python-versions = ">=3.7" +[[package]] +name = "urllib3" +version = "1.26.9" +description = "HTTP library with thread-safe connection pooling, file post, and more." +category = "main" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4" + +[package.extras] +brotli = ["brotlicffi (>=0.8.0)", "brotli (>=1.0.9)", "brotlipy (>=0.6.0)"] +secure = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "certifi", "ipaddress"] +socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"] + +[[package]] +name = "uvicorn" +version = "0.17.6" +description = "The lightning-fast ASGI server." +category = "main" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +asgiref = ">=3.4.0" +click = ">=7.0" +h11 = ">=0.8" + +[package.extras] +standard = ["websockets (>=10.0)", "httptools (>=0.4.0)", "watchgod (>=0.6)", "python-dotenv (>=0.13)", "PyYAML (>=5.1)", "uvloop (>=0.14.0,!=0.15.0,!=0.15.1)", "colorama (>=0.4)"] + [[package]] name = "wcwidth" version = "0.2.5" @@ -551,7 +636,7 @@ python-versions = "*" [metadata] lock-version = "1.1" python-versions = "^3.8" -content-hash = "1e063e12af3889e809b53f9a6c5d6a76b6f76639335e397e000877ad7931ebc1" +content-hash = "45f47abd7ba511aa4f51a9c28c32dfa7ad6cc16d0e07304dbe369bde8318f09c" [metadata.files] anyio = [ @@ -562,6 +647,10 @@ appnope = [ {file = "appnope-0.1.3-py2.py3-none-any.whl", hash = "sha256:265a455292d0bd8a72453494fa24df5a11eb18373a60c7c0430889f22548605e"}, {file = "appnope-0.1.3.tar.gz", hash = "sha256:02bd91c4de869fbb1e1c50aafc4098827a7a54ab2f39d9dcba6c9547ed920e24"}, ] +asgiref = [ + {file = "asgiref-3.5.0-py3-none-any.whl", hash = "sha256:88d59c13d634dcffe0510be048210188edd79aeccb6a6c9028cdad6f31d730a9"}, + {file = "asgiref-3.5.0.tar.gz", hash = "sha256:2f8abc20f7248433085eda803936d98992f1343ddb022065779f37c5da0181d0"}, +] asttokens = [ {file = "asttokens-2.0.5-py2.py3-none-any.whl", hash = "sha256:0844691e88552595a6f4a4281a9f7f79b8dd45ca4ccea82e5e05b4bbdb76705c"}, {file = "asttokens-2.0.5.tar.gz", hash = "sha256:9a54c114f02c7a9480d56550932546a3f1fe71d8a02f1bc7ccd0ee3ee35cf4d5"}, @@ -595,6 +684,14 @@ black = [ {file = "black-22.3.0-py3-none-any.whl", hash = "sha256:bc58025940a896d7e5356952228b68f793cf5fcb342be703c3a2669a1488cb72"}, {file = "black-22.3.0.tar.gz", hash = "sha256:35020b8886c022ced9282b51b5a875b6d1ab0c387b31a065b84db7c33085ca79"}, ] +certifi = [ + {file = "certifi-2021.10.8-py2.py3-none-any.whl", hash = "sha256:d62a0163eb4c2344ac042ab2bdf75399a71a2d8c7d47eac2e2ee91b9d6339569"}, + {file = "certifi-2021.10.8.tar.gz", hash = "sha256:78884e7c1d4b00ce3cea67b44566851c4343c120abd683433ce934a68ea58872"}, +] +charset-normalizer = [ + {file = "charset-normalizer-2.0.12.tar.gz", hash = "sha256:2857e29ff0d34db842cd7ca3230549d1a697f96ee6d3fb071cfa6c7393832597"}, + {file = "charset_normalizer-2.0.12-py3-none-any.whl", hash = "sha256:6881edbebdb17b39b4eaaa821b438bf6eddffb4468cf344f09f89def34a8b1df"}, +] click = [ {file = "click-8.1.2-py3-none-any.whl", hash = "sha256:24e1a4a9ec5bf6299411369b208c1df2188d9eb8d916302fe6bf03faed227f1e"}, {file = "click-8.1.2.tar.gz", hash = "sha256:479707fe14d9ec9a0757618b7a100a0ae4c4e236fac5b7f80ca68028141a1a72"}, @@ -684,6 +781,10 @@ greenlet = [ {file = "greenlet-1.1.2-cp39-cp39-win_amd64.whl", hash = "sha256:013d61294b6cd8fe3242932c1c5e36e5d1db2c8afb58606c5a67efce62c1f5fd"}, {file = "greenlet-1.1.2.tar.gz", hash = "sha256:e30f5ea4ae2346e62cedde8794a56858a67b878dd79f7df76a0767e356b1744a"}, ] +h11 = [ + {file = "h11-0.13.0-py3-none-any.whl", hash = "sha256:8ddd78563b633ca55346c8cd41ec0af27d3c79931828beffb46ce70a379e7442"}, + {file = "h11-0.13.0.tar.gz", hash = "sha256:70813c1135087a248a4d38cc0e1a0181ffab2188141a93eaf567940c3957ff06"}, +] idna = [ {file = "idna-3.3-py3-none-any.whl", hash = "sha256:84d9dd047ffa80596e0f246e2eab0b391788b0503584e8945f2368256d2735ff"}, {file = "idna-3.3.tar.gz", hash = "sha256:9d643ff0a55b762d5cdb124b8eaa99c66322e2157b69160bc32796e824360e6d"}, @@ -789,6 +890,10 @@ pygments = [ {file = "Pygments-2.11.2-py3-none-any.whl", hash = "sha256:44238f1b60a76d78fc8ca0528ee429702aae011c265fe6a8dd8b63049ae41c65"}, {file = "Pygments-2.11.2.tar.gz", hash = "sha256:4e426f72023d88d03b2fa258de560726ce890ff3b630f88c21cbb8b2503b8c6a"}, ] +requests = [ + {file = "requests-2.27.1-py2.py3-none-any.whl", hash = "sha256:f22fa1e554c9ddfd16e6e41ac79759e17be9e492b3587efa038054674760e72d"}, + {file = "requests-2.27.1.tar.gz", hash = "sha256:68d7c56fd5a8999887728ef304a6d12edc7be74f1cfa47714fc8b414525c9a61"}, +] rich = [ {file = "rich-12.2.0-py3-none-any.whl", hash = "sha256:c50f3d253bc6a9bb9c79d61a26d510d74abdf1b16881260fab5edfc3edfb082f"}, {file = "rich-12.2.0.tar.gz", hash = "sha256:ea74bc9dad9589d8eea3e3fd0b136d8bf6e428888955f215824c2894f0da8b47"}, @@ -871,6 +976,14 @@ typing-extensions = [ {file = "typing_extensions-4.2.0-py3-none-any.whl", hash = "sha256:6657594ee297170d19f67d55c05852a874e7eb634f4f753dbd667855e07c1708"}, {file = "typing_extensions-4.2.0.tar.gz", hash = "sha256:f1c24655a0da0d1b67f07e17a5e6b2a105894e6824b92096378bb3668ef02376"}, ] +urllib3 = [ + {file = "urllib3-1.26.9-py2.py3-none-any.whl", hash = "sha256:44ece4d53fb1706f667c9bd1c648f5469a2ec925fcf3a776667042d645472c14"}, + {file = "urllib3-1.26.9.tar.gz", hash = "sha256:aabaf16477806a5e1dd19aa41f8c2b7950dd3c746362d7e3223dbe6de6ac448e"}, +] +uvicorn = [ + {file = "uvicorn-0.17.6-py3-none-any.whl", hash = "sha256:19e2a0e96c9ac5581c01eb1a79a7d2f72bb479691acd2b8921fce48ed5b961a6"}, + {file = "uvicorn-0.17.6.tar.gz", hash = "sha256:5180f9d059611747d841a4a4c4ab675edf54c8489e97f96d0583ee90ac3bfc23"}, +] wcwidth = [ {file = "wcwidth-0.2.5-py2.py3-none-any.whl", hash = "sha256:beb4802a9cebb9144e99086eff703a642a13d6a0052920003a230f3294bbe784"}, {file = "wcwidth-0.2.5.tar.gz", hash = "sha256:c4d647b99872929fdb7bdcaa4fbe7f01413ed3d98077df798530e5b04f116c83"}, diff --git a/pyproject.toml b/pyproject.toml index ad3f120..bc44619 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,6 +14,8 @@ rich = "^12.2.0" dynaconf = "^3.1.8" black = "^22.3.0" flake8 = "^4.0.1" +uvicorn = "^0.17.6" +requests = "^2.27.1" [tool.poetry.dev-dependencies] ipython = "^8.2.0" diff --git a/tests/test_core.py b/tests/test_core.py new file mode 100644 index 0000000..cdf7652 --- /dev/null +++ b/tests/test_core.py @@ -0,0 +1,11 @@ +from beerlog.core import get_beers_from_database, add_beer_to_database + + +def test_add_beer_to_database(): + assert add_beer_to_database("Brahma", "Pilsen", 5, 4, 7) + + +def test_get_beers_from_database(): + add_beer_to_database("Brahma", "Pilsen", 5, 4, 7) + results = get_beers_from_database() + assert len(results) > 0 diff --git a/tests/test_functional_api.py b/tests/test_functional_api.py new file mode 100644 index 0000000..ebd27b4 --- /dev/null +++ b/tests/test_functional_api.py @@ -0,0 +1,22 @@ +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": "Lagunitas", + "style": "IPA", + "flavor": 8, + "image": 8, + "cost": 8, + }, + ) + assert response.status_code == 200 + result = response.json() + assert result["name"] == "Lagunitas" + assert result["id"] == 1 diff --git a/tests/test_functional_cli.py b/tests/test_functional_cli.py new file mode 100644 index 0000000..9dd77fe --- /dev/null +++ b/tests/test_functional_cli.py @@ -0,0 +1,12 @@ +from typer.testing import CliRunner +from beerlog.cli import main + +runner = CliRunner() + + +def test_add_beer(): + result = runner.invoke( + main, ["add", "Lagunitas", "IPA", "--flavor=8", "--image=8", "--cost=8" ] + ) + assert result.exit_code == 0 + assert "beer added" in result.stdout \ No newline at end of file From e04837379b6b049df46a9a8849e1c360e38109a1 Mon Sep 17 00:00:00 2001 From: Joel Borges Junior Date: Thu, 28 Apr 2022 00:45:41 -0300 Subject: [PATCH 04/11] Python Week dia 3.1 --- .idea/workspace.xml | 16 +--------------- beerlog/cli.py | 2 +- beerlog/core.py | 2 +- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index ad8eb52..87246d4 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,23 +2,9 @@ - - - - - - - + - - - - - - - -