From 97c22ec0fc2a57b35fff78a878a88faa809a1583 Mon Sep 17 00:00:00 2001 From: Thaza_Kun <61819672+Thaza-Kun@users.noreply.github.com> Date: Tue, 13 Sep 2022 13:20:55 +0800 Subject: [PATCH 01/11] feat: poetry entrypoint --- .pre-commit-config.yaml | 28 +++--- poetry.lock | 185 +++++++++++++++++++++++----------------- 2 files changed, 122 insertions(+), 91 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1af676f..6732f15 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,17 +7,19 @@ repos: rev: v2.5.0 hooks: - id: check-added-large-files - - repo: local + # - repo: local + # hooks: + # - id: pylint + # name: pylint + # entry: poetry run pylint samudra/ + # language: system + # always_run: true + # pass_filenames: false + - repo: https://github.com/python-poetry/poetry + rev: 1.2.0 hooks: - # - id: pylint - # name: pylint - # entry: poetry run pylint samudra/ - # language: system - # always_run: true - # pass_filenames: false - - id: create requirements - name: create requirements - entry: poetry export -o requirements.txt --extras mysql --without-hashes - language: system - always_run: true - pass_filenames: false \ No newline at end of file + - id: poetry-check + - id: poetry-lock + - id: poetry-export + name: create requirements with mysql + args: [ "-o", "requirements.txt", "--extras", "mysql", "--without-hashes" ] \ No newline at end of file diff --git a/poetry.lock b/poetry.lock index ff55e38..7ae42f8 100644 --- a/poetry.lock +++ b/poetry.lock @@ -11,13 +11,13 @@ idna = ">=2.8" sniffio = ">=1.1" [package.extras] -doc = ["packaging", "sphinx-rtd-theme", "sphinx-autodoc-typehints (>=1.2.0)"] -test = ["coverage[toml] (>=4.5)", "hypothesis (>=4.0)", "pytest (>=7.0)", "pytest-mock (>=3.6.1)", "trustme", "contextlib2", "uvloop (<0.15)", "mock (>=4)", "uvloop (>=0.15)"] +doc = ["packaging", "sphinx-autodoc-typehints (>=1.2.0)", "sphinx-rtd-theme"] +test = ["contextlib2", "coverage[toml] (>=4.5)", "hypothesis (>=4.0)", "mock (>=4)", "pytest (>=7.0)", "pytest-mock (>=3.6.1)", "trustme", "uvloop (<0.15)", "uvloop (>=0.15)"] trio = ["trio (>=0.16)"] [[package]] name = "astroid" -version = "2.12.6" +version = "2.12.9" description = "An abstract syntax tree for Python with inference support." category = "dev" optional = false @@ -40,10 +40,10 @@ optional = false python-versions = ">=3.5" [package.extras] -dev = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "mypy (>=0.900,!=0.940)", "pytest-mypy-plugins", "zope.interface", "furo", "sphinx", "sphinx-notfound-page", "pre-commit", "cloudpickle"] -docs = ["furo", "sphinx", "zope.interface", "sphinx-notfound-page"] -tests = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "mypy (>=0.900,!=0.940)", "pytest-mypy-plugins", "zope.interface", "cloudpickle"] -tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "mypy (>=0.900,!=0.940)", "pytest-mypy-plugins", "cloudpickle"] +dev = ["cloudpickle", "coverage[toml] (>=5.0.2)", "furo", "hypothesis", "mypy (>=0.900,!=0.940)", "pre-commit", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "sphinx", "sphinx-notfound-page", "zope.interface"] +docs = ["furo", "sphinx", "sphinx-notfound-page", "zope.interface"] +tests = ["cloudpickle", "coverage[toml] (>=5.0.2)", "hypothesis", "mypy (>=0.900,!=0.940)", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "zope.interface"] +tests_no_zope = ["cloudpickle", "coverage[toml] (>=5.0.2)", "hypothesis", "mypy (>=0.900,!=0.940)", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins"] [[package]] name = "bcrypt" @@ -84,7 +84,7 @@ uvloop = ["uvloop (>=0.15.2)"] [[package]] name = "certifi" -version = "2022.6.15" +version = "2022.6.15.1" description = "Python package for providing Mozilla's CA Bundle." category = "main" optional = false @@ -151,12 +151,12 @@ python-versions = ">=3.6" cffi = ">=1.12" [package.extras] -docs = ["sphinx (>=1.6.5,!=1.8.0,!=3.1.0,!=3.1.1)", "sphinx-rtd-theme"] -docstest = ["pyenchant (>=1.6.11)", "twine (>=1.12.0)", "sphinxcontrib-spelling (>=4.0.1)"] +docs = ["sphinx (>=1.6.5,!=1.8.0,!=3.1.0,!=3.1.1)", "sphinx_rtd_theme"] +docstest = ["pyenchant (>=1.6.11)", "sphinxcontrib-spelling (>=4.0.1)", "twine (>=1.12.0)"] pep8test = ["black", "flake8", "flake8-import-order", "pep8-naming"] sdist = ["setuptools_rust (>=0.11.4)"] ssh = ["bcrypt (>=3.1.5)"] -test = ["pytest (>=6.2.0)", "pytest-benchmark", "pytest-cov", "pytest-subtests", "pytest-xdist", "pretend", "iso8601", "pytz", "hypothesis (>=1.11.4,!=3.79.2)"] +test = ["hypothesis (>=1.11.4,!=3.79.2)", "iso8601", "pretend", "pytest (>=6.2.0)", "pytest-benchmark", "pytest-cov", "pytest-subtests", "pytest-xdist", "pytz"] [[package]] name = "dill" @@ -213,10 +213,10 @@ pydantic = ">=1.6.2,<1.7 || >1.7,<1.7.1 || >1.7.1,<1.7.2 || >1.7.2,<1.7.3 || >1. starlette = "0.19.1" [package.extras] -test = ["types-dataclasses (==0.6.5)", "types-orjson (==3.6.2)", "types-ujson (==4.2.1)", "anyio[trio] (>=3.2.1,<4.0.0)", "flask (>=1.1.2,<3.0.0)", "python-multipart (>=0.0.5,<0.0.6)", "ujson (>=4.0.1,!=4.0.2,!=4.1.0,!=4.2.0,!=4.3.0,!=5.0.0,!=5.1.0,<6.0.0)", "orjson (>=3.2.1,<4.0.0)", "databases[sqlite] (>=0.3.2,<0.6.0)", "peewee (>=3.13.3,<4.0.0)", "sqlalchemy (>=1.3.18,<1.5.0)", "email_validator (>=1.1.1,<2.0.0)", "httpx (>=0.14.0,<0.19.0)", "requests (>=2.24.0,<3.0.0)", "isort (>=5.0.6,<6.0.0)", "black (==22.3.0)", "flake8 (>=3.8.3,<4.0.0)", "mypy (==0.910)", "pytest-cov (>=2.12.0,<4.0.0)", "pytest (>=6.2.4,<7.0.0)"] -doc = ["pyyaml (>=5.3.1,<7.0.0)", "typer (>=0.4.1,<0.5.0)", "mkdocs-markdownextradata-plugin (>=0.1.7,<0.3.0)", "mdx-include (>=1.4.1,<2.0.0)", "mkdocs-material (>=8.1.4,<9.0.0)", "mkdocs (>=1.1.2,<2.0.0)"] -dev = ["pre-commit (>=2.17.0,<3.0.0)", "uvicorn[standard] (>=0.12.0,<0.18.0)", "flake8 (>=3.8.3,<4.0.0)", "autoflake (>=1.4.0,<2.0.0)", "passlib[bcrypt] (>=1.7.2,<2.0.0)", "python-jose[cryptography] (>=3.3.0,<4.0.0)"] -all = ["uvicorn[standard] (>=0.12.0,<0.18.0)", "email_validator (>=1.1.1,<2.0.0)", "orjson (>=3.2.1,<4.0.0)", "ujson (>=4.0.1,!=4.0.2,!=4.1.0,!=4.2.0,!=4.3.0,!=5.0.0,!=5.1.0,<6.0.0)", "pyyaml (>=5.3.1,<7.0.0)", "itsdangerous (>=1.1.0,<3.0.0)", "python-multipart (>=0.0.5,<0.0.6)", "jinja2 (>=2.11.2,<4.0.0)", "requests (>=2.24.0,<3.0.0)"] +all = ["email_validator (>=1.1.1,<2.0.0)", "itsdangerous (>=1.1.0,<3.0.0)", "jinja2 (>=2.11.2,<4.0.0)", "orjson (>=3.2.1,<4.0.0)", "python-multipart (>=0.0.5,<0.0.6)", "pyyaml (>=5.3.1,<7.0.0)", "requests (>=2.24.0,<3.0.0)", "ujson (>=4.0.1,!=4.0.2,!=4.1.0,!=4.2.0,!=4.3.0,!=5.0.0,!=5.1.0,<6.0.0)", "uvicorn[standard] (>=0.12.0,<0.18.0)"] +dev = ["autoflake (>=1.4.0,<2.0.0)", "flake8 (>=3.8.3,<4.0.0)", "passlib[bcrypt] (>=1.7.2,<2.0.0)", "pre-commit (>=2.17.0,<3.0.0)", "python-jose[cryptography] (>=3.3.0,<4.0.0)", "uvicorn[standard] (>=0.12.0,<0.18.0)"] +doc = ["mdx-include (>=1.4.1,<2.0.0)", "mkdocs (>=1.1.2,<2.0.0)", "mkdocs-markdownextradata-plugin (>=0.1.7,<0.3.0)", "mkdocs-material (>=8.1.4,<9.0.0)", "pyyaml (>=5.3.1,<7.0.0)", "typer (>=0.4.1,<0.5.0)"] +test = ["anyio[trio] (>=3.2.1,<4.0.0)", "black (==22.3.0)", "databases[sqlite] (>=0.3.2,<0.6.0)", "email_validator (>=1.1.1,<2.0.0)", "flake8 (>=3.8.3,<4.0.0)", "flask (>=1.1.2,<3.0.0)", "httpx (>=0.14.0,<0.19.0)", "isort (>=5.0.6,<6.0.0)", "mypy (==0.910)", "orjson (>=3.2.1,<4.0.0)", "peewee (>=3.13.3,<4.0.0)", "pytest (>=6.2.4,<7.0.0)", "pytest-cov (>=2.12.0,<4.0.0)", "python-multipart (>=0.0.5,<0.0.6)", "requests (>=2.24.0,<3.0.0)", "sqlalchemy (>=1.3.18,<1.5.0)", "types-dataclasses (==0.6.5)", "types-orjson (==3.6.2)", "types-ujson (==4.2.1)", "ujson (>=4.0.1,!=4.0.2,!=4.1.0,!=4.2.0,!=4.3.0,!=5.0.0,!=5.1.0,<6.0.0)"] [[package]] name = "filelock" @@ -240,7 +240,7 @@ python-versions = ">=3.6" [[package]] name = "identify" -version = "2.5.4" +version = "2.5.5" description = "File identification library for Python" category = "dev" optional = false @@ -274,10 +274,10 @@ optional = false python-versions = ">=3.6.1,<4.0" [package.extras] -pipfile_deprecated_finder = ["pipreqs", "requirementslib"] -requirements_deprecated_finder = ["pipreqs", "pip-api"] colors = ["colorama (>=0.4.3,<0.5.0)"] +pipfile_deprecated_finder = ["pipreqs", "requirementslib"] plugins = ["setuptools"] +requirements_deprecated_finder = ["pip-api", "pipreqs"] [[package]] name = "lazy-object-proxy" @@ -311,9 +311,12 @@ category = "dev" optional = false python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*" +[package.dependencies] +setuptools = "*" + [[package]] name = "numpy" -version = "1.23.2" +version = "1.23.3" description = "NumPy is the fundamental package for array computing with Python." category = "main" optional = false @@ -373,7 +376,7 @@ python-versions = "*" [package.extras] argon2 = ["argon2-cffi (>=18.2.0)"] bcrypt = ["bcrypt (>=3.1.0)"] -build_docs = ["sphinx (>=1.6)", "sphinxcontrib-fulltoc (>=1.2.0)", "cloud-sptheme (>=1.10.1)"] +build_docs = ["cloud-sptheme (>=1.10.1)", "sphinx (>=1.6)", "sphinxcontrib-fulltoc (>=1.2.0)"] totp = ["cryptography"] [[package]] @@ -401,8 +404,8 @@ optional = false python-versions = ">=3.7" [package.extras] -docs = ["furo (>=2021.7.5b38)", "proselint (>=0.10.2)", "sphinx-autodoc-typehints (>=1.12)", "sphinx (>=4)"] -test = ["appdirs (==1.4.4)", "pytest-cov (>=2.7)", "pytest-mock (>=3.6)", "pytest (>=6)"] +docs = ["furo (>=2021.7.5b38)", "proselint (>=0.10.2)", "sphinx (>=4)", "sphinx-autodoc-typehints (>=1.12)"] +test = ["appdirs (==1.4.4)", "pytest (>=6)", "pytest-cov (>=2.7)", "pytest-mock (>=3.6)"] [[package]] name = "pluggy" @@ -413,8 +416,8 @@ optional = false python-versions = ">=3.6" [package.extras] -testing = ["pytest-benchmark", "pytest"] -dev = ["tox", "pre-commit"] +dev = ["pre-commit", "tox"] +testing = ["pytest", "pytest-benchmark"] [[package]] name = "pre-commit" @@ -489,14 +492,14 @@ email = ["email-validator (>=1.0.3)"] [[package]] name = "pylint" -version = "2.15.0" +version = "2.15.2" description = "python code static checker" category = "dev" optional = false python-versions = ">=3.7.2" [package.dependencies] -astroid = ">=2.12.4,<=2.14.0-dev0" +astroid = ">=2.12.9,<=2.14.0-dev0" colorama = {version = ">=0.4.5", markers = "sys_platform == \"win32\""} dill = ">=0.2" isort = ">=4.2.5,<6" @@ -511,7 +514,7 @@ spelling = ["pyenchant (>=3.2,<4.0)"] testutils = ["gitpython (>3)"] [[package]] -name = "pymysql" +name = "PyMySQL" version = "1.0.2" description = "Pure Python MySQL Driver" category = "main" @@ -519,8 +522,8 @@ optional = true python-versions = ">=3.6" [package.extras] -rsa = ["cryptography"] ed25519 = ["PyNaCl (>=1.4.0)"] +rsa = ["cryptography"] [[package]] name = "pyparsing" @@ -531,7 +534,7 @@ optional = false python-versions = ">=3.6.8" [package.extras] -diagrams = ["railroad-diagrams", "jinja2"] +diagrams = ["jinja2", "railroad-diagrams"] [[package]] name = "pytest" @@ -590,8 +593,8 @@ rsa = "*" [package.extras] cryptography = ["cryptography (>=3.4.0)"] -pycrypto = ["pycrypto (>=2.6.0,<2.7.0)", "pyasn1"] -pycryptodome = ["pycryptodome (>=3.3.1,<4.0.0)", "pyasn1"] +pycrypto = ["pyasn1", "pycrypto (>=2.6.0,<2.7.0)"] +pycryptodome = ["pyasn1", "pycryptodome (>=3.3.1,<4.0.0)"] [[package]] name = "python-multipart" @@ -621,7 +624,7 @@ optional = false python-versions = "*" [[package]] -name = "pyyaml" +name = "PyYAML" version = "6.0" description = "YAML parser and emitter for Python" category = "dev" @@ -657,6 +660,19 @@ python-versions = ">=3.6,<4" [package.dependencies] pyasn1 = ">=0.1.3" +[[package]] +name = "setuptools" +version = "65.3.0" +description = "Easily download, build, install, upgrade, and uninstall Python packages" +category = "dev" +optional = false +python-versions = ">=3.7" + +[package.extras] +docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "rst.linker (>=1.9)", "sphinx", "sphinx-favicon", "sphinx-hoverxref (<2)", "sphinx-inline-tabs", "sphinx-notfound-page (==0.8.3)", "sphinx-reredirects", "sphinxcontrib-towncrier"] +testing = ["build[virtualenv]", "filelock (>=3.4.0)", "flake8 (<5)", "flake8-2020", "ini2toml[lite] (>=0.9)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "mock", "pip (>=19.1)", "pip-run (>=8.8)", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-flake8", "pytest-mypy (>=0.9.1)", "pytest-perf", "pytest-xdist", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"] +testing-integration = ["build[virtualenv]", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"] + [[package]] name = "six" version = "1.16.0" @@ -729,8 +745,8 @@ optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, <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", "urllib3-secure-extra", "ipaddress"] +brotli = ["brotli (>=1.0.9)", "brotlicffi (>=0.8.0)", "brotlipy (>=0.6.0)"] +secure = ["certifi", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "ipaddress", "pyOpenSSL (>=0.14)", "urllib3-secure-extra"] socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"] [[package]] @@ -750,7 +766,7 @@ standard = ["colorama (>=0.4)", "httptools (>=0.4.0)", "python-dotenv (>=0.13)", [[package]] name = "virtualenv" -version = "20.16.4" +version = "20.16.5" description = "Virtual Python Environment builder" category = "dev" optional = false @@ -783,10 +799,13 @@ python-versions = "^3.8" content-hash = "3c10bbdb2edc9f8516ba779200445d33dcd8e2e800922826b6a983306ec9015c" [metadata.files] -anyio = [] +anyio = [ + {file = "anyio-3.6.1-py3-none-any.whl", hash = "sha256:cb29b9c70620506a9a8f87a309591713446953302d7d995344d0d7c6c0c9a7be"}, + {file = "anyio-3.6.1.tar.gz", hash = "sha256:413adf95f93886e442aea925f3ee43baa5a765a64a0f52c6081894f9992fdd0b"}, +] astroid = [ - {file = "astroid-2.12.6-py3-none-any.whl", hash = "sha256:bf0fe7ff5d28f697f5eddc9f33140ad6086941c472f53e9dbbb9aaa6bc8952cb"}, - {file = "astroid-2.12.6.tar.gz", hash = "sha256:cfef6fa5aeba225d01f217e435472da458711bceb949c6eccb07dc93701edd29"}, + {file = "astroid-2.12.9-py3-none-any.whl", hash = "sha256:27a22f40e45af6d362498647a0940e8ae9c35f71cb572a1b6f8f810122a11918"}, + {file = "astroid-2.12.9.tar.gz", hash = "sha256:0dafbfcf4ebdecd3c8f6d742c9d9c88508229ca823d5c98ab872d964f3321e56"}, ] attrs = [ {file = "attrs-22.1.0-py2.py3-none-any.whl", hash = "sha256:86efa402f67bf2df34f51a335487cf46b1ec130d02b8d39fd248abfd30da551c"}, @@ -831,8 +850,8 @@ black = [ {file = "black-22.8.0.tar.gz", hash = "sha256:792f7eb540ba9a17e8656538701d3eb1afcb134e3b45b71f20b25c77a8db7e6e"}, ] certifi = [ - {file = "certifi-2022.6.15-py3-none-any.whl", hash = "sha256:fe86415d55e84719d75f8b69414f6438ac3547d2078ab91b67e779ef69378412"}, - {file = "certifi-2022.6.15.tar.gz", hash = "sha256:84c85a9078b11105f04f3036a9482ae10e4621616db313fe045dd24743a0820d"}, + {file = "certifi-2022.6.15.1-py3-none-any.whl", hash = "sha256:43dadad18a7f168740e66944e4fa82c6611848ff9056ad910f8f7a3e46ab89e0"}, + {file = "certifi-2022.6.15.1.tar.gz", hash = "sha256:cffdcd380919da6137f76633531a5817e3a9f268575c128249fb637e4f9e73fb"}, ] cffi = [ {file = "cffi-1.15.1-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:a66d3508133af6e8548451b25058d5812812ec3798c886bf38ed24a98216fab2"}, @@ -964,10 +983,13 @@ filelock = [ {file = "filelock-3.8.0-py3-none-any.whl", hash = "sha256:617eb4e5eedc82fc5f47b6d61e4d11cb837c56cb4544e39081099fa17ad109d4"}, {file = "filelock-3.8.0.tar.gz", hash = "sha256:55447caa666f2198c5b6b13a26d2084d26fa5b115c00d065664b2124680c4edc"}, ] -h11 = [] +h11 = [ + {file = "h11-0.13.0-py3-none-any.whl", hash = "sha256:8ddd78563b633ca55346c8cd41ec0af27d3c79931828beffb46ce70a379e7442"}, + {file = "h11-0.13.0.tar.gz", hash = "sha256:70813c1135087a248a4d38cc0e1a0181ffab2188141a93eaf567940c3957ff06"}, +] identify = [ - {file = "identify-2.5.4-py2.py3-none-any.whl", hash = "sha256:962d9bec27ccd1fcceff9b11f8c635afeb163ea3d8b6b30d8f1eee37ec7fac47"}, - {file = "identify-2.5.4.tar.gz", hash = "sha256:b020e876cec2b11dadb3324fa0427eb744b7d66ef19ac579a748dfff774b6dcf"}, + {file = "identify-2.5.5-py2.py3-none-any.whl", hash = "sha256:ef78c0d96098a3b5fe7720be4a97e73f439af7cf088ebf47b620aeaa10fadf97"}, + {file = "identify-2.5.5.tar.gz", hash = "sha256:322a5699daecf7c6fd60e68852f36f2ecbb6a36ff6e6e973e0d2bb6fca203ee6"}, ] idna = [ {file = "idna-3.3-py3-none-any.whl", hash = "sha256:84d9dd047ffa80596e0f246e2eab0b391788b0503584e8945f2368256d2735ff"}, @@ -1033,34 +1055,34 @@ nodeenv = [ {file = "nodeenv-1.7.0.tar.gz", hash = "sha256:e0e7f7dfb85fc5394c6fe1e8fa98131a2473e04311a45afb6508f7cf1836fa2b"}, ] numpy = [ - {file = "numpy-1.23.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:e603ca1fb47b913942f3e660a15e55a9ebca906857edfea476ae5f0fe9b457d5"}, - {file = "numpy-1.23.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:633679a472934b1c20a12ed0c9a6c9eb167fbb4cb89031939bfd03dd9dbc62b8"}, - {file = "numpy-1.23.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:17e5226674f6ea79e14e3b91bfbc153fdf3ac13f5cc54ee7bc8fdbe820a32da0"}, - {file = "numpy-1.23.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bdc02c0235b261925102b1bd586579b7158e9d0d07ecb61148a1799214a4afd5"}, - {file = "numpy-1.23.2-cp310-cp310-win32.whl", hash = "sha256:df28dda02c9328e122661f399f7655cdcbcf22ea42daa3650a26bce08a187450"}, - {file = "numpy-1.23.2-cp310-cp310-win_amd64.whl", hash = "sha256:8ebf7e194b89bc66b78475bd3624d92980fca4e5bb86dda08d677d786fefc414"}, - {file = "numpy-1.23.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:dc76bca1ca98f4b122114435f83f1fcf3c0fe48e4e6f660e07996abf2f53903c"}, - {file = "numpy-1.23.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:ecfdd68d334a6b97472ed032b5b37a30d8217c097acfff15e8452c710e775524"}, - {file = "numpy-1.23.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5593f67e66dea4e237f5af998d31a43e447786b2154ba1ad833676c788f37cde"}, - {file = "numpy-1.23.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ac987b35df8c2a2eab495ee206658117e9ce867acf3ccb376a19e83070e69418"}, - {file = "numpy-1.23.2-cp311-cp311-win32.whl", hash = "sha256:d98addfd3c8728ee8b2c49126f3c44c703e2b005d4a95998e2167af176a9e722"}, - {file = "numpy-1.23.2-cp311-cp311-win_amd64.whl", hash = "sha256:8ecb818231afe5f0f568c81f12ce50f2b828ff2b27487520d85eb44c71313b9e"}, - {file = "numpy-1.23.2-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:909c56c4d4341ec8315291a105169d8aae732cfb4c250fbc375a1efb7a844f8f"}, - {file = "numpy-1.23.2-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:8247f01c4721479e482cc2f9f7d973f3f47810cbc8c65e38fd1bbd3141cc9842"}, - {file = "numpy-1.23.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b8b97a8a87cadcd3f94659b4ef6ec056261fa1e1c3317f4193ac231d4df70215"}, - {file = "numpy-1.23.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bd5b7ccae24e3d8501ee5563e82febc1771e73bd268eef82a1e8d2b4d556ae66"}, - {file = "numpy-1.23.2-cp38-cp38-win32.whl", hash = "sha256:9b83d48e464f393d46e8dd8171687394d39bc5abfe2978896b77dc2604e8635d"}, - {file = "numpy-1.23.2-cp38-cp38-win_amd64.whl", hash = "sha256:dec198619b7dbd6db58603cd256e092bcadef22a796f778bf87f8592b468441d"}, - {file = "numpy-1.23.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:4f41f5bf20d9a521f8cab3a34557cd77b6f205ab2116651f12959714494268b0"}, - {file = "numpy-1.23.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:806cc25d5c43e240db709875e947076b2826f47c2c340a5a2f36da5bb10c58d6"}, - {file = "numpy-1.23.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8f9d84a24889ebb4c641a9b99e54adb8cab50972f0166a3abc14c3b93163f074"}, - {file = "numpy-1.23.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c403c81bb8ffb1c993d0165a11493fd4bf1353d258f6997b3ee288b0a48fce77"}, - {file = "numpy-1.23.2-cp39-cp39-win32.whl", hash = "sha256:cf8c6aed12a935abf2e290860af8e77b26a042eb7f2582ff83dc7ed5f963340c"}, - {file = "numpy-1.23.2-cp39-cp39-win_amd64.whl", hash = "sha256:5e28cd64624dc2354a349152599e55308eb6ca95a13ce6a7d5679ebff2962913"}, - {file = "numpy-1.23.2-pp38-pypy38_pp73-macosx_10_9_x86_64.whl", hash = "sha256:806970e69106556d1dd200e26647e9bee5e2b3f1814f9da104a943e8d548ca38"}, - {file = "numpy-1.23.2-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2bd879d3ca4b6f39b7770829f73278b7c5e248c91d538aab1e506c628353e47f"}, - {file = "numpy-1.23.2-pp38-pypy38_pp73-win_amd64.whl", hash = "sha256:be6b350dfbc7f708d9d853663772a9310783ea58f6035eec649fb9c4371b5389"}, - {file = "numpy-1.23.2.tar.gz", hash = "sha256:b78d00e48261fbbd04aa0d7427cf78d18401ee0abd89c7559bbf422e5b1c7d01"}, + {file = "numpy-1.23.3-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:c9f707b5bb73bf277d812ded9896f9512a43edff72712f31667d0a8c2f8e71ee"}, + {file = "numpy-1.23.3-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:ffcf105ecdd9396e05a8e58e81faaaf34d3f9875f137c7372450baa5d77c9a54"}, + {file = "numpy-1.23.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0ea3f98a0ffce3f8f57675eb9119f3f4edb81888b6874bc1953f91e0b1d4f440"}, + {file = "numpy-1.23.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:004f0efcb2fe1c0bd6ae1fcfc69cc8b6bf2407e0f18be308612007a0762b4089"}, + {file = "numpy-1.23.3-cp310-cp310-win32.whl", hash = "sha256:98dcbc02e39b1658dc4b4508442a560fe3ca5ca0d989f0df062534e5ca3a5c1a"}, + {file = "numpy-1.23.3-cp310-cp310-win_amd64.whl", hash = "sha256:39a664e3d26ea854211867d20ebcc8023257c1800ae89773cbba9f9e97bae036"}, + {file = "numpy-1.23.3-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:1f27b5322ac4067e67c8f9378b41c746d8feac8bdd0e0ffede5324667b8a075c"}, + {file = "numpy-1.23.3-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:2ad3ec9a748a8943e6eb4358201f7e1c12ede35f510b1a2221b70af4bb64295c"}, + {file = "numpy-1.23.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:bdc9febce3e68b697d931941b263c59e0c74e8f18861f4064c1f712562903411"}, + {file = "numpy-1.23.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:301c00cf5e60e08e04d842fc47df641d4a181e651c7135c50dc2762ffe293dbd"}, + {file = "numpy-1.23.3-cp311-cp311-win32.whl", hash = "sha256:7cd1328e5bdf0dee621912f5833648e2daca72e3839ec1d6695e91089625f0b4"}, + {file = "numpy-1.23.3-cp311-cp311-win_amd64.whl", hash = "sha256:8355fc10fd33a5a70981a5b8a0de51d10af3688d7a9e4a34fcc8fa0d7467bb7f"}, + {file = "numpy-1.23.3-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:bc6e8da415f359b578b00bcfb1d08411c96e9a97f9e6c7adada554a0812a6cc6"}, + {file = "numpy-1.23.3-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:22d43376ee0acd547f3149b9ec12eec2f0ca4a6ab2f61753c5b29bb3e795ac4d"}, + {file = "numpy-1.23.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a64403f634e5ffdcd85e0b12c08f04b3080d3e840aef118721021f9b48fc1460"}, + {file = "numpy-1.23.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:efd9d3abe5774404becdb0748178b48a218f1d8c44e0375475732211ea47c67e"}, + {file = "numpy-1.23.3-cp38-cp38-win32.whl", hash = "sha256:f8c02ec3c4c4fcb718fdf89a6c6f709b14949408e8cf2a2be5bfa9c49548fd85"}, + {file = "numpy-1.23.3-cp38-cp38-win_amd64.whl", hash = "sha256:e868b0389c5ccfc092031a861d4e158ea164d8b7fdbb10e3b5689b4fc6498df6"}, + {file = "numpy-1.23.3-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:09f6b7bdffe57fc61d869a22f506049825d707b288039d30f26a0d0d8ea05164"}, + {file = "numpy-1.23.3-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:8c79d7cf86d049d0c5089231a5bcd31edb03555bd93d81a16870aa98c6cfb79d"}, + {file = "numpy-1.23.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e5d5420053bbb3dd64c30e58f9363d7a9c27444c3648e61460c1237f9ec3fa14"}, + {file = "numpy-1.23.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d5422d6a1ea9b15577a9432e26608c73a78faf0b9039437b075cf322c92e98e7"}, + {file = "numpy-1.23.3-cp39-cp39-win32.whl", hash = "sha256:c1ba66c48b19cc9c2975c0d354f24058888cdc674bebadceb3cdc9ec403fb5d1"}, + {file = "numpy-1.23.3-cp39-cp39-win_amd64.whl", hash = "sha256:78a63d2df1d947bd9d1b11d35564c2f9e4b57898aae4626638056ec1a231c40c"}, + {file = "numpy-1.23.3-pp38-pypy38_pp73-macosx_10_9_x86_64.whl", hash = "sha256:17c0e467ade9bda685d5ac7f5fa729d8d3e76b23195471adae2d6a6941bd2c18"}, + {file = "numpy-1.23.3-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:91b8d6768a75247026e951dce3b2aac79dc7e78622fc148329135ba189813584"}, + {file = "numpy-1.23.3-pp38-pypy38_pp73-win_amd64.whl", hash = "sha256:94c15ca4e52671a59219146ff584488907b1f9b3fc232622b47e2cf832e94fb8"}, + {file = "numpy-1.23.3.tar.gz", hash = "sha256:51bf49c0cd1d52be0a240aa66f3458afc4b95d8993d2d04f0d91fa60c10af6cd"}, ] openpyxl = [ {file = "openpyxl-3.0.10-py2.py3-none-any.whl", hash = "sha256:0ab6d25d01799f97a9464630abacbb34aafecdcaa0ef3cba6d6b3499867d0355"}, @@ -1223,10 +1245,10 @@ pydantic = [ {file = "pydantic-1.10.2.tar.gz", hash = "sha256:91b8e218852ef6007c2b98cd861601c6a09f1aa32bbbb74fab5b1c33d4a1e410"}, ] pylint = [ - {file = "pylint-2.15.0-py3-none-any.whl", hash = "sha256:4b124affc198b7f7c9b5f9ab690d85db48282a025ef9333f51d2d7281b92a6c3"}, - {file = "pylint-2.15.0.tar.gz", hash = "sha256:4f3f7e869646b0bd63b3dfb79f3c0f28fc3d2d923ea220d52620fd625aed92b0"}, + {file = "pylint-2.15.2-py3-none-any.whl", hash = "sha256:cc3da458ba810c49d330e09013dec7ced5217772dec8f043ccdd34dae648fde8"}, + {file = "pylint-2.15.2.tar.gz", hash = "sha256:f63404a2547edb5247da263748771ac9a806ed1de4174cda01293c08ddbc2999"}, ] -pymysql = [ +PyMySQL = [ {file = "PyMySQL-1.0.2-py3-none-any.whl", hash = "sha256:41fc3a0c5013d5f039639442321185532e3e2c8924687abe6537de157d403641"}, {file = "PyMySQL-1.0.2.tar.gz", hash = "sha256:816927a350f38d56072aeca5dfb10221fe1dc653745853d30a216637f5d7ad36"}, ] @@ -1300,7 +1322,7 @@ pytz = [ {file = "pytz-2022.2.1-py2.py3-none-any.whl", hash = "sha256:220f481bdafa09c3955dfbdddb7b57780e9a94f5127e35456a48589b9e0c0197"}, {file = "pytz-2022.2.1.tar.gz", hash = "sha256:cea221417204f2d1a2aa03ddae3e867921971d0d76f14d87abb4414415bbdcf5"}, ] -pyyaml = [ +PyYAML = [ {file = "PyYAML-6.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:d4db7c7aef085872ef65a8fd7d6d09a14ae91f691dec3e87ee5ee0539d516f53"}, {file = "PyYAML-6.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:9df7ed3b3d2e0ecfe09e14741b857df43adb5a3ddadc919a2d94fbdf78fea53c"}, {file = "PyYAML-6.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:77f396e6ef4c73fdc33a9157446466f1cff553d979bd00ecb64385760c6babdc"}, @@ -1343,6 +1365,10 @@ rsa = [ {file = "rsa-4.9-py3-none-any.whl", hash = "sha256:90260d9058e514786967344d0ef75fa8727eed8a7d2e43ce9f4bcf1b536174f7"}, {file = "rsa-4.9.tar.gz", hash = "sha256:e38464a49c6c85d7f1351b0126661487a7e0a14a50f1675ec50eb34d4f20ef21"}, ] +setuptools = [ + {file = "setuptools-65.3.0-py3-none-any.whl", hash = "sha256:2e24e0bec025f035a2e72cdd1961119f557d78ad331bb00ff82efb2ab8da8e82"}, + {file = "setuptools-65.3.0.tar.gz", hash = "sha256:7732871f4f7fa58fb6bdcaeadb0161b2bd046c85905dbaa066bdcbcc81953b57"}, +] six = [ {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"}, {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"}, @@ -1351,7 +1377,10 @@ sniffio = [ {file = "sniffio-1.3.0-py3-none-any.whl", hash = "sha256:eecefdce1e5bbfb7ad2eeaabf7c1eeb404d7757c379bd1f7e5cce9d8bf425384"}, {file = "sniffio-1.3.0.tar.gz", hash = "sha256:e60305c5e5d314f5389259b7f22aaa33d8f7dee49763119234af3755c55b9101"}, ] -starlette = [] +starlette = [ + {file = "starlette-0.19.1-py3-none-any.whl", hash = "sha256:5a60c5c2d051f3a8eb546136aa0c9399773a689595e099e0877704d5888279bf"}, + {file = "starlette-0.19.1.tar.gz", hash = "sha256:c6d21096774ecb9639acad41b86b7706e52ba3bf1dc13ea4ed9ad593d47e24c7"}, +] toml = [ {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, @@ -1377,8 +1406,8 @@ uvicorn = [ {file = "uvicorn-0.18.3.tar.gz", hash = "sha256:9a66e7c42a2a95222f76ec24a4b754c158261c4696e683b9dadc72b590e0311b"}, ] virtualenv = [ - {file = "virtualenv-20.16.4-py3-none-any.whl", hash = "sha256:035ed57acce4ac35c82c9d8802202b0e71adac011a511ff650cbcf9635006a22"}, - {file = "virtualenv-20.16.4.tar.gz", hash = "sha256:014f766e4134d0008dcaa1f95bafa0fb0f575795d07cae50b1bee514185d6782"}, + {file = "virtualenv-20.16.5-py3-none-any.whl", hash = "sha256:d07dfc5df5e4e0dbc92862350ad87a36ed505b978f6c39609dc489eadd5b0d27"}, + {file = "virtualenv-20.16.5.tar.gz", hash = "sha256:227ea1b9994fdc5ea31977ba3383ef296d7472ea85be9d6732e42a91c04e80da"}, ] wrapt = [ {file = "wrapt-1.14.1-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:1b376b3f4896e7930f1f772ac4b064ac12598d1c38d04907e696cc4d794b43d3"}, From 67b51a59990af3c72dba76a76d7f59d5167eb1fc Mon Sep 17 00:00:00 2001 From: Thaza_Kun <61819672+Thaza-Kun@users.noreply.github.com> Date: Tue, 13 Sep 2022 13:22:39 +0800 Subject: [PATCH 02/11] feat: added query filters and parameters --- samudra/core/crud/lemma.py | 35 ++++++--- samudra/schemas/input/query_filter.py | 9 +++ samudra/server/routes/lemmas.py | 29 +++++-- samudra/server/setup.py | 3 + tests/test_crud.py | 109 +++++++++++++++++--------- 5 files changed, 133 insertions(+), 52 deletions(-) create mode 100644 samudra/schemas/input/query_filter.py diff --git a/samudra/core/crud/lemma.py b/samudra/core/crud/lemma.py index 5e40831..dac8876 100644 --- a/samudra/core/crud/lemma.py +++ b/samudra/core/crud/lemma.py @@ -3,6 +3,7 @@ from peewee import prefetch from samudra import models +from schemas.input.query_filter import QueryFilter def create_lemma(lemma: str, safe: bool = True) -> models.Lemma: @@ -12,30 +13,44 @@ def create_lemma(lemma: str, safe: bool = True) -> models.Lemma: def get_lemma_minimum_info( - where: Any, limit: Optional[int] = None + query: Optional[QueryFilter] = None, where: Any = None ) -> List[models.Lemma]: - stmt = models.Lemma.select(models.Lemma).where(where).limit(limit) + query: QueryFilter = QueryFilter(**query.dict()) + stmt = models.Lemma.select().where(where) + to_return = prefetch( stmt, models.Konsep, models.CakupanXKonsep, - models.Cakupan, + models.Cakupan.select().where( + ( + models.Cakupan.nama.in_(query.cakupan) + if query.cakupan is not None + else None + ) + ), models.KataAsingXKonsep, - models.KataAsing, + models.KataAsing.select().where( + ( + models.KataAsing.nama.in_(query.kata_asing) + if query.kata_asing is not None + else None + ) + ), ) return to_return -def get_lemma(limit: int = 10) -> List[models.Lemma]: - return get_lemma_minimum_info(where=None, limit=limit) +def get_lemma(query: QueryFilter) -> List[models.Lemma]: + return get_lemma_minimum_info(query=query) -def get_lemma_by_name(nama: str, limit: int = 1) -> List[models.Lemma]: - return get_lemma_minimum_info(where=models.Lemma.nama == nama, limit=limit) +def get_lemma_by_name(nama: str, query: QueryFilter) -> List[models.Lemma]: + return get_lemma_minimum_info(where=models.Lemma.nama == nama, query=query) -def get_lemma_by_id(lemma_id: int, limit: Optional[int] = None) -> List[models.Lemma]: - return get_lemma_minimum_info(where=(models.Lemma.id == lemma_id), limit=limit) +def get_lemma_by_id(lemma_id: int, query: QueryFilter) -> List[models.Lemma]: + return get_lemma_minimum_info(where=(models.Lemma.id == lemma_id), query=query) def delete_lemma(lemma: models.Lemma) -> int: diff --git a/samudra/schemas/input/query_filter.py b/samudra/schemas/input/query_filter.py new file mode 100644 index 0000000..b83639f --- /dev/null +++ b/samudra/schemas/input/query_filter.py @@ -0,0 +1,9 @@ +from typing import List, Optional + +import pydantic as pyd + + +class QueryFilter(pyd.BaseModel): + limit: Optional[int] + cakupan: Optional[List[str]] + kata_asing: Optional[List[str]] diff --git a/samudra/server/routes/lemmas.py b/samudra/server/routes/lemmas.py index ba96784..a70ab02 100644 --- a/samudra/server/routes/lemmas.py +++ b/samudra/server/routes/lemmas.py @@ -1,24 +1,39 @@ -from typing import List, Union, Dict +from typing import List, Union, Dict, Optional import pydantic -from fastapi import APIRouter, Depends, HTTPException +from fastapi import APIRouter, Depends, HTTPException, Query from samudra import models, schemas from samudra.core import crud from samudra.server.dependencies import get_db +from schemas.input.query_filter import QueryFilter from server.dependencies import oauth2_scheme router = APIRouter(prefix="/lemma", dependencies=[Depends(get_db)]) @router.get("/", response_model=List[schemas.LemmaResponse]) -def get_all_lemma(limit: int = None) -> List[models.Lemma]: - return crud.get_lemma(limit=limit) +def get_all_lemma( + limit: Optional[int] = Query(default=None), + cakupan: Optional[List[str]] = Query(default=None), + kata_asing: Optional[List[str]] = Query(default=None), +) -> List[models.Lemma]: + return crud.get_lemma( + QueryFilter(limit=limit, cakupan=cakupan, kata_asing=kata_asing) + ) @router.get("/{nama}", response_model=List[schemas.LemmaResponse]) -def read_lemma(nama: str) -> List[models.Lemma]: - db_lemma = crud.get_lemma_by_name(nama=nama) +def read_lemma( + nama: str, + limit: Optional[int] = Query(default=None), + cakupan: Optional[List[str]] = Query(default=None), + kata_asing: Optional[List[str]] = Query(default=None), +) -> List[models.Lemma]: + db_lemma = crud.get_lemma_by_name( + nama=nama, + query=QueryFilter(limit=limit, cakupan=cakupan, kata_asing=kata_asing), + ) if db_lemma is None: raise HTTPException(status_code=404, detail="Lemma not in record") return db_lemma @@ -26,7 +41,7 @@ def read_lemma(nama: str) -> List[models.Lemma]: @router.post("/{nama}", response_model=schemas.KonsepResponseFromAnnotatedBody) def create_lemma( - nama: str, post: schemas.AnnotatedText, token: str = Depends(oauth2_scheme) + nama: str, post: schemas.AnnotatedText, token: str = Depends(oauth2_scheme) ) -> Union[models.Konsep, schemas.AnnotatedText]: try: to_return = crud.create_konsep(post, lemma_name=nama) diff --git a/samudra/server/setup.py b/samudra/server/setup.py index 6522177..260ebcc 100644 --- a/samudra/server/setup.py +++ b/samudra/server/setup.py @@ -6,6 +6,9 @@ from samudra.conf import Database +# TODO Refactor Database.connection to decouple dependency on conf + + def check_tables(create_tables: bool = False) -> None: for TABLE in models.TABLES: if Database.connection.table_exists(TABLE): diff --git a/tests/test_crud.py b/tests/test_crud.py index 4defe7c..5fa41b8 100644 --- a/tests/test_crud.py +++ b/tests/test_crud.py @@ -7,6 +7,7 @@ from samudra.core.crud.konsep import create_konsep, get_konsep_minimum_info from samudra.core.crud.lemma import get_lemma_minimum_info from samudra.schemas import AnnotatedText, CreateGolonganKata +from schemas.input.query_filter import QueryFilter from tests import mocks from passlib.context import CryptContext @@ -15,44 +16,63 @@ # TODO create wrappers for setup of each crud test + @mocks.bind_test_database def test_create_golongan_kata(): - data = CreateGolonganKata(id='nama', nama='kata nama', keterangan='kata yang digunakan untuk merujuk kepada benda.') + data = CreateGolonganKata( + id="nama", + nama="kata nama", + keterangan="kata yang digunakan untuk merujuk kepada benda.", + ) create_golongan_kata(data=data) - gol = models.GolonganKata.get_or_none(id='NAMA') - assert gol.id == 'NAMA' - assert gol.nama == 'Kata Nama' + gol = models.GolonganKata.get_or_none(id="NAMA") + assert gol.id == "NAMA" + assert gol.nama == "Kata Nama" @mocks.bind_test_database def test_create_golongan_kata_w_value_error(): with pytest.raises(ValueError): - CreateGolonganKata(id='namayasa', nama='kata nama', - keterangan='kata yang digunakan untuk merujuk kepada benda.') + CreateGolonganKata( + id="namayasa", + nama="kata nama", + keterangan="kata yang digunakan untuk merujuk kepada benda.", + ) @mocks.bind_test_database def test_create_konsep(): data = AnnotatedText(body=DATA_1) - create_golongan_kata(data=CreateGolonganKata(id='NAMA', nama='kata nama', - keterangan='kata yang digunakan untuk merujuk kepada benda.')) - konsep = create_konsep(annotated_text=data, lemma_name='ujian') + create_golongan_kata( + data=CreateGolonganKata( + id="NAMA", + nama="kata nama", + keterangan="kata yang digunakan untuk merujuk kepada benda.", + ) + ) + konsep = create_konsep(annotated_text=data, lemma_name="ujian") assert konsep.keterangan == "Ini adalah konsep cubaan" - assert konsep.cakupan[0].cakupan.nama == 'tag 1' - assert konsep.cakupan[1].cakupan.nama == 'tag-2' + assert konsep.cakupan[0].cakupan.nama == "tag 1" + assert konsep.cakupan[1].cakupan.nama == "tag-2" @mocks.bind_test_database def test_create_konsep_attachment_with_error(): data = AnnotatedText(body=DATA_1) - create_golongan_kata(data=CreateGolonganKata(id='NAMA', nama='kata nama', - keterangan='kata yang digunakan untuk merujuk kepada benda.')) + create_golongan_kata( + data=CreateGolonganKata( + id="NAMA", + nama="kata nama", + keterangan="kata yang digunakan untuk merujuk kepada benda.", + ) + ) from samudra.models import Cakupan + old_attr = Cakupan.connection_table try: - delattr(Cakupan, 'connection_table') + delattr(Cakupan, "connection_table") with pytest.raises(AttributeError): - create_konsep(annotated_text=data, lemma_name='ujian') + create_konsep(annotated_text=data, lemma_name="ujian") finally: # Properly restore attr for other tests Cakupan.connection_table = old_attr @@ -60,14 +80,18 @@ def test_create_konsep_attachment_with_error(): @mocks.bind_test_database def test_get_minimum_lemma_info(): - from samudra.models import Lemma data = AnnotatedText(body=DATA_1) - create_golongan_kata(data=CreateGolonganKata(id='NAMA', nama='kata nama', - keterangan='kata yang digunakan untuk merujuk kepada benda.')) - create_konsep(annotated_text=data, lemma_name='ujian') - create_konsep(annotated_text=data, lemma_name='ujian') - lemma = get_lemma_minimum_info(where=(Lemma.nama == 'ujian'), limit=1)[0] - assert lemma.nama == 'ujian' + create_golongan_kata( + data=CreateGolonganKata( + id="NAMA", + nama="kata nama", + keterangan="kata yang digunakan untuk merujuk kepada benda.", + ) + ) + create_konsep(annotated_text=data, lemma_name="ujian") + create_konsep(annotated_text=data, lemma_name="ujian") + lemma = get_lemma_minimum_info(query=QueryFilter(limit=10))[0] + assert lemma.nama == "ujian" assert lemma.id == 1 assert len(lemma.konsep) == 2 @@ -75,9 +99,14 @@ def test_get_minimum_lemma_info(): @mocks.bind_test_database def test_get_minimum_konsep_info(): data = AnnotatedText(body=DATA_1) - create_golongan_kata(data=CreateGolonganKata(id='NAMA', nama='kata nama', - keterangan='kata yang digunakan untuk merujuk kepada benda.')) - create_konsep(annotated_text=data, lemma_name='ujian') + create_golongan_kata( + data=CreateGolonganKata( + id="NAMA", + nama="kata nama", + keterangan="kata yang digunakan untuk merujuk kepada benda.", + ) + ) + create_konsep(annotated_text=data, lemma_name="ujian") konsep = get_konsep_minimum_info(where=None, limit=None) assert konsep == list(models.Konsep) @@ -85,18 +114,28 @@ def test_get_minimum_konsep_info(): @mocks.bind_test_database def test_get_cakupan_by_name(): data = AnnotatedText(body=DATA_1) - create_golongan_kata(data=CreateGolonganKata(id='NAMA', nama='kata nama', - keterangan='kata yang digunakan untuk merujuk kepada benda.')) - create_konsep(annotated_text=data, lemma_name='ujian') - cakupan = get_cakupan_by_name(nama='tag 1') - assert cakupan[0].nama == 'tag 1' + create_golongan_kata( + data=CreateGolonganKata( + id="NAMA", + nama="kata nama", + keterangan="kata yang digunakan untuk merujuk kepada benda.", + ) + ) + create_konsep(annotated_text=data, lemma_name="ujian") + cakupan = get_cakupan_by_name(nama="tag 1") + assert cakupan[0].nama == "tag 1" @mocks.bind_test_database def test_get_kata_asing_by_name(): data = AnnotatedText(body=DATA_1) - create_golongan_kata(data=CreateGolonganKata(id='NAMA', nama='kata nama', - keterangan='kata yang digunakan untuk merujuk kepada benda.')) - create_konsep(annotated_text=data, lemma_name='ujian') - kata_asing = get_kata_asing_by_name(nama='concept') - assert kata_asing[0].nama == 'concept' + create_golongan_kata( + data=CreateGolonganKata( + id="NAMA", + nama="kata nama", + keterangan="kata yang digunakan untuk merujuk kepada benda.", + ) + ) + create_konsep(annotated_text=data, lemma_name="ujian") + kata_asing = get_kata_asing_by_name(nama="concept") + assert kata_asing[0].nama == "concept" From 5853958a9c0de4c92aa9d091e40e113b1849e38b Mon Sep 17 00:00:00 2001 From: Thaza_Kun <61819672+Thaza-Kun@users.noreply.github.com> Date: Tue, 13 Sep 2022 14:13:06 +0800 Subject: [PATCH 03/11] feat: export to requirements.txt --- requirements.txt | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..bf83d53 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,37 @@ +anyio==3.6.1 ; python_version >= "3.8" and python_version < "4.0" +bcrypt==3.2.2 ; python_version >= "3.8" and python_version < "4.0" +certifi==2022.6.15.1 ; python_version >= "3.8" and python_version < "4" +cffi==1.15.1 ; python_version >= "3.8" and python_version < "4.0" +charset-normalizer==2.1.1 ; python_version >= "3.8" and python_version < "4" +click==8.1.3 ; python_version >= "3.8" and python_version < "4.0" +colorama==0.4.5 ; python_version >= "3.8" and python_version < "4.0" and platform_system == "Windows" +cryptography==37.0.4 ; python_version >= "3.8" and python_version < "4.0" +ecdsa==0.18.0 ; python_version >= "3.8" and python_version < "4.0" +et-xmlfile==1.1.0 ; python_version >= "3.8" and python_version < "4.0" +fastapi==0.79.1 ; python_version >= "3.8" and python_version < "4.0" +h11==0.13.0 ; python_version >= "3.8" and python_version < "4.0" +idna==3.3 ; python_version >= "3.8" and python_version < "4" +numpy==1.23.3 ; python_version < "4.0" and python_version >= "3.8" +openpyxl==3.0.10 ; python_version >= "3.8" and python_version < "4.0" +pandas==1.4.4 ; python_version >= "3.8" and python_version < "4.0" +passlib==1.7.4 ; python_version >= "3.8" and python_version < "4.0" +peewee==3.15.2 ; python_version >= "3.8" and python_version < "4.0" +pyasn1==0.4.8 ; python_version >= "3.8" and python_version < "4.0" +pycparser==2.21 ; python_version >= "3.8" and python_version < "4.0" +pycryptodome==3.15.0 ; python_version >= "3.8" and python_version < "4.0" +pydantic==1.10.2 ; python_version >= "3.8" and python_version < "4.0" +pymysql==1.0.2 ; python_version >= "3.8" and python_version < "4.0" +python-dateutil==2.8.2 ; python_version >= "3.8" and python_version < "4.0" +python-dotenv==0.20.0 ; python_version >= "3.8" and python_version < "4.0" +python-jose==3.3.0 ; python_version >= "3.8" and python_version < "4.0" +python-multipart==0.0.5 ; python_version >= "3.8" and python_version < "4.0" +pytomlpp==1.0.11 ; python_version >= "3.8" and python_version < "4.0" +pytz==2022.2.1 ; python_version >= "3.8" and python_version < "4.0" +requests==2.28.1 ; python_version >= "3.8" and python_version < "4" +rsa==4.9 ; python_version >= "3.8" and python_version < "4" +six==1.16.0 ; python_version >= "3.8" and python_version < "4.0" +sniffio==1.3.0 ; python_version >= "3.8" and python_version < "4.0" +starlette==0.19.1 ; python_version >= "3.8" and python_version < "4.0" +typing-extensions==4.3.0 ; python_version >= "3.8" and python_version < "4.0" +urllib3==1.26.12 ; python_version >= "3.8" and python_version < "4" +uvicorn==0.18.3 ; python_version >= "3.8" and python_version < "4.0" From 49dd4182425451e0d420b7ec80cf6ca7587c04e7 Mon Sep 17 00:00:00 2001 From: Thaza_Kun <61819672+Thaza-Kun@users.noreply.github.com> Date: Tue, 27 Sep 2022 13:57:31 +0800 Subject: [PATCH 04/11] refactor: cleanup API routes --- poetry.lock | 105 ++++++++++++++----------- samudra/serve.py | 4 +- samudra/server/__init__.py | 2 +- samudra/server/routes/auth.py | 55 +++++++++++++ samudra/server/routes/golongan_kata.py | 8 +- samudra/server/tokens.py | 26 ++++++ tests/mocks.py | 4 +- tests/test_routes.py | 12 +++ 8 files changed, 162 insertions(+), 54 deletions(-) create mode 100644 samudra/server/routes/auth.py create mode 100644 samudra/server/tokens.py create mode 100644 tests/test_routes.py diff --git a/poetry.lock b/poetry.lock index 7ae42f8..8841aa6 100644 --- a/poetry.lock +++ b/poetry.lock @@ -17,7 +17,7 @@ trio = ["trio (>=0.16)"] [[package]] name = "astroid" -version = "2.12.9" +version = "2.12.10" description = "An abstract syntax tree for Python with inference support." category = "dev" optional = false @@ -84,7 +84,7 @@ uvloop = ["uvloop (>=0.15.2)"] [[package]] name = "certifi" -version = "2022.6.15.1" +version = "2022.9.24" description = "Python package for providing Mozilla's CA Bundle." category = "main" optional = false @@ -232,11 +232,11 @@ testing = ["covdefaults (>=2.2)", "coverage (>=6.4.2)", "pytest (>=7.1.2)", "pyt [[package]] name = "h11" -version = "0.13.0" +version = "0.14.0" description = "A pure-Python, bring-your-own-I/O implementation of HTTP/1.1" category = "main" optional = false -python-versions = ">=3.6" +python-versions = ">=3.7" [[package]] name = "identify" @@ -251,7 +251,7 @@ license = ["ukkonen"] [[package]] name = "idna" -version = "3.3" +version = "3.4" description = "Internationalized Domain Names in Applications (IDNA)" category = "main" optional = false @@ -346,7 +346,7 @@ pyparsing = ">=2.0.2,<3.0.5 || >3.0.5" [[package]] name = "pandas" -version = "1.4.4" +version = "1.5.0" description = "Powerful data structures for data analysis, time series, and statistics" category = "main" optional = false @@ -354,10 +354,8 @@ python-versions = ">=3.8" [package.dependencies] numpy = [ - {version = ">=1.18.5", markers = "platform_machine != \"aarch64\" and platform_machine != \"arm64\" and python_version < \"3.10\""}, - {version = ">=1.19.2", markers = "platform_machine == \"aarch64\" and python_version < \"3.10\""}, - {version = ">=1.20.0", markers = "platform_machine == \"arm64\" and python_version < \"3.10\""}, {version = ">=1.21.0", markers = "python_version >= \"3.10\""}, + {version = ">=1.20.3", markers = "python_version < \"3.10\""}, ] python-dateutil = ">=2.8.1" pytz = ">=2020.1" @@ -389,7 +387,7 @@ python-versions = ">=3.7" [[package]] name = "peewee" -version = "3.15.2" +version = "3.15.3" description = "a little orm" category = "main" optional = false @@ -492,14 +490,14 @@ email = ["email-validator (>=1.0.3)"] [[package]] name = "pylint" -version = "2.15.2" +version = "2.15.3" description = "python code static checker" category = "dev" optional = false python-versions = ">=3.7.2" [package.dependencies] -astroid = ">=2.12.9,<=2.14.0-dev0" +astroid = ">=2.12.10,<=2.14.0-dev0" colorama = {version = ">=0.4.5", markers = "sys_platform == \"win32\""} dill = ">=0.2" isort = ">=4.2.5,<6" @@ -662,7 +660,7 @@ pyasn1 = ">=0.1.3" [[package]] name = "setuptools" -version = "65.3.0" +version = "65.4.0" description = "Easily download, build, install, upgrade, and uninstall Python packages" category = "dev" optional = false @@ -804,8 +802,8 @@ anyio = [ {file = "anyio-3.6.1.tar.gz", hash = "sha256:413adf95f93886e442aea925f3ee43baa5a765a64a0f52c6081894f9992fdd0b"}, ] astroid = [ - {file = "astroid-2.12.9-py3-none-any.whl", hash = "sha256:27a22f40e45af6d362498647a0940e8ae9c35f71cb572a1b6f8f810122a11918"}, - {file = "astroid-2.12.9.tar.gz", hash = "sha256:0dafbfcf4ebdecd3c8f6d742c9d9c88508229ca823d5c98ab872d964f3321e56"}, + {file = "astroid-2.12.10-py3-none-any.whl", hash = "sha256:997e0c735df60d4a4caff27080a3afc51f9bdd693d3572a4a0b7090b645c36c5"}, + {file = "astroid-2.12.10.tar.gz", hash = "sha256:81f870105d892e73bf535da77a8261aa5bde838fa4ed12bb2f435291a098c581"}, ] attrs = [ {file = "attrs-22.1.0-py2.py3-none-any.whl", hash = "sha256:86efa402f67bf2df34f51a335487cf46b1ec130d02b8d39fd248abfd30da551c"}, @@ -850,8 +848,8 @@ black = [ {file = "black-22.8.0.tar.gz", hash = "sha256:792f7eb540ba9a17e8656538701d3eb1afcb134e3b45b71f20b25c77a8db7e6e"}, ] certifi = [ - {file = "certifi-2022.6.15.1-py3-none-any.whl", hash = "sha256:43dadad18a7f168740e66944e4fa82c6611848ff9056ad910f8f7a3e46ab89e0"}, - {file = "certifi-2022.6.15.1.tar.gz", hash = "sha256:cffdcd380919da6137f76633531a5817e3a9f268575c128249fb637e4f9e73fb"}, + {file = "certifi-2022.9.24-py3-none-any.whl", hash = "sha256:90c1a32f1d68f940488354e36370f6cca89f0f106db09518524c88d6ed83f382"}, + {file = "certifi-2022.9.24.tar.gz", hash = "sha256:0d9c601124e5a6ba9712dbc60d9c53c21e34f5f641fe83002317394311bdce14"}, ] cffi = [ {file = "cffi-1.15.1-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:a66d3508133af6e8548451b25058d5812812ec3798c886bf38ed24a98216fab2"}, @@ -984,16 +982,16 @@ filelock = [ {file = "filelock-3.8.0.tar.gz", hash = "sha256:55447caa666f2198c5b6b13a26d2084d26fa5b115c00d065664b2124680c4edc"}, ] h11 = [ - {file = "h11-0.13.0-py3-none-any.whl", hash = "sha256:8ddd78563b633ca55346c8cd41ec0af27d3c79931828beffb46ce70a379e7442"}, - {file = "h11-0.13.0.tar.gz", hash = "sha256:70813c1135087a248a4d38cc0e1a0181ffab2188141a93eaf567940c3957ff06"}, + {file = "h11-0.14.0-py3-none-any.whl", hash = "sha256:e3fe4ac4b851c468cc8363d500db52c2ead036020723024a109d37346efaa761"}, + {file = "h11-0.14.0.tar.gz", hash = "sha256:8f19fbbe99e72420ff35c00b27a34cb9937e902a8b810e2c88300c6f0a3b699d"}, ] identify = [ {file = "identify-2.5.5-py2.py3-none-any.whl", hash = "sha256:ef78c0d96098a3b5fe7720be4a97e73f439af7cf088ebf47b620aeaa10fadf97"}, {file = "identify-2.5.5.tar.gz", hash = "sha256:322a5699daecf7c6fd60e68852f36f2ecbb6a36ff6e6e973e0d2bb6fca203ee6"}, ] idna = [ - {file = "idna-3.3-py3-none-any.whl", hash = "sha256:84d9dd047ffa80596e0f246e2eab0b391788b0503584e8945f2368256d2735ff"}, - {file = "idna-3.3.tar.gz", hash = "sha256:9d643ff0a55b762d5cdb124b8eaa99c66322e2157b69160bc32796e824360e6d"}, + {file = "idna-3.4-py3-none-any.whl", hash = "sha256:90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2"}, + {file = "idna-3.4.tar.gz", hash = "sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4"}, ] iniconfig = [ {file = "iniconfig-1.1.1-py2.py3-none-any.whl", hash = "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3"}, @@ -1093,27 +1091,33 @@ packaging = [ {file = "packaging-21.3.tar.gz", hash = "sha256:dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb"}, ] pandas = [ - {file = "pandas-1.4.4-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:799e6a25932df7e6b1f8dabf63de064e2205dc309abb75956126a0453fd88e97"}, - {file = "pandas-1.4.4-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:7cd1d69a387f7d5e1a5a06a87574d9ef2433847c0e78113ab51c84d3a8bcaeaa"}, - {file = "pandas-1.4.4-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:94f2ed1fd51e545ebf71da1e942fe1822ee01e10d3dd2a7276d01351333b7c6b"}, - {file = "pandas-1.4.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4591cadd06fbbbd16fafc2de6e840c1aaefeae3d5864b688004777ef1bbdede3"}, - {file = "pandas-1.4.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d0022fe6a313df1c4869b5edc012d734c6519a6fffa3cf70930f32e6a1078e49"}, - {file = "pandas-1.4.4-cp310-cp310-win_amd64.whl", hash = "sha256:785e878a6e6d8ddcdb8c181e600855402750052497d7fc6d6b508894f6b8830b"}, - {file = "pandas-1.4.4-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:c4bb8b0ab9f94207d07e401d24baebfc63057246b1a5e0cd9ee50df85a656871"}, - {file = "pandas-1.4.4-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:51c424ca134fdaeac9a4acd719d1ab48046afc60943a489028f0413fdbe9ef1c"}, - {file = "pandas-1.4.4-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:ce35f947202b0b99c660221d82beb91d2e6d553d55a40b30128204e3e2c63848"}, - {file = "pandas-1.4.4-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ee6f1848148ed3204235967613b0a32be2d77f214e9623f554511047705c1e04"}, - {file = "pandas-1.4.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e7cc960959be28d064faefc0cb2aef854d46b827c004ebea7e79b5497ed83e7d"}, - {file = "pandas-1.4.4-cp38-cp38-win32.whl", hash = "sha256:9d805bce209714b1c1fa29bfb1e42ad87e4c0a825e4b390c56a3e71593b7e8d8"}, - {file = "pandas-1.4.4-cp38-cp38-win_amd64.whl", hash = "sha256:afbddad78a98ec4d2ce08b384b81730de1ccc975b99eb663e6dac43703f36d98"}, - {file = "pandas-1.4.4-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:a08ceb59db499864c58a9bf85ab6219d527d91f14c0240cc25fa2c261032b2a7"}, - {file = "pandas-1.4.4-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:0959c41004e3d2d16f39c828d6da66ebee329836a7ecee49fb777ac9ad8a7501"}, - {file = "pandas-1.4.4-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:87b4194f344dcd14c0f885cecb22005329b38bda10f1aaf7b9596a00ec8a4768"}, - {file = "pandas-1.4.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9d2a7a3c1fea668d56bd91edbd5f2732e0af8feb9d2bf8d9bfacb2dea5fa9536"}, - {file = "pandas-1.4.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a981cfabf51c318a562deb4ae7deec594c07aee7cf18b4594a92c23718ec8275"}, - {file = "pandas-1.4.4-cp39-cp39-win32.whl", hash = "sha256:050aada67a5ec6699a7879e769825b510018a95fb9ac462bb1867483d0974a97"}, - {file = "pandas-1.4.4-cp39-cp39-win_amd64.whl", hash = "sha256:8d4d2fe2863ecddb0ba1979bdda26c8bc2ea138f5a979abe3ba80c0fa4015c91"}, - {file = "pandas-1.4.4.tar.gz", hash = "sha256:ab6c0d738617b675183e5f28db32b5148b694ad9bba0a40c3ea26d96b431db67"}, + {file = "pandas-1.5.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:0d8d7433d19bfa33f11c92ad9997f15a902bda4f5ad3a4814a21d2e910894484"}, + {file = "pandas-1.5.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:5cc47f2ebaa20ef96ae72ee082f9e101b3dfbf74f0e62c7a12c0b075a683f03c"}, + {file = "pandas-1.5.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:8e8e5edf97d8793f51d258c07c629bd49d271d536ce15d66ac00ceda5c150eb3"}, + {file = "pandas-1.5.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:41aec9f87455306496d4486df07c1b98c15569c714be2dd552a6124cd9fda88f"}, + {file = "pandas-1.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c76f1d104844c5360c21d2ef0e1a8b2ccf8b8ebb40788475e255b9462e32b2be"}, + {file = "pandas-1.5.0-cp310-cp310-win_amd64.whl", hash = "sha256:1642fc6138b4e45d57a12c1b464a01a6d868c0148996af23f72dde8d12486bbc"}, + {file = "pandas-1.5.0-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:171cef540bfcec52257077816a4dbbac152acdb8236ba11d3196ae02bf0959d8"}, + {file = "pandas-1.5.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:a68a9b9754efff364b0c5ee5b0f18e15ca640c01afe605d12ba8b239ca304d6b"}, + {file = "pandas-1.5.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:86d87279ebc5bc20848b4ceb619073490037323f80f515e0ec891c80abad958a"}, + {file = "pandas-1.5.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:207d63ac851e60ec57458814613ef4b3b6a5e9f0b33c57623ba2bf8126c311f8"}, + {file = "pandas-1.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e252a9e49b233ff96e2815c67c29702ac3a062098d80a170c506dff3470fd060"}, + {file = "pandas-1.5.0-cp311-cp311-win_amd64.whl", hash = "sha256:de34636e2dc04e8ac2136a8d3c2051fd56ebe9fd6cd185581259330649e73ca9"}, + {file = "pandas-1.5.0-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:1d34b1f43d9e3f4aea056ba251f6e9b143055ebe101ed04c847b41bb0bb4a989"}, + {file = "pandas-1.5.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:1b82ccc7b093e0a93f8dffd97a542646a3e026817140e2c01266aaef5fdde11b"}, + {file = "pandas-1.5.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:4e30a31039574d96f3d683df34ccb50bb435426ad65793e42a613786901f6761"}, + {file = "pandas-1.5.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:62e61003411382e20d7c2aec1ee8d7c86c8b9cf46290993dd8a0a3be44daeb38"}, + {file = "pandas-1.5.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fc987f7717e53d372f586323fff441263204128a1ead053c1b98d7288f836ac9"}, + {file = "pandas-1.5.0-cp38-cp38-win32.whl", hash = "sha256:e178ce2d7e3b934cf8d01dc2d48d04d67cb0abfaffdcc8aa6271fd5a436f39c8"}, + {file = "pandas-1.5.0-cp38-cp38-win_amd64.whl", hash = "sha256:33a9d9e21ab2d91e2ab6e83598419ea6a664efd4c639606b299aae8097c1c94f"}, + {file = "pandas-1.5.0-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:73844e247a7b7dac2daa9df7339ecf1fcf1dfb8cbfd11e3ffe9819ae6c31c515"}, + {file = "pandas-1.5.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:e9c5049333c5bebf993033f4bf807d163e30e8fada06e1da7fa9db86e2392009"}, + {file = "pandas-1.5.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:85a516a7f6723ca1528f03f7851fa8d0360d1d6121cf15128b290cf79b8a7f6a"}, + {file = "pandas-1.5.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:947ed9f896ee61adbe61829a7ae1ade493c5a28c66366ec1de85c0642009faac"}, + {file = "pandas-1.5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c7f38d91f21937fe2bec9449570d7bf36ad7136227ef43b321194ec249e2149d"}, + {file = "pandas-1.5.0-cp39-cp39-win32.whl", hash = "sha256:2504c032f221ef9e4a289f5e46a42b76f5e087ecb67d62e342ccbba95a32a488"}, + {file = "pandas-1.5.0-cp39-cp39-win_amd64.whl", hash = "sha256:8a4fc04838615bf0a8d3a03ed68197f358054f0df61f390bcc64fbe39e3d71ec"}, + {file = "pandas-1.5.0.tar.gz", hash = "sha256:3ee61b881d2f64dd90c356eb4a4a4de75376586cd3c9341c6c0fcaae18d52977"}, ] passlib = [ {file = "passlib-1.7.4-py2.py3-none-any.whl", hash = "sha256:aa6bca462b8d8bda89c70b382f0c298a20b5560af6cbfa2dce410c0a2fb669f1"}, @@ -1124,7 +1128,7 @@ pathspec = [ {file = "pathspec-0.10.1.tar.gz", hash = "sha256:7ace6161b621d31e7902eb6b5ae148d12cfd23f4a249b9ffb6b9fee12084323d"}, ] peewee = [ - {file = "peewee-3.15.2.tar.gz", hash = "sha256:94d8eb7fc2b8d97d6216382bf5961239645dc9e2473b0e732eb6c79c920c4768"}, + {file = "peewee-3.15.3.tar.gz", hash = "sha256:cc934286d0c0842203abe66a3c6583d1463371e633b03d6da054d0f74e70706f"}, ] platformdirs = [ {file = "platformdirs-2.5.2-py3-none-any.whl", hash = "sha256:027d8e83a2d7de06bbac4e5ef7e023c02b863d7ea5d079477e722bb41ab25788"}, @@ -1245,8 +1249,8 @@ pydantic = [ {file = "pydantic-1.10.2.tar.gz", hash = "sha256:91b8e218852ef6007c2b98cd861601c6a09f1aa32bbbb74fab5b1c33d4a1e410"}, ] pylint = [ - {file = "pylint-2.15.2-py3-none-any.whl", hash = "sha256:cc3da458ba810c49d330e09013dec7ced5217772dec8f043ccdd34dae648fde8"}, - {file = "pylint-2.15.2.tar.gz", hash = "sha256:f63404a2547edb5247da263748771ac9a806ed1de4174cda01293c08ddbc2999"}, + {file = "pylint-2.15.3-py3-none-any.whl", hash = "sha256:7f6aad1d8d50807f7bc64f89ac75256a9baf8e6ed491cc9bc65592bc3f462cf1"}, + {file = "pylint-2.15.3.tar.gz", hash = "sha256:5fdfd44af182866999e6123139d265334267339f29961f00c89783155eacc60b"}, ] PyMySQL = [ {file = "PyMySQL-1.0.2-py3-none-any.whl", hash = "sha256:41fc3a0c5013d5f039639442321185532e3e2c8924687abe6537de157d403641"}, @@ -1330,6 +1334,13 @@ PyYAML = [ {file = "PyYAML-6.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:f84fbc98b019fef2ee9a1cb3ce93e3187a6df0b2538a651bfb890254ba9f90b5"}, {file = "PyYAML-6.0-cp310-cp310-win32.whl", hash = "sha256:2cd5df3de48857ed0544b34e2d40e9fac445930039f3cfe4bcc592a1f836d513"}, {file = "PyYAML-6.0-cp310-cp310-win_amd64.whl", hash = "sha256:daf496c58a8c52083df09b80c860005194014c3698698d1a57cbcfa182142a3a"}, + {file = "PyYAML-6.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:d4b0ba9512519522b118090257be113b9468d804b19d63c71dbcf4a48fa32358"}, + {file = "PyYAML-6.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:81957921f441d50af23654aa6c5e5eaf9b06aba7f0a19c18a538dc7ef291c5a1"}, + {file = "PyYAML-6.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:afa17f5bc4d1b10afd4466fd3a44dc0e245382deca5b3c353d8b757f9e3ecb8d"}, + {file = "PyYAML-6.0-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:dbad0e9d368bb989f4515da330b88a057617d16b6a8245084f1b05400f24609f"}, + {file = "PyYAML-6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:432557aa2c09802be39460360ddffd48156e30721f5e8d917f01d31694216782"}, + {file = "PyYAML-6.0-cp311-cp311-win32.whl", hash = "sha256:bfaef573a63ba8923503d27530362590ff4f576c626d86a9fed95822a8255fd7"}, + {file = "PyYAML-6.0-cp311-cp311-win_amd64.whl", hash = "sha256:01b45c0191e6d66c470b6cf1b9531a771a83c1c4208272ead47a3ae4f2f603bf"}, {file = "PyYAML-6.0-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:897b80890765f037df3403d22bab41627ca8811ae55e9a722fd0392850ec4d86"}, {file = "PyYAML-6.0-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:50602afada6d6cbfad699b0c7bb50d5ccffa7e46a3d738092afddc1f9758427f"}, {file = "PyYAML-6.0-cp36-cp36m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:48c346915c114f5fdb3ead70312bd042a953a8ce5c7106d5bfb1a5254e47da92"}, @@ -1366,8 +1377,8 @@ rsa = [ {file = "rsa-4.9.tar.gz", hash = "sha256:e38464a49c6c85d7f1351b0126661487a7e0a14a50f1675ec50eb34d4f20ef21"}, ] setuptools = [ - {file = "setuptools-65.3.0-py3-none-any.whl", hash = "sha256:2e24e0bec025f035a2e72cdd1961119f557d78ad331bb00ff82efb2ab8da8e82"}, - {file = "setuptools-65.3.0.tar.gz", hash = "sha256:7732871f4f7fa58fb6bdcaeadb0161b2bd046c85905dbaa066bdcbcc81953b57"}, + {file = "setuptools-65.4.0-py3-none-any.whl", hash = "sha256:c2d2709550f15aab6c9110196ea312f468f41cd546bceb24127a1be6fdcaeeb1"}, + {file = "setuptools-65.4.0.tar.gz", hash = "sha256:a8f6e213b4b0661f590ccf40de95d28a177cd747d098624ad3f69c40287297e9"}, ] six = [ {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"}, diff --git a/samudra/serve.py b/samudra/serve.py index c533b31..447d6f7 100644 --- a/samudra/serve.py +++ b/samudra/serve.py @@ -7,7 +7,7 @@ from samudra.conf.server.cors_policy import ALLOWED_ORIGINS from samudra.server.setup import check_tables -from samudra.server import lemmas, authentication +from samudra.server import lemmas, auth SLEEP_TIME: int = 10 @@ -15,7 +15,7 @@ # TODO: Add more server endpoints! app.include_router(lemmas.router) -app.include_router(authentication.router) +app.include_router(auth.router) app.add_middleware( CORSMiddleware, diff --git a/samudra/server/__init__.py b/samudra/server/__init__.py index a13f351..8762f70 100644 --- a/samudra/server/__init__.py +++ b/samudra/server/__init__.py @@ -1 +1 @@ -from .routes import lemmas, authentication +from .routes import lemmas, auth diff --git a/samudra/server/routes/auth.py b/samudra/server/routes/auth.py new file mode 100644 index 0000000..424077b --- /dev/null +++ b/samudra/server/routes/auth.py @@ -0,0 +1,55 @@ +from fastapi import APIRouter, Depends, HTTPException, status +from fastapi.security import OAuth2PasswordRequestForm + +from samudra import models, schemas +from samudra.core import auth +from samudra.server.dependencies import get_db +from datetime import timedelta + +from server.tokens import ( + ACCESS_TOKEN_EXPIRE_MINUTES, + PenggunaCreateDTO, + create_access_token, +) + +# TODO Set peranan +router = APIRouter(prefix="/auth", dependencies=[Depends(get_db)]) + + +@router.post("/daftar", response_model=schemas.DaftarResponse) +def create_pengguna(pengguna: PenggunaCreateDTO): + try: + pengguna = auth.get_pengguna_by_nama(pengguna.nama) + raise HTTPException(status_code=409, detail="User already exist") + except models.Pengguna.DoesNotExist: + pengguna = auth.create_pengguna( + nama=pengguna.nama, katalaluan=pengguna.katalaluan + ) + return { + "pengguna": pengguna.nama, + "mesej": f"Pengguna {pengguna.nama} telah berjaya didaftarkan!", + } + except SyntaxError as e: + raise HTTPException(status_code=400, detail=e.msg) + + +@router.post("/logmasuk", response_model=schemas.LogMasukResponse) +async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends()): + try: + pengguna = auth.authenticate_pengguna(form_data.username, form_data.password) + if not pengguna: + raise HTTPException( + status_code=status.HTTP_401_UNAUTHORIZED, + detail="Incorrect username or password", + headers={"WWW-Authenticate": "Bearer"}, + ) + access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES) + access_token = create_access_token( + data={"sub": pengguna.nama}, expires_delta=access_token_expires + ) + return { + "pengguna": form_data.username, + "token": {"access_token": access_token, "token_type": "bearer"}, + } + except SyntaxError as e: + raise HTTPException(status_code=400, detail=e.msg) diff --git a/samudra/server/routes/golongan_kata.py b/samudra/server/routes/golongan_kata.py index 99b3d98..77440c0 100644 --- a/samudra/server/routes/golongan_kata.py +++ b/samudra/server/routes/golongan_kata.py @@ -4,11 +4,13 @@ from core import crud from server.dependencies import get_db, oauth2_scheme -router = APIRouter(prefix="/golongan_kata", dependencies=[Depends(get_db)]) +router = APIRouter(prefix="/golongan", dependencies=[Depends(get_db)]) -@router.post('/new') -def create_golongan_kata(post: schemas.CreateGolonganKata, token: str = Depends(oauth2_scheme)): +@router.post("/new") +def create_golongan_kata( + post: schemas.CreateGolonganKata, token: str = Depends(oauth2_scheme) +): try: return crud.create_golongan_kata(data=post) except ValueError as e: diff --git a/samudra/server/tokens.py b/samudra/server/tokens.py new file mode 100644 index 0000000..89aac49 --- /dev/null +++ b/samudra/server/tokens.py @@ -0,0 +1,26 @@ +import os +from datetime import timedelta, datetime +from typing import Optional + +from jose import jwt +from pydantic import BaseModel + +SECRET_KEY = os.getenv("SECRET_KEY") +ALGORITHM = os.getenv("ALGORITHM") +ACCESS_TOKEN_EXPIRE_MINUTES = int(os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES")) + + +class PenggunaCreateDTO(BaseModel): + nama: str + katalaluan: str + + +def create_access_token(data: dict, expires_delta: Optional[timedelta]): + to_encode = data.copy() + if expires_delta: + expire = datetime.utcnow() + expires_delta + else: + expire = datetime.utcnow() + timedelta(minutes=15) + to_encode.update({"exp": expire}) + encoded_jwt = jwt.encode(to_encode, SECRET_KEY) + return encoded_jwt diff --git a/tests/mocks.py b/tests/mocks.py index 7cbb44d..4809237 100644 --- a/tests/mocks.py +++ b/tests/mocks.py @@ -2,13 +2,15 @@ import peewee as pw +from conf import Database from samudra import schemas from samudra.models import TABLES, JOIN_TABLES -mock_db = pw.SqliteDatabase(':memory:') +Database.engine = pw.SqliteDatabase(":memory:") models = [*TABLES] relational_models = [*JOIN_TABLES] +mock_db = Database.engine def bind_test_database(function: callable, *args, **kwargs) -> callable: diff --git a/tests/test_routes.py b/tests/test_routes.py new file mode 100644 index 0000000..a4692be --- /dev/null +++ b/tests/test_routes.py @@ -0,0 +1,12 @@ +from fastapi.testclient import TestClient +from serve import app +from mocks import * + +client = TestClient(app) + + +# TODO Test FastAPI +@bind_test_database +def test_get_lemma(): + response = client.get("/lemma/nama") + assert response is False From af65d26e74215838f672f6c09ba1beee7ff6eb05 Mon Sep 17 00:00:00 2001 From: Thaza_Kun <61819672+Thaza-Kun@users.noreply.github.com> Date: Tue, 27 Sep 2022 14:16:48 +0800 Subject: [PATCH 05/11] test: workflow for pytest --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 623961f..1cfcbd5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,4 +19,4 @@ jobs: poetry install - name: Test with pytest run: | - poetry run pytest --verbose \ No newline at end of file + pytest \ No newline at end of file From fb64769c95d4586349c8fd9191e94c4027394dd9 Mon Sep 17 00:00:00 2001 From: Thaza_Kun <61819672+Thaza-Kun@users.noreply.github.com> Date: Tue, 27 Sep 2022 14:18:33 +0800 Subject: [PATCH 06/11] docs: create requirements --- .pre-commit-config.yaml | 16 ++++++++-------- requirements.txt | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 requirements.txt diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6732f15..6ae48f3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,11 +15,11 @@ repos: # language: system # always_run: true # pass_filenames: false - - repo: https://github.com/python-poetry/poetry - rev: 1.2.0 - hooks: - - id: poetry-check - - id: poetry-lock - - id: poetry-export - name: create requirements with mysql - args: [ "-o", "requirements.txt", "--extras", "mysql", "--without-hashes" ] \ No newline at end of file +# - repo: https://github.com/python-poetry/poetry +# rev: 1.2.0 +# hooks: +# - id: poetry-check +# - id: poetry-lock +# - id: poetry-export +# name: create requirements with mysql +# args: [ "-o", "requirements.txt", "--extras", "mysql", "--without-hashes" ] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..ef046ad --- /dev/null +++ b/requirements.txt @@ -0,0 +1,37 @@ +anyio==3.6.1 ; python_version >= "3.8" and python_version < "4.0" +bcrypt==3.2.2 ; python_version >= "3.8" and python_version < "4.0" +certifi==2022.9.24 ; python_version >= "3.8" and python_version < "4" +cffi==1.15.1 ; python_version >= "3.8" and python_version < "4.0" +charset-normalizer==2.1.1 ; python_version >= "3.8" and python_version < "4" +click==8.1.3 ; python_version >= "3.8" and python_version < "4.0" +colorama==0.4.5 ; python_version >= "3.8" and python_version < "4.0" and platform_system == "Windows" +cryptography==37.0.4 ; python_version >= "3.8" and python_version < "4.0" +ecdsa==0.18.0 ; python_version >= "3.8" and python_version < "4.0" +et-xmlfile==1.1.0 ; python_version >= "3.8" and python_version < "4.0" +fastapi==0.79.1 ; python_version >= "3.8" and python_version < "4.0" +h11==0.14.0 ; python_version >= "3.8" and python_version < "4.0" +idna==3.4 ; python_version >= "3.8" and python_version < "4" +numpy==1.23.3 ; python_version >= "3.8" and python_version < "4.0" +openpyxl==3.0.10 ; python_version >= "3.8" and python_version < "4.0" +pandas==1.5.0 ; python_version >= "3.8" and python_version < "4.0" +passlib==1.7.4 ; python_version >= "3.8" and python_version < "4.0" +peewee==3.15.3 ; python_version >= "3.8" and python_version < "4.0" +pyasn1==0.4.8 ; python_version >= "3.8" and python_version < "4.0" +pycparser==2.21 ; python_version >= "3.8" and python_version < "4.0" +pycryptodome==3.15.0 ; python_version >= "3.8" and python_version < "4.0" +pydantic==1.10.2 ; python_version >= "3.8" and python_version < "4.0" +pymysql==1.0.2 ; python_version >= "3.8" and python_version < "4.0" +python-dateutil==2.8.2 ; python_version >= "3.8" and python_version < "4.0" +python-dotenv==0.20.0 ; python_version >= "3.8" and python_version < "4.0" +python-jose==3.3.0 ; python_version >= "3.8" and python_version < "4.0" +python-multipart==0.0.5 ; python_version >= "3.8" and python_version < "4.0" +pytomlpp==1.0.11 ; python_version >= "3.8" and python_version < "4.0" +pytz==2022.2.1 ; python_version >= "3.8" and python_version < "4.0" +requests==2.28.1 ; python_version >= "3.8" and python_version < "4" +rsa==4.9 ; python_version >= "3.8" and python_version < "4" +six==1.16.0 ; python_version >= "3.8" and python_version < "4.0" +sniffio==1.3.0 ; python_version >= "3.8" and python_version < "4.0" +starlette==0.19.1 ; python_version >= "3.8" and python_version < "4.0" +typing-extensions==4.3.0 ; python_version >= "3.8" and python_version < "4.0" +urllib3==1.26.12 ; python_version >= "3.8" and python_version < "4" +uvicorn==0.18.3 ; python_version >= "3.8" and python_version < "4.0" From 2bf256e93405123a5d61405acdc914c17307b007 Mon Sep 17 00:00:00 2001 From: Thaza_Kun <61819672+Thaza-Kun@users.noreply.github.com> Date: Tue, 27 Sep 2022 14:23:57 +0800 Subject: [PATCH 07/11] test: install pytest --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1cfcbd5..b86b4ba 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,7 @@ jobs: python-version: "3.8" - name: Install dependencies run: | - python -m pip install poetry + python -m pip install poetry pytest poetry install - name: Test with pytest run: | From 5f7b160c71da205296f4fd99cefeb320b4a3709e Mon Sep 17 00:00:00 2001 From: Thaza_Kun <61819672+Thaza-Kun@users.noreply.github.com> Date: Tue, 27 Sep 2022 14:36:56 +0800 Subject: [PATCH 08/11] test: revert to poetry --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b86b4ba..a8569d2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,8 +15,8 @@ jobs: python-version: "3.8" - name: Install dependencies run: | - python -m pip install poetry pytest + python -m pip install poetry poetry install - name: Test with pytest run: | - pytest \ No newline at end of file + poetry run pytest \ No newline at end of file From 6a278df442db3084e0325d43beec0bd6bd6b838f Mon Sep 17 00:00:00 2001 From: Thaza_Kun <61819672+Thaza-Kun@users.noreply.github.com> Date: Tue, 27 Sep 2022 14:40:32 +0800 Subject: [PATCH 09/11] refactor: rename to auth.py --- samudra/server/routes/authentication.py | 74 ------------------------- 1 file changed, 74 deletions(-) delete mode 100644 samudra/server/routes/authentication.py diff --git a/samudra/server/routes/authentication.py b/samudra/server/routes/authentication.py deleted file mode 100644 index 1694796..0000000 --- a/samudra/server/routes/authentication.py +++ /dev/null @@ -1,74 +0,0 @@ -from typing import Optional -import os -from fastapi import APIRouter, Depends, HTTPException, status -from fastapi.security import OAuth2PasswordRequestForm -from jose import jwt - -from samudra import models, schemas -from samudra.core import auth -from samudra.server.dependencies import get_db -from datetime import datetime, timedelta - -from pydantic import BaseModel - -SECRET_KEY = os.getenv("SECRET_KEY") -ALGORITHM = os.getenv("ALGORITHM") -ACCESS_TOKEN_EXPIRE_MINUTES = int(os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES")) - - -class PenggunaCreateDTO(BaseModel): - nama: str - katalaluan: str - - -def create_access_token(data: dict, expires_delta: Optional[timedelta]): - to_encode = data.copy() - if expires_delta: - expire = datetime.utcnow() + expires_delta - else: - expire = datetime.utcnow() + timedelta(minutes=15) - to_encode.update({"exp": expire}) - encoded_jwt = jwt.encode(to_encode, SECRET_KEY) - return encoded_jwt - - -router = APIRouter(prefix="/authentication", dependencies=[Depends(get_db)]) - - -@router.post("/daftar", response_model=schemas.DaftarResponse) -def create_pengguna(pengguna: PenggunaCreateDTO): - try: - pengguna = auth.get_pengguna_by_nama(pengguna.nama) - raise HTTPException(status_code=409, detail="User already exist") - except models.Pengguna.DoesNotExist: - pengguna = auth.create_pengguna( - nama=pengguna.nama, katalaluan=pengguna.katalaluan - ) - return { - "pengguna": pengguna.nama, - "mesej": f"Pengguna {pengguna.nama} telah berjaya didaftarkan!", - } - except SyntaxError as e: - raise HTTPException(status_code=400, detail=e.msg) - - -@router.post("/logmasuk", response_model=schemas.LogMasukResponse) -async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends()): - try: - pengguna = auth.authenticate_pengguna(form_data.username, form_data.password) - if not pengguna: - raise HTTPException( - status_code=status.HTTP_401_UNAUTHORIZED, - detail="Incorrect username or password", - headers={"WWW-Authenticate": "Bearer"}, - ) - access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES) - access_token = create_access_token( - data={"sub": pengguna.nama}, expires_delta=access_token_expires - ) - return { - "pengguna": form_data.username, - "token": {"access_token": access_token, "token_type": "bearer"}, - } - except SyntaxError as e: - raise HTTPException(status_code=400, detail=e.msg) From 05d90c301855904da6599e618cc9a96c31230e06 Mon Sep 17 00:00:00 2001 From: Thaza_Kun <61819672+Thaza-Kun@users.noreply.github.com> Date: Tue, 27 Sep 2022 14:54:40 +0800 Subject: [PATCH 10/11] fix: add golongan_kata to app router --- samudra/serve.py | 3 ++- samudra/server/__init__.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/samudra/serve.py b/samudra/serve.py index 447d6f7..b1d5dfe 100644 --- a/samudra/serve.py +++ b/samudra/serve.py @@ -7,7 +7,7 @@ from samudra.conf.server.cors_policy import ALLOWED_ORIGINS from samudra.server.setup import check_tables -from samudra.server import lemmas, auth +from samudra.server import lemmas, auth, golongan_kata SLEEP_TIME: int = 10 @@ -16,6 +16,7 @@ # TODO: Add more server endpoints! app.include_router(lemmas.router) app.include_router(auth.router) +app.include_router(golongan_kata.router) app.add_middleware( CORSMiddleware, diff --git a/samudra/server/__init__.py b/samudra/server/__init__.py index 8762f70..4008e9b 100644 --- a/samudra/server/__init__.py +++ b/samudra/server/__init__.py @@ -1 +1 @@ -from .routes import lemmas, auth +from .routes import lemmas, auth, golongan_kata From 2eee48189eec5dfe3f018e3333af6dfcddf667e1 Mon Sep 17 00:00:00 2001 From: Thaza_Kun <61819672+Thaza-Kun@users.noreply.github.com> Date: Tue, 27 Sep 2022 15:02:32 +0800 Subject: [PATCH 11/11] :rocket: RELEASE: Version 0.7.0 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 6a254c6..5a72e5d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "samudra" -version = "0.6.0" +version = "0.7.0" description = "" authors = ["Thaza_Kun <61819672+Thaza-Kun@users.noreply.github.com>"]