Skip to content

Commit

Permalink
Merge pull request #49 from rodekruis/dev-final
Browse files Browse the repository at this point in the history
Dev-final
  • Loading branch information
tijsziere authored Oct 22, 2024
2 parents d71ccd1 + 7407812 commit 44a465f
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
38 changes: 38 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Run automated Tests

on:
push:
workflow_dispatch:
pull_request:

permissions:
contents: read

jobs:
test:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v3
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
33 changes: 32 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# pylint: disable=invalid-name
import uvicorn
from fastapi import FastAPI
from fastapi.responses import RedirectResponse, JSONResponse
Expand All @@ -11,6 +10,28 @@
load_dotenv()
port = os.environ["PORT"]

# Set up logs export to Azure Application Insights
logger_provider = LoggerProvider()
set_logger_provider(logger_provider)
exporter = AzureMonitorLogExporter(
connection_string=os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"]
)
logger_provider.add_log_record_processor(BatchLogRecordProcessor(exporter))

# Attach LoggingHandler to root logger
handler = LoggingHandler()
logging.getLogger().addHandler(handler)
logging.getLogger().setLevel(logging.NOTSET)
logger = logging.getLogger(__name__)

# Silence noisy loggers
logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("urllib3").setLevel(logging.WARNING)
logging.getLogger("azure").setLevel(logging.WARNING)
logging.getLogger("requests_oauthlib").setLevel(logging.WARNING)
logging.getLogger("asyncio").setLevel(logging.WARNING)
logging.getLogger("opentelemetry").setLevel(logging.ERROR)

# initialize FastAPI
app = FastAPI(
title="kobo-connect",
Expand All @@ -25,6 +46,16 @@
},
)

# initialize CosmosDB
client_ = cosmos_client.CosmosClient(
os.getenv("COSMOS_URL"),
{"masterKey": os.getenv("COSMOS_KEY")},
user_agent="kobo-connect",
user_agent_overwrite=True,
)
cosmos_db = client_.get_database_client("kobo-connect")
cosmos_container_client = cosmos_db.get_container_client("kobo-submissions")


@app.get("/", include_in_schema=False)
async def docs_redirect():
Expand Down
Empty file removed routes/__init__.py
Empty file.

0 comments on commit 44a465f

Please sign in to comment.