Skip to content

Commit 329aee7

Browse files
committed
GH-4 # add fastapi skeleton
1 parent 3f489fe commit 329aee7

File tree

7 files changed

+880
-19
lines changed

7 files changed

+880
-19
lines changed

poetry.lock

+855-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+3-4
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,19 @@ package-mode = false
1414
requires = ["poetry-core>=2.0.0,<3.0.0"]
1515
build-backend = "poetry.core.masonry.api"
1616

17-
dependencies = [
18-
"xxhash (>=3.5.0,<4.0.0)"
19-
]
20-
2117
[tool.poetry.group.dev.dependencies]
2218
pytest = "^8.3.4"
2319
ruff = "^0.9.4"
2420
testcontainers = {extras = ["generic"], version = "^4.9.1"}
21+
httpx = "^0.28.1" # required to test fastapi
2522

2623

2724
[tool.poetry.dependencies]
2825
redis = "^5.2.1"
2926
docopt = "^0.6.2"
3027
xxhash = "^3.5.0"
28+
fastapi = {extras = ["standard"], version = "^0.115.8"}
29+
3130
[tool.ruff]
3231
line-length = 120
3332
indent-width = 4
File renamed without changes.

src/api/main.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from fastapi import FastAPI
2+
3+
app = FastAPI()
4+
5+
6+
@app.get("/")
7+
def read_root():
8+
return {"Hello": "World"}

src/init_scripts/init_db_with_password_file.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<passwords-path> Absolute path to the password init file (1 password per line
1212
1313
"""
14+
1415
import os
1516
import time
1617

@@ -23,21 +24,20 @@
2324
KVROCKS_PORT = int(os.environ.get("KVROCKS_PORT", "6666"))
2425

2526

26-
2727
def init_db(file_path: str, db_client: Redis) -> int:
2828
"""Return the number of password inserted in db"""
2929
print("") # allow print below to clear this line return
3030
hasher = PasswordHasher()
3131
storage = PasswordStorage(client=db_client)
3232
processed = 0
33-
with open(file_path, encoding='latin-1') as file:
33+
with open(file_path, encoding="latin-1") as file:
3434
for line in file:
3535
password = line.strip()
3636
prefix = hasher.prefix(password)
3737
storage.add_password(prefix=prefix, password=password)
3838
processed += 1
3939
if processed % 100 == 0:
40-
print(f'\r{processed=}', end="")
40+
print(f"\r{processed=}", end="")
4141
storage.flush()
4242
print("\ndone")
4343
return processed

tests/integration/api/__init__.py

Whitespace-only changes.

tests/integration/api/test_api.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from fastapi.testclient import TestClient
2+
3+
from src.api.main import app
4+
5+
client = TestClient(app)
6+
7+
8+
def test_main():
9+
response = client.get("/")
10+
assert response.status_code == 200
11+
assert response.json() == {"Hello": "World"}

0 commit comments

Comments
 (0)