diff --git a/.funcignore b/.funcignore new file mode 100644 index 0000000..9966315 --- /dev/null +++ b/.funcignore @@ -0,0 +1,8 @@ +.git* +.vscode +__azurite_db*__.json +__blobstorage__ +__queuestorage__ +local.settings.json +test +.venv \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7685fc4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,135 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don’t work, or not +# install all needed dependencies. +#Pipfile.lock + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# Azure Functions artifacts +bin +obj +appsettings.json +local.settings.json + +# Azurite artifacts +__blobstorage__ +__queuestorage__ +__azurite_db*__.json +.python_packages \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..3f63eb9 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "ms-azuretools.vscode-azurefunctions", + "ms-python.python" + ] +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..ea3e0f1 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,12 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Attach to Python Functions", + "type": "python", + "request": "attach", + "port": 9091, + "preLaunchTask": "func: host start" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ef4ffb5 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "azureFunctions.deploySubpath": ".", + "azureFunctions.scmDoBuildDuringDeployment": true, + "azureFunctions.pythonVenv": ".venv", + "azureFunctions.projectLanguage": "Python", + "azureFunctions.projectRuntime": "~4", + "debug.internalConsoleOptions": "neverOpen" +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..0c465f1 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,27 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "func", + "label": "func: host start", + "command": "host start", + "problemMatcher": "$func-python-watch", + "isBackground": true, + "dependsOn": "pip install (functions)" + }, + { + "label": "pip install (functions)", + "type": "shell", + "osx": { + "command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt" + }, + "windows": { + "command": "${config:azureFunctions.pythonVenv}\\Scripts\\python -m pip install -r requirements.txt" + }, + "linux": { + "command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt" + }, + "problemMatcher": [] + } + ] +} \ No newline at end of file diff --git a/LeagueAdd/__init__.py b/LeagueAdd/__init__.py new file mode 100644 index 0000000..e48e072 --- /dev/null +++ b/LeagueAdd/__init__.py @@ -0,0 +1,21 @@ +import logging + +import azure.functions as func + +def main(req: func.HttpRequest) -> func.HttpResponse: + logging.info('Python HTTP trigger function processed a request.') + + name = req.params.get('name') or req.get_json().get('name') + country = req.params.get('country') or req.get_json().get('country') + + if name: + # Insert to Dataverse DB + # league = orm.entity("leagues") + # league.create({"name": name, "country": country}) + + return func.HttpResponse(f"League successfully created. Name : {name}, country : {country}.") + else: + return func.HttpResponse( + "Params are missing. Please include at least a 'name' to create a league.", + status_code=422 + ) diff --git a/LeagueAdd/function.json b/LeagueAdd/function.json new file mode 100644 index 0000000..6826c68 --- /dev/null +++ b/LeagueAdd/function.json @@ -0,0 +1,24 @@ +{ + "scriptFile": "__init__.py", + "bindings": [ + { + "authLevel": "function", + "type": "httpTrigger", + "direction": "in", + "name": "req", + "methods": [ + "get", + "post" + ] + }, + { + "type": "http", + "direction": "out", + "name": "$return" + }, + { + "name": "league_add", + "path": "/api/leagues/create" + } + ] +} \ No newline at end of file diff --git a/LeagueAdd/sample.dat b/LeagueAdd/sample.dat new file mode 100644 index 0000000..2e60943 --- /dev/null +++ b/LeagueAdd/sample.dat @@ -0,0 +1,3 @@ +{ + "name": "Azure" +} \ No newline at end of file diff --git a/README.md b/README.md index 8ec4b68..35af7f1 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,21 @@ # Core-App -This will contain the core of the Horseball App - Horseball App is a League Management System for horseball competitions +> This will contain the core of the Horseball App - Horseball App is a League Management System for horseball competitions + +## Installation +This project uses the Python package manager `pip`. To install the required packages, run the following command : + +```bash +pip install -r requirements.txt +``` + +## Dependencies +- Python 3.9+ + +## Usage + +> This section will be populated when adding new features. + +## License + +> This section will be updated soon. + diff --git a/host.json b/host.json new file mode 100644 index 0000000..fd4bee7 --- /dev/null +++ b/host.json @@ -0,0 +1,15 @@ +{ + "version": "2.0", + "logging": { + "applicationInsights": { + "samplingSettings": { + "isEnabled": true, + "excludedTypes": "Request" + } + } + }, + "extensionBundle": { + "id": "Microsoft.Azure.Functions.ExtensionBundle", + "version": "[3.*, 4.0.0)" + } +} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6b724b4 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +# DO NOT include azure-functions-worker in this file +# The Python Worker is managed by Azure Functions platform +# Manually managing azure-functions-worker may cause unexpected issues + +azure-functions +ms-dataverse +pytest \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/league_add_test.py b/tests/league_add_test.py new file mode 100644 index 0000000..e7d43ab --- /dev/null +++ b/tests/league_add_test.py @@ -0,0 +1,38 @@ +import unittest +import azure.functions as func +import json + +from LeagueAdd import main +from unittest import mock + +class TestLeagueAdd(unittest.TestCase): + def test_league_add_200(self): + # Setup + request = func.HttpRequest( + method='POST', + url='api/leagues/create', + body=json.dumps({ + 'name': 'Foobar', + 'country': 'can' + }).encode('utf8') + ) + + response = main(request) + + # Assertions + assert response.status_code == 200 + assert "League successfully created. Name : Foobar, country : can." in response.get_body().decode() + + def test_league_add_422(self): + # Setup + request = func.HttpRequest( + method='POST', + url='api/leagues/create', + body=json.dumps({}).encode('utf8') + ) + + response = main(request) + + # Assertions + assert response.status_code == 422 + assert "Params are missing. Please include at least a 'name' to create a league." in response.get_body().decode()