diff --git a/nombres/nombres.yml b/nombres/nombres.yml index 7665d82..18bb806 100644 --- a/nombres/nombres.yml +++ b/nombres/nombres.yml @@ -11,3 +11,7 @@ functions: lang: python3-flask handler: ./historico image: ralsina/nombres_historico:latest + tapas: + lang: python3-flask + handler: ./tapas + image: ralsina/tapas:latest diff --git a/nombres/tapas/__init__.py b/nombres/tapas/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nombres/tapas/handler.py b/nombres/tapas/handler.py new file mode 100644 index 0000000..6349dd6 --- /dev/null +++ b/nombres/tapas/handler.py @@ -0,0 +1,32 @@ +from json import loads +from tapita import Cover +from io import BytesIO +import base64 + + +def handle(req): + """handle a request to the function + Args: + req (str): request body + + { + "title": "foo", + "subtitle": "bar", + "author": "bat", + } + """ + try: + args = loads(req) + except Exception: + return "Bad Request", 400 + + c = Cover(**args) + byte_arr = BytesIO() + c.image.save(byte_arr, format="JPEG") + + # return Response(chart.render(is_unicode=True), mimetype="image/svg+xml") + return ( + f'', + 200, + {"Content-Type": "text/html"}, + ) diff --git a/nombres/tapas/handler_test.py b/nombres/tapas/handler_test.py new file mode 100644 index 0000000..1ce59c9 --- /dev/null +++ b/nombres/tapas/handler_test.py @@ -0,0 +1,11 @@ +from .handler import handle + +# Test your handler here + +# To disable testing, you can set the build_arg `TEST_ENABLED=false` on the CLI or in your stack.yml +# https://docs.openfaas.com/reference/yaml/#function-build-args-build-args + + +def test_handle(): + # assert handle("input") == "input" + pass diff --git a/nombres/tapas/requirements.txt b/nombres/tapas/requirements.txt new file mode 100644 index 0000000..4f493d1 --- /dev/null +++ b/nombres/tapas/requirements.txt @@ -0,0 +1 @@ +tapita diff --git a/nombres/tapas/tox.ini b/nombres/tapas/tox.ini new file mode 100644 index 0000000..a64a800 --- /dev/null +++ b/nombres/tapas/tox.ini @@ -0,0 +1,41 @@ +# If you would like to disable +# automated testing during faas-cli build, + +# Replace the content of this file with +# [tox] +# skipsdist = true + +# You can also edit, remove, or add additional test steps +# by editing, removing, or adding new testenv sections + + +# find out more about tox: https://tox.readthedocs.io/en/latest/ +[tox] +envlist = lint,test +skipsdist = true + +[testenv:test] +deps = + flask + pytest + -rrequirements.txt +commands = + # run unit tests with pytest + # https://docs.pytest.org/en/stable/ + # configure by adding a pytest.ini to your handler + pytest + +[testenv:lint] +deps = + flake8 +commands = + flake8 . + +[flake8] +count = true +max-line-length = 127 +max-complexity = 10 +statistics = true +# stop the build if there are Python syntax errors or undefined names +select = E9,F63,F7,F82 +show-source = true