Skip to content

Commit

Permalink
Add few tests checking error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
lampajr committed May 7, 2024
1 parent 8054533 commit 47999f2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
11 changes: 5 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,17 @@ ${PROJECT_BIN}/kiota:
tools: kiota ## Install external tools.

${OPENAPI_SPEC}:
@{\
set -e ;\
@if [ ! -f ${OPENAPI_SPEC} ]; then \
mkdir -p ${OPENAPI_PATH} ;\
echo "fetching openapi spec from ${HORREUM_OPENAPI_PATH}" ;\
curl -sSfL -o ${OPENAPI_SPEC} ${HORREUM_OPENAPI_PATH} ;\
}
echo "fetching openapi from ${HORREUM_OPENAPI_PATH}"; \
curl -sSfL -o $@ ${HORREUM_OPENAPI_PATH}; \
fi

.PHONY: generate
generate: tools ${OPENAPI_SPEC} ## Generate the Horreum client
@{\
set -e ;\
${PROJECT_BIN}/kiota generate -l python -c HorreumRawClient -n raw_client -d ${OPENAPI_PATH}/openapi.yaml -o ${GENERATED_CLIENT_PATH} ;\
${PROJECT_BIN}/kiota generate --clean-output --log-level Debug -l python -c HorreumRawClient -n raw_client -d ${OPENAPI_PATH}/openapi.yaml -o ${GENERATED_CLIENT_PATH} ;\
}


Expand Down
23 changes: 23 additions & 0 deletions test/horreum_client_it.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import httpx
import pytest
from kiota_abstractions.api_error import APIError
from kiota_abstractions.authentication import BaseBearerTokenAuthenticationProvider
from kiota_abstractions.base_request_configuration import RequestConfiguration
from kiota_abstractions.headers_collection import HeadersCollection
Expand Down Expand Up @@ -111,3 +112,25 @@ async def test_check_create_test(custom_authenticated_client: HorreumClient):
# Delete test
await custom_authenticated_client.raw_client.api.test.by_id(created.id).delete()
assert (await custom_authenticated_client.raw_client.api.test.get()).count == 0


@pytest.mark.asyncio
async def test_create_test_unauthorized(anonymous_client: HorreumClient):
# Create new test
t = Test(name="TestName", description="Simple test", owner="dev-team", access=ProtectedType_access.PUBLIC)
with pytest.raises(APIError) as ex:
await anonymous_client.raw_client.api.test.post(t)
assert ex.value.response_status_code == 401
assert ex.value.message == ("The server returned an unexpected status code and no error class is registered "
"for this code 401")

assert (await anonymous_client.raw_client.api.test.get()).count == 0


@pytest.mark.asyncio
async def test_get_test_not_found(anonymous_client: HorreumClient):
with pytest.raises(APIError) as ex:
await anonymous_client.raw_client.api.test.by_id(999).get()
assert ex.value.response_status_code == 404
assert ex.value.message == ("The server returned an unexpected status code and no error class is registered "
"for this code 404")

0 comments on commit 47999f2

Please sign in to comment.