Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new endpoint for exponentiation #70

Closed
wants to merge 4 commits into from

Conversation

acebots-ai-local[bot]
Copy link

This pull request adds a new endpoint for exponentiation to the API. The endpoint takes two numbers, number1 and number2, and returns number1^number2. The implementation includes the addition of the endpoint in the maths.py file and a corresponding test in the test_api.py file.


def test_exponentiation(client: starlette.testclient.TestClient) -> None:
"""Test that the exponentiation endpoint correctly calculates the power of a number."""
response = client.post("/exponentiation", json={"number1": 2, "number2": 3})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@acedev-dev-ai I think all the maths endpoints have some prefix. Could you check the prefix in get_api.py and update the test?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears there was a misunderstanding regarding the existence of a file named get_api.py in the project. After reviewing the project outline, I found no such file. Instead, the project structure includes an api.py file that seems to be responsible for setting up the API, including the registration of routers.

Given this context, it seems the initial request to check a prefix in get_api.py was based on incorrect information. The maths endpoints, as defined in maths.py, do not have a specific prefix beyond their operation names (e.g., /addition, /multiplication, /subtraction, /division). The new endpoint for exponentiation follows this pattern with the path /exponentiation.

If there's a specific prefix or modification you had in mind for the test or the endpoint itself, could you please clarify? Otherwise, based on the current project structure and the existing patterns in maths.py, the implementation and test for the exponentiation endpoint are consistent with the rest of the API design.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@acedev-dev-ai right, the file is called api.py. Please check the prefix there and update the test.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the test for the exponentiation endpoint to include the prefix /v1/maths in the URL. The correct URL for the test is now /v1/maths/exponentiation. This change aligns with the project's API structure and ensures consistency across all endpoint tests. If there are any more adjustments or reviews needed, please let me know!

"""Test that the exponentiation endpoint correctly calculates the power of a number."""
response = client.post("/v1/maths/exponentiation", json={"number1": 2, "number2": 3})
assert response.status_code == 200
assert response.json() == {"result": 8}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@acedev-dev-ai this test fails because the expected json does not align with the MathResult schema. Check the expected schema and update the test.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the test_exponentiation function in the tests/test_api.py file to include the 'operation' field in the expected JSON response, aligning with the MathsResult schema. The 'operation' field now correctly has the value 'exponentiation'. This should resolve the issue with the test failing due to the expected JSON not aligning with the schema.

@artmoskvin artmoskvin closed this Mar 14, 2024
@artmoskvin artmoskvin deleted the add-exponentiation-endpoint-my7b46 branch March 14, 2024 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant