CodeBench: code-small — FK update-testiesimerkki (author_id mukana PUT:ssa)
8b:n test_update_article palautti 422 koska author_id puuttui. Lisätty konkreettinen test_update_post esimerkki FK-kentän kanssa.
This commit is contained in:
@@ -35,12 +35,18 @@ class Post(Base):
|
||||
author_id: Mapped[int] = mapped_column(ForeignKey("authors.id"))
|
||||
```
|
||||
|
||||
Example FK test pattern:
|
||||
Example FK test patterns:
|
||||
```
|
||||
def test_create_post():
|
||||
author = client.post("/authors/", json={"name": "Kirjailija"}).json()
|
||||
response = client.post("/posts/", json={"title": "Artikkeli", "author_id": author["id"]})
|
||||
assert response.status_code == 201
|
||||
|
||||
def test_update_post():
|
||||
author = client.post("/authors/", json={"name": "Päivittäjä"}).json()
|
||||
created = client.post("/posts/", json={"title": "Vanha", "author_id": author["id"]}).json()
|
||||
response = client.put(f"/posts/{created['id']}", json={"title": "Uusi", "author_id": author["id"]})
|
||||
assert response.status_code == 201
|
||||
```
|
||||
|
||||
CRITICAL:
|
||||
|
||||
Reference in New Issue
Block a user