fix: auth current user on code validation (#6911)
* Add user auth for /code endpoint * import * revert * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes (attempt 2/3) * ruff * fix tests * [autofix.ci] apply automated fixes * ruff --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Nadir J <31660040+NadirJ@users.noreply.github.com>
This commit is contained in:
parent
e1ee081d32
commit
faac4db133
3 changed files with 36 additions and 12 deletions
|
|
@ -127,7 +127,8 @@ async def test_get_all(client: AsyncClient, logged_in_headers):
|
|||
assert "ChatOutput" in json_response["outputs"]
|
||||
|
||||
|
||||
async def test_post_validate_code(client: AsyncClient):
|
||||
@pytest.mark.usefixtures("active_user")
|
||||
async def test_post_validate_code(client: AsyncClient, logged_in_headers):
|
||||
# Test case with a valid import and function
|
||||
code1 = """
|
||||
import math
|
||||
|
|
@ -135,7 +136,7 @@ import math
|
|||
def square(x):
|
||||
return x ** 2
|
||||
"""
|
||||
response1 = await client.post("api/v1/validate/code", json={"code": code1})
|
||||
response1 = await client.post("api/v1/validate/code", json={"code": code1}, headers=logged_in_headers)
|
||||
assert response1.status_code == 200
|
||||
assert response1.json() == {"imports": {"errors": []}, "function": {"errors": []}}
|
||||
|
||||
|
|
@ -146,7 +147,7 @@ import non_existent_module
|
|||
def square(x):
|
||||
return x ** 2
|
||||
"""
|
||||
response2 = await client.post("api/v1/validate/code", json={"code": code2})
|
||||
response2 = await client.post("api/v1/validate/code", json={"code": code2}, headers=logged_in_headers)
|
||||
assert response2.status_code == 200
|
||||
assert response2.json() == {
|
||||
"imports": {"errors": ["No module named 'non_existent_module'"]},
|
||||
|
|
@ -160,7 +161,7 @@ import math
|
|||
def square(x)
|
||||
return x ** 2
|
||||
"""
|
||||
response3 = await client.post("api/v1/validate/code", json={"code": code3})
|
||||
response3 = await client.post("api/v1/validate/code", json={"code": code3}, headers=logged_in_headers)
|
||||
assert response3.status_code == 200
|
||||
assert response3.json() == {
|
||||
"imports": {"errors": []},
|
||||
|
|
@ -168,11 +169,11 @@ def square(x)
|
|||
}
|
||||
|
||||
# Test case with invalid JSON payload
|
||||
response4 = await client.post("api/v1/validate/code", json={"invalid_key": code1})
|
||||
response4 = await client.post("api/v1/validate/code", json={"invalid_key": code1}, headers=logged_in_headers)
|
||||
assert response4.status_code == 422
|
||||
|
||||
# Test case with an empty code string
|
||||
response5 = await client.post("api/v1/validate/code", json={"code": ""})
|
||||
response5 = await client.post("api/v1/validate/code", json={"code": ""}, headers=logged_in_headers)
|
||||
assert response5.status_code == 200
|
||||
assert response5.json() == {"imports": {"errors": []}, "function": {"errors": []}}
|
||||
|
||||
|
|
@ -183,7 +184,7 @@ import math
|
|||
def square(x)
|
||||
return x ** 2
|
||||
"""
|
||||
response6 = await client.post("api/v1/validate/code", json={"code": code6})
|
||||
response6 = await client.post("api/v1/validate/code", json={"code": code6}, headers=logged_in_headers)
|
||||
assert response6.status_code == 200
|
||||
assert response6.json() == {
|
||||
"imports": {"errors": []},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue