Merge branch 'feature_3_2_api'

This commit is contained in:
Colin Goutte 2023-08-25 11:11:50 +02:00
commit c1386d0d35
7 changed files with 102 additions and 4 deletions

2
.gitignore vendored
View File

@ -3,3 +3,5 @@ __pycache__/
.venv*
*.py[o|c]
**_build/
geckodriver.log

View File

@ -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

View File

@ -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"

View File

@ -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
<snip>

13
dev.py
View File

@ -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)

30
functionnal_test.py Normal file
View File

@ -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", "")

12
gitaliases.gitconfig Normal file
View File

@ -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'"