Skip to content

Commit 1129801

Browse files
committed
fix
1 parent 7697f2c commit 1129801

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

fastapi_jsonapi/querystring.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ def fields(self) -> Dict[str, List[str]]:
242242
self._get_schema(resource_type)
243243

244244
for field_name in field_names:
245+
if field_name == "":
246+
continue
247+
245248
if field_name not in schema.__fields__:
246249
msg = "{schema} has no attribute {field}".format(
247250
schema=schema.__name__,

tests/fixtures/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def add_routers(app_plain: FastAPI):
112112
class_detail=DetailViewBaseGeneric,
113113
class_list=ListViewBaseGeneric,
114114
schema=PostCommentSchema,
115-
resource_type="comment",
115+
resource_type="post_comment",
116116
model=PostComment,
117117
)
118118

tests/test_api/test_api_sqla_with_includes.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ async def test_select_custom_fields_with_includes(
232232
("fields[user]", "name"),
233233
("fields[post]", "title"),
234234
# empty str means ignore all fields
235-
("fields[comment]", ""),
235+
("fields[post_comment]", ""),
236236
("include", "posts,posts.comments"),
237237
("sort", "id"),
238238
],
@@ -284,7 +284,14 @@ async def test_select_custom_fields_with_includes(
284284
"attributes": PostAttributesBaseSchema.from_orm(user_2_post).dict(include={"title"}),
285285
"id": str(user_2_post.id),
286286
"relationships": {
287-
"comments": {"data": [{"id": str(user_1_comment.id), "type": "post_comment"}]},
287+
"comments": {
288+
"data": [
289+
{
290+
"id": str(user_1_comment.id),
291+
"type": "post_comment",
292+
},
293+
],
294+
},
288295
},
289296
"type": "post",
290297
},
@@ -298,12 +305,12 @@ async def test_select_custom_fields_with_includes(
298305
},
299306
{
300307
"attributes": {},
301-
"id": "1",
308+
"id": str(user_1_comment.id),
302309
"type": "post_comment",
303310
},
304311
{
305312
"attributes": {},
306-
"id": "2",
313+
"id": str(user_2_comment.id),
307314
"type": "post_comment",
308315
},
309316
],
@@ -426,7 +433,7 @@ async def test_create_comments_for_post(
426433
user_2: User,
427434
user_1_post: Post,
428435
):
429-
url = app.url_path_for("get_comment_list")
436+
url = app.url_path_for("get_post_comment_list")
430437
url = f"{url}?include=author,post,post.user"
431438
comment_attributes = PostCommentAttributesBaseSchema(
432439
text=fake.sentence(),
@@ -457,7 +464,7 @@ async def test_create_comments_for_post(
457464
comment_id = comment_data.pop("id")
458465
assert comment_id
459466
assert comment_data == {
460-
"type": "comment",
467+
"type": "post_comment",
461468
"attributes": comment_attributes,
462469
"relationships": {
463470
"post": {
@@ -515,7 +522,7 @@ async def test_create_comment_error_no_relationship(
515522
:param user_1_post:
516523
:return:
517524
"""
518-
url = app.url_path_for("get_comment_list")
525+
url = app.url_path_for("get_post_comment_list")
519526
comment_attributes = PostCommentAttributesBaseSchema(
520527
text=fake.sentence(),
521528
).dict()
@@ -556,7 +563,7 @@ async def test_create_comment_error_no_relationships_content(
556563
app: FastAPI,
557564
client: AsyncClient,
558565
):
559-
url = app.url_path_for("get_comment_list")
566+
url = app.url_path_for("get_post_comment_list")
560567
comment_attributes = PostCommentAttributesBaseSchema(
561568
text=fake.sentence(),
562569
).dict()
@@ -602,7 +609,7 @@ async def test_create_comment_error_no_relationships_field(
602609
app: FastAPI,
603610
client: AsyncClient,
604611
):
605-
url = app.url_path_for("get_comment_list")
612+
url = app.url_path_for("get_post_comment_list")
606613
comment_attributes = PostCommentAttributesBaseSchema(
607614
text=fake.sentence(),
608615
).dict()

0 commit comments

Comments
 (0)