From 8ce1d9be2198f092a216657e8ca2564830635e65 Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 23:37:29 +0100 Subject: [PATCH 1/2] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 916fd005..83303f72 100644 --- a/README.md +++ b/README.md @@ -86,3 +86,6 @@ Note: This project integrates with third-party APIs. You will need to obtain the We <3 contributions big and small: - Submit a [feature request](https://github.com/chapter-gtm/chapter/issues/new?assignees=&labels=&projects=&template=feature_request.md&title=) or [bug report](https://github.com/chapter-gtm/chapter/issues/new?assignees=&labels=&projects=&template=bug_report.md&title=) + +## Test +- 1 From 2f290024eab16be33e190d37de9cbaf70dba6489 Mon Sep 17 00:00:00 2001 From: chapter-test-bot Date: Fri, 14 Feb 2025 22:42:03 +0000 Subject: [PATCH 2/2] test(api): add tests generated by Chapter --- .../validation/test_post_api-access-logout.py | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 chapter_api_tests/0.2.0/validation/test_post_api-access-logout.py diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-logout.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-logout.py new file mode 100644 index 00000000..b1801f3a --- /dev/null +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-logout.py @@ -0,0 +1,89 @@ +import os +import pytest +import httpx + + +@pytest.fixture +async def client(): + base_url = os.getenv('API_BASE_URL') + async with httpx.AsyncClient(base_url=base_url) as client: + yield client + + +@pytest.mark.asyncio +async def test_logout_success(client): + response = await client.post('/api/access/logout') + assert response.status_code == 201 + assert response.headers['Content-Type'] == 'application/json' + assert response.json() == {} + + +@pytest.mark.asyncio +async def test_logout_unauthorized(client): + response = await client.post('/api/access/logout', headers={'Authorization': 'Bearer invalid_token'}) + assert response.status_code == 401 + assert response.headers['Content-Type'] == 'application/json' + assert 'error' in response.json() + + +@pytest.mark.asyncio +async def test_logout_forbidden(client): + response = await client.post('/api/access/logout', headers={'Authorization': 'Bearer forbidden_token'}) + assert response.status_code == 403 + assert response.headers['Content-Type'] == 'application/json' + assert 'error' in response.json() + + +@pytest.mark.asyncio +async def test_logout_empty_response(client): + response = await client.post('/api/access/logout') + assert response.status_code == 201 + assert response.json() == {} + + +@pytest.mark.asyncio +async def test_logout_invalid_request(client): + # Simulate a malformed request (if applicable) + response = await client.post('/api/access/logout', json={'malformed': 'data'}) + assert response.status_code == 400 + assert response.headers['Content-Type'] == 'application/json' + assert 'error' in response.json() + + +@pytest.mark.asyncio +async def test_logout_rate_limiting(client): + # Simulate rate limiting by making multiple requests in a short time + for _ in range(10): + await client.post('/api/access/logout') + response = await client.post('/api/access/logout') + assert response.status_code == 429 + assert response.headers['Content-Type'] == 'application/json' + assert 'error' in response.json() + + +@pytest.mark.asyncio +async def test_logout_server_error(client): + # Simulate a server error (if applicable) + response = await client.post('/api/access/logout', headers={'Authorization': 'Bearer server_error_token'}) + assert response.status_code == 500 + assert response.headers['Content-Type'] == 'application/json' + assert 'error' in response.json() + + +@pytest.mark.asyncio +async def test_logout_large_payload(client): + # Test with a large payload if applicable + large_payload = {'data': 'x' * 10000} + response = await client.post('/api/access/logout', json=large_payload) + assert response.status_code == 400 + assert response.headers['Content-Type'] == 'application/json' + assert 'error' in response.json() + + +@pytest.mark.asyncio +async def test_logout_empty_string(client): + # Test with an empty string if applicable + response = await client.post('/api/access/logout', json={'data': ''}) + assert response.status_code == 400 + assert response.headers['Content-Type'] == 'application/json' + assert 'error' in response.json()