fix : fixed issue with json body handling in test_create_answer function#17
Open
Ishan-53 wants to merge 1 commit intomarciovrl:masterfrom
Open
fix : fixed issue with json body handling in test_create_answer function#17Ishan-53 wants to merge 1 commit intomarciovrl:masterfrom
Ishan-53 wants to merge 1 commit intomarciovrl:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull request for Issue #15
Issue Description :
The test_create_answer function is incorrectly using the data parameter to send JSON data. The data parameter is meant for form-encoded data, while JSON data should be sent using the json parameter in FastAPI/Starlette TestClient.
Steps to Reproduce:
Run the test_create_answer function.
Observe that the test fails due to incorrect JSON handling or doesn't work as intended.
Expected Behavior:
The test should post the JSON payload correctly to the endpoint using the json parameter.
Actual Behavior:
Using the data parameter causes issues in JSON data encoding or incorrect behavior.
Code Snippet (Problem Area):
def test_create_answer(): body = {"user_id": 1, "answers": [{"question_id": 1, "alternative_id": 2}, { "question_id": 2, "alternative_id": 2}, {"question_id": 2, "alternative_id": 2}]} body = json.dumps(body) # Unnecessary step response = client.post('/answer', data=body) # Incorrect usage of 'data' assert response.status_code == 201
fixed code :
def test_create_answer():
body = {"user_id": 1, "answers": [{"question_id": 1, "alternative_id": 2}, {
"question_id": 2, "alternative_id": 2}, {"question_id": 2, "alternative_id": 2}]}
body = json.dumps(body)
response = client.post('/answer', json=body)
assert response.status_code == 201