diff --git a/.gitignore b/.gitignore index a5c14e5..54cd5e6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ __pycache__/ .venv* *.py[o|c] **_build/ +geckodriver.log + diff --git a/Makefile b/Makefile index 673af69..d2b2955 100644 --- a/Makefile +++ b/Makefile @@ -9,14 +9,19 @@ install_dev: make requirements run_dev: - pipenv run python dev.py + git ls-files | entr -r pipenv run python dev.py tdd: git ls-files | entr pipenv run pytest --lf --nf + git ls-files | entr make functionnal_tests + test: pipenv run pytest $(opt) +functionnal_tests: + pipenv run python -m pytest functionnal_test.py + requirements: pipenv requirements > requirements.txt pipenv requirements --dev-only > requirements_dev.txt diff --git a/Pipfile b/Pipfile index a58cd5b..a630cd6 100644 --- a/Pipfile +++ b/Pipfile @@ -4,11 +4,12 @@ verify_ssl = true name = "pypi" [packages] +fastapi = "*" +uvicorn = "*" [dev-packages] pytest = "*" -sphinx = "==7.1.2" -"sphinx.builders.linkcheck" = "*" +selenium = "*" [requires] python_version = "3.12" diff --git a/README.rst b/README.rst index b18ac90..f28350a 100644 --- a/README.rst +++ b/README.rst @@ -39,3 +39,40 @@ if pipenv is *not* installed I suggest you have pipenv installed, this projet is writtent under python 3.12 and may work on other versiona We have a requirement of being virtualenv compatible while i will working with Pipenv. + + +Testing +------- + +Unitest should run flawlessly using make test, however functionnal testing may require some extra work. + +Functional testing requires *geckodriver* and *selenium* which is a driver to programatically control firefox (so one ca reproduce user behavior) + +.. code-block:: shell + + #debian + sudo apt-get install firefox-geckodriver + + # arch + sudo pacman -S geckodriver + + + +Toolings +-------- + +Few useful git aliases may be found in `gitalias.gitconfig` to use them add the include directive to your .git/config file + +.. code-block:: + + [include] + path = ../gitaliases.gitconfig + + [core] + repositoryformatversion = 0 + filemode = true + bare = false + logallrefupdates = true + + + diff --git a/dev.py b/dev.py index 894eaff..0ce2447 100644 --- a/dev.py +++ b/dev.py @@ -1,2 +1,13 @@ +from fastapi import FastAPI +import uvicorn + +app = FastAPI() + + +@app.get("/") +async def root(): + return {"message": "Hello World"} + + if __name__ == "__main__": - print("dev.py file ok") + uvicorn.run(app, host="127.0.0.1", port=5000) diff --git a/functionnal_test.py b/functionnal_test.py new file mode 100644 index 0000000..0ae2cdf --- /dev/null +++ b/functionnal_test.py @@ -0,0 +1,30 @@ +import unittest + +from selenium import webdriver +from selenium.webdriver.common.by import By + + +server = "localhost" +port = 5000 + +base_url = f"http://{server}{':%d' % port if port else '' }" + +docs_url = f"{base_url}/docs" + + +class BaseFunctionnalTestCase(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.driver = webdriver.Firefox() + cls.addClassCleanup(cls.driver.quit) + + def test_app_homepage_is_reachale(self): + self.driver.get(base_url) + + def test_app_has_swagger_documentation(self): + swagger_header_content = "FastAPI 0.1.0 OAS 3.1" + + self.driver.get(docs_url) + + swagger = self.driver.find_elements(By.ID, "swagger-ui")[0] + assert swagger_header_content in swagger.text.replace("\n", "") diff --git a/gitaliases.gitconfig b/gitaliases.gitconfig new file mode 100644 index 0000000..8d62732 --- /dev/null +++ b/gitaliases.gitconfig @@ -0,0 +1,12 @@ +# Add this to your .git/config file +#[include] +# path = ../gitaliases.gitconfig + +[alias] + um = "!git checkout main && git pull && git checkout - " + resync = "! git um && git rebase -" + out-of-sync = branch --no-merged main --no-contains main # Thee branch derive from an old main + open = branch --no-merged main --contains main + integ = "! git resync && git checkout main && git merge --no-ff - " + icm = "! echo 'ok'" +