Skip to content

Commit

Permalink
pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
mattholy committed Jan 22, 2024
1 parent afbc370 commit a4ce232
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 7 deletions.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[tool.pytest.ini_options]
testpaths = ["service/backend/tests"]
python_files = ["test_*.py"]
Empty file added service/backend/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion service/backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async def actor():


@app.get("/.well-known/webfinger", response_class=ActivityResponse, tags=['.well-known'], name='Webfinger', response_model=activitypub_model.WebfingerResource)
def read_webfinger(resource: Optional[str] = Query(None, regex="acct:.+")):
def read_webfinger(resource: Optional[str] = Query(None, pattern="acct:.+")):
if resource is None:
raise HTTPException(
status_code=400, detail="Missing resource parameter")
Expand Down
10 changes: 4 additions & 6 deletions service/backend/app/model/activitypub_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@


class PublicKey(BaseModel):
model_config = ConfigDict(populate_by_name=True)

id: Optional[str] = Field(None, alias='id')
owner: Optional[str] = Field(None, alias='owner')
public_key_pem: Optional[str] = Field(None, alias='publicKeyPem')

class Config:
populate_by_name = True


class Endpoints(BaseModel):
model_config = ConfigDict(populate_by_name=True)
Expand All @@ -32,10 +31,9 @@ class Endpoints(BaseModel):


class Image(BaseModel):
url: Optional[str] = Field(None, alias='url')
model_config = ConfigDict(populate_by_name=True)

class Config:
populate_by_name = True
url: Optional[str] = Field(None, alias='url')


class Actor(BaseModel):
Expand Down
Empty file.
24 changes: 24 additions & 0 deletions service/backend/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- encoding: utf-8 -*-
'''
test_main.py
----
testing
@Time : 2024/01/22 12:57:51
@Author : Mattholy
@Version : 1.0
@Contact : [email protected]
@License : MIT License
'''

from fastapi.testclient import TestClient

from ..app.main import app

client = TestClient(app)


def test_read_main():
response = client.get("/")
assert response.status_code == 200

0 comments on commit a4ce232

Please sign in to comment.