Skip to content
This repository was archived by the owner on Apr 29, 2025. It is now read-only.

Commit b0539b9

Browse files
authored
docs: update badges and README..upgrade mypy to 1.1.1; test: add tag service tests (#25)
1 parent 2709744 commit b0539b9

File tree

16 files changed

+159
-44
lines changed

16 files changed

+159
-44
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: build, test and deploy
1+
name: ci
22

33
on:
44
push:

README.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
<img alt="Coverage" src="https://codecov.io/gh/nickatnight/tag-youre-it-backend/branch/main/graph/badge.svg?token=E03I4QK6D9"/>
77
</a>
88
<a href="https://github.com/nickatnight/tag-youre-it-backend/releases"><img alt="Release Status" src="https://img.shields.io/github/v/release/nickatnight/tag-youre-it-backend"></a>
9-
<a href="https://github.com/nickatnight/tag-youre-it-backend/releases"><img alt="Python Badge" src="https://img.shields.io/badge/python-3.8%7C3.9%7C3.10%7C3.11-blue"></a>
9+
<a href="https://api.tagyoureitbot.com/docs"><img alt="Docs Badge" src="https://img.shields.io/badge/openapi-docs-blue"></a>
10+
<a href="https://tagyoureitbot.com"><img alt="Site Badge" src="https://img.shields.io/badge/site-React-important"></a>
11+
<a href="https://github.com/psf/black"><img alt="Style Badge" src="https://img.shields.io/badge/code%20style-black-000000"></a>
12+
<a href="https://mypy.readthedocs.io/en/stable/"><img alt="MyPy Badge" src="https://img.shields.io/badge/mypy-1.1.1-FFDD23">
1013
<a href="https://github.com/nickatnight/tag-youre-it-backend/blob/main/LICENSE">
1114
<img alt="License Shield" src="https://img.shields.io/github/license/nickatnight/tag-youre-it-backend">
1215
</a>
@@ -20,10 +23,6 @@
2023

2124
FastAPI backend for Reddit's TagYoureItBot
2225

23-
Frontend - https://tagyoureitbot.com
24-
25-
API - https://api.tagyoureitbot.com/docs
26-
2726
Project was scaffolded with [cookiecutter-fastapi-backend](https://github.com/nickatnight/cookiecutter-fastapi-backend)
2827

2928
## How To Play (beta)
@@ -68,15 +67,9 @@ See [r/TagYoureItBot](https://www.reddit.com/r/TagYoureItBot) for more updates.
6867
3. Backend, JSON based web API based on OpenAPI: `http://localhost/v1/`
6968
4. Automatic interactive documentation with Swagger UI (from the OpenAPI backend): `http://localhost/docs`
7069

71-
The entrypoint to the bot can be found in `src.core.bot`. In short, for each sub which the bot is enabled, an async process will be pushed onto the event loop (each sub gets their own game engine).
70+
The entrypoint to the bot can be found in [src.core.bot](/backend/src/core/bot.py). In short, for each sub which the bot is enabled, an async process will be pushed onto the event loop (each sub gets their own game engine).
7271

7372
### Migrations
74-
75-
After adding some models in `src/models/`, you can run the initial making of the migrations
76-
```console
77-
$ make alembic-init
78-
$ make alembic-migrate
79-
```
8073
Every migration after that, you can create new migrations and apply them with
8174
```console
8275
$ make alembic-make-migrations "cool comment dude"

backend/pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "tag-youre-it-backend"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
description = "Backend for TagYoureIt Reddit bot"
55
authors = ["nickatnight <nickkelly.858@gmail.com>"]
66

@@ -29,9 +29,10 @@ pytest = "^7.2.1"
2929
pytest-cov = "^4.0.0"
3030
pytest-mock = "^3.10.0"
3131
pytest-asyncio = "^0.19.0"
32-
mypy = "^0.982"
32+
mypy = "^1.1.1"
3333
ruff = "^0.0.241"
3434
httpx = "^0.23.3"
35+
Faker = "^17.6.0"
3536

3637
[tool.isort]
3738
multi_line_output = 3

backend/src/api/v1/game.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ async def games(
3030
repo = GameRepository(db=session)
3131
games = await repo.all(skip=skip, limit=limit, sort_field=sort, sort_order=order.lower())
3232

33-
response.headers["x-content-range"] = f"{len(games)}/{10}"
33+
response.headers["x-content-range"] = f"{len(games)}/{limit}"
3434
return IGetResponseBase[List[IGameRead]](data=games)

backend/src/api/v1/player.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ async def players(
3030
repo = PlayerRepository(db=session)
3131
players = await repo.all(skip=skip, limit=limit, sort_field=sort, sort_order=order.lower())
3232

33-
response.headers["x-content-range"] = f"{len(players)}/{10}"
33+
response.headers["x-content-range"] = f"{len(players)}/{limit}"
3434
return IGetResponseBase[List[IPlayerRead]](data=players)

backend/src/api/v1/subreddit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ async def subreddits(
3030
repo = SubRedditRepository(db=session)
3131
subreddits = await repo.all(skip=skip, limit=limit, sort_field=sort, sort_order=order.lower())
3232

33-
response.headers["x-content-range"] = f"{len(subreddits)}/{10}"
33+
response.headers["x-content-range"] = f"{len(subreddits)}/{limit}"
3434
return IGetResponseBase[List[ISubRedditRead]](data=subreddits)

backend/src/clients/reddit/inbox.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
from typing import AsyncIterator
1+
from typing import AsyncIterator, Optional
22

3+
from asyncpraw import Reddit
34
from asyncpraw.models import Message
45

56
from src.clients.reddit.base import RedditResource
67

78

89
class InboxClient(RedditResource):
9-
def __init__(self, reddit=None) -> None:
10+
def __init__(self, reddit: Optional[Reddit] = None) -> None:
1011
self.reddit = reddit or self.configure()
1112

1213
def stream(self) -> AsyncIterator[Message]:

backend/src/core/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class Settings(BaseSettings):
2828
DB_POOL_SIZE: int = Field(default=83, env="DB_POOL_SIZE")
2929
WEB_CONCURRENCY: int = Field(default=9, env="WEB_CONCURRENCY")
3030
MAX_OVERFLOW: int = Field(default=64, env="MAX_OVERFLOW")
31-
POOL_SIZE: Optional[int]
32-
POSTGRES_URL: Optional[str]
31+
POOL_SIZE: int = Field(default=None, env="POOL_SIZE")
32+
POSTGRES_URL: str = Field(default=None, env="POSTGRES_URL")
3333

3434
CLIENT_ID: str = Field(default="", env="CLIENT_ID")
3535
CLIENT_SECRET: str = Field(default="", env="CLIENT_SECRET")

backend/src/core/decorators.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import functools
22
import logging
3-
from typing import Any
3+
from typing import Any, Callable
44

55
import asyncprawcore
66

77

88
logger = logging.getLogger(__name__)
99

1010

11-
def catch_apraw_and_log(func):
11+
# TODO: revisit this
12+
def catch_apraw_and_log(func: Callable[..., Any]) -> Any:
1213
@functools.wraps(func)
13-
async def wrapper_catch_apraw_and_log(*args, **kwargs):
14+
async def wrapper_catch_apraw_and_log(*args: str, **kwargs: int) -> Any:
1415
try:
1516
result: Any = await func(*args, **kwargs)
1617
except asyncprawcore.exceptions.RequestException as a_exc:

backend/src/core/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ class TagYoureItBackendException(Exception):
44

55
class ObjectNotFound(TagYoureItBackendException):
66
pass
7+
8+
9+
class TagTimeNullError(TagYoureItBackendException):
10+
pass

0 commit comments

Comments
 (0)