Skip to content

Commit

Permalink
Merge ba37729 into da2717d
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanklee86 committed Jan 17, 2022
2 parents da2717d + ba37729 commit 25b305f
Show file tree
Hide file tree
Showing 24 changed files with 405 additions and 33 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/ci.yml
Expand Up @@ -25,17 +25,18 @@ jobs:
poetry run isort . --check --diff
poetry run black --check --target-version py310 telathbot tests
- name: Run tests
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
run: |
docker-compose -f tests/local_dev/docker-compose.yaml up -d
sleep 10
cp .env-local .env
poetry run pytest
# - name: "Upload coverage to Codecov"
# uses: codecov/codecov-action@v2
# with:
# fail_ci_if_error: true
# files: ./test_results/cov.xml
# token: ${{ secrets.CODECOV_TOKEN }}
- name: Send coverage to Coveralls
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
poetry run coveralls --service=github
- uses: actions/upload-artifact@v2
with:
name: test-results
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -130,4 +130,5 @@ dmypy.json

# Custom
.vscode
.idea
test_results
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -16,9 +16,9 @@ build: clean build-package upload
lint:
export PYTHONPATH=${ROOT_DIR}:$$PYTHONPATH;
mypy --install-types --non-interactive ${PROJECT_NAME};
pylint ${PROJECT_NAME};
isort .;
black telathbot tests --target-version py310;
pylint ${PROJECT_NAME};

pytest:
export PYTHONPATH=${ROOT_DIR}:$$PYTHONPATH && \
Expand Down
154 changes: 153 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion pyproject.toml
Expand Up @@ -14,6 +14,8 @@ prometheus-fastapi-instrumentator = "^5.7.1"
motor = "^2.5.1"
aiomysql = "^0.0.22"
mypy = "^0.931"
httpx = "^0.21.3"
umongo = "^3.1.0"

[tool.poetry.dev-dependencies]
pytest = "^6.2.5"
Expand All @@ -26,6 +28,8 @@ pytest-mock = "^3.6.1"
pytest-html = "^3.1.1"
black = "^21.12b0"
isort = "^5.10.1"
pytest-asyncio = "^0.17.1"
coveralls = "^3.3.1"

[tool.isort]
profile = "black"
Expand All @@ -52,8 +56,11 @@ disable = [
"line-too-long",
"missing-function-docstring",
"missing-module-docstring",
"missing-class-docstring"
"missing-class-docstring",
"too-few-public-methods",
"logging-fstring-interpolation"
]
logging-format-style="new"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
8 changes: 4 additions & 4 deletions telathbot/app.py
Expand Up @@ -2,22 +2,22 @@
from prometheus_fastapi_instrumentator import Instrumentator

from telathbot import constants
from telathbot.databases.mongo import initialize
from telathbot.logger import init_logger
from telathbot.models.responses import HealthResponse
from telathbot.routers import safetytools
from telathbot.routers import metadata, safetytools
from telathbot.schemas.responses import HealthResponse

init_logger()
app = FastAPI()
Instrumentator().instrument(app).expose(app)


app.include_router(safetytools.SAFETYTOOLS_ROUTER)
app.include_router(metadata.METADATA_ROUTER)


@app.on_event("startup")
async def on_startup() -> None:
await initialize()
await metadata.initialize()


@app.get("/health")
Expand Down
23 changes: 9 additions & 14 deletions telathbot/databases/mongo.py
@@ -1,19 +1,14 @@
import asyncio

import motor.core
from motor.motor_asyncio import AsyncIOMotorClient
from umongo.frameworks import MotorAsyncIOInstance

from telathbot.config import get_settings
from telathbot.constants import METADATA_COLLECTION, TELATHBOT_DB, VERSION
from telathbot.logger import LOGGER


async def initialize():
config = get_settings()
database = AsyncIOMotorClient(config.telathbot_db_url)
metadata_collection = database[TELATHBOT_DB][METADATA_COLLECTION]
from telathbot.constants import TELATHBOT_DB

if await metadata_collection.count_documents({}) == 0:
metadata = {"type": "metadata", "appVersion": VERSION, "lastPostId": 0}
CLIENT = AsyncIOMotorClient(get_settings().telathbot_db_url)
CLIENT.get_io_loop = asyncio.get_running_loop
DB = CLIENT[TELATHBOT_DB]

await metadata_collection.insert_one(metadata)
LOGGER.info("No metadata found. Initializing!")
else:
LOGGER.info("Metadata found.")
UMONGO = MotorAsyncIOInstance(DB)
2 changes: 1 addition & 1 deletion telathbot/databases/mysql.py
Expand Up @@ -4,7 +4,7 @@
import aiomysql

from telathbot.config import get_settings
from telathbot.models.reaction import PostReaction
from telathbot.schemas.reaction import PostReaction


async def get_post_reactions(
Expand Down

0 comments on commit 25b305f

Please sign in to comment.