From a94080e0547d69230d879e37285ce1434dcd1901 Mon Sep 17 00:00:00 2001 From: Shri Date: Thu, 13 Feb 2025 21:29:45 +0100 Subject: [PATCH 01/71] 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 1c15f7d435e419076e2e4524d6e476a318b89035 Mon Sep 17 00:00:00 2001 From: Shri Date: Thu, 13 Feb 2025 21:31:38 +0100 Subject: [PATCH 02/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 83303f72..9b033ada 100644 --- a/README.md +++ b/README.md @@ -89,3 +89,4 @@ We <3 contributions big and small: ## Test - 1 +- 2 From ee17dc95a4db8f55be51f832b0029a5fcf76d710 Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 11:01:44 +0100 Subject: [PATCH 03/71] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 9b033ada..81eb59a4 100644 --- a/README.md +++ b/README.md @@ -90,3 +90,5 @@ We <3 contributions big and small: ## Test - 1 - 2 +- 3 +- 4 From 362863c1f2791af7863f2eaf254a8d01b7796517 Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 12:09:11 +0100 Subject: [PATCH 04/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 81eb59a4..a90d6f3a 100644 --- a/README.md +++ b/README.md @@ -92,3 +92,4 @@ We <3 contributions big and small: - 2 - 3 - 4 +- 5 From ea34be3c5f7b7f0a8a39853e23f5fbdc2947a3ac Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 12:37:38 +0100 Subject: [PATCH 05/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a90d6f3a..c0a1d026 100644 --- a/README.md +++ b/README.md @@ -93,3 +93,4 @@ We <3 contributions big and small: - 3 - 4 - 5 +- 6 From ca4693c873c9a05d9c913e76db7efd9dba67257d Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 13:04:45 +0100 Subject: [PATCH 06/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c0a1d026..733a93df 100644 --- a/README.md +++ b/README.md @@ -94,3 +94,4 @@ We <3 contributions big and small: - 4 - 5 - 6 +- 7 From 894676704a8bac661e06bf80ab280c746e02fb58 Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 13:06:16 +0100 Subject: [PATCH 07/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 733a93df..b3eda97e 100644 --- a/README.md +++ b/README.md @@ -95,3 +95,4 @@ We <3 contributions big and small: - 5 - 6 - 7 +- 8 From 125ad847e6f1738ee6c63160faa6dafad58cc849 Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 13:59:03 +0100 Subject: [PATCH 08/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b3eda97e..3c07425b 100644 --- a/README.md +++ b/README.md @@ -96,3 +96,4 @@ We <3 contributions big and small: - 6 - 7 - 8 +- 9 From ade696dd4005fdb0d57db98b6df871a3eb9bdced Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 14:32:19 +0100 Subject: [PATCH 09/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3c07425b..1c06273b 100644 --- a/README.md +++ b/README.md @@ -97,3 +97,4 @@ We <3 contributions big and small: - 7 - 8 - 9 +- 10 From e072b5f0bd0f19eecdb516bd4e2a7a6b4c6bcf3a Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 14:50:56 +0100 Subject: [PATCH 10/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1c06273b..00cb5ebb 100644 --- a/README.md +++ b/README.md @@ -98,3 +98,4 @@ We <3 contributions big and small: - 8 - 9 - 10 +- 11 From 14a639ee6050dea8c4a409c4cb7dbd38832308da Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 15:20:03 +0100 Subject: [PATCH 11/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 00cb5ebb..a049bf3a 100644 --- a/README.md +++ b/README.md @@ -99,3 +99,4 @@ We <3 contributions big and small: - 9 - 10 - 11 +- 12 From e5a4328d705c4409ac1ba3701e9d3195b40493cb Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 16:04:49 +0100 Subject: [PATCH 12/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a049bf3a..40eb8d27 100644 --- a/README.md +++ b/README.md @@ -100,3 +100,4 @@ We <3 contributions big and small: - 10 - 11 - 12 +- 13 From c955c4ba49316100a74b02b548aa170c2f116e54 Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 16:40:32 +0100 Subject: [PATCH 13/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 40eb8d27..ebc87dc2 100644 --- a/README.md +++ b/README.md @@ -101,3 +101,4 @@ We <3 contributions big and small: - 11 - 12 - 13 +- 14 From a19a82ce11f8acd103023fb36dff0fe246f76148 Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 16:47:41 +0100 Subject: [PATCH 14/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ebc87dc2..5175b002 100644 --- a/README.md +++ b/README.md @@ -102,3 +102,4 @@ We <3 contributions big and small: - 12 - 13 - 14 +- 15 From 136c62805b722b25cd9b64fec83f7f936ce835b3 Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 17:28:56 +0100 Subject: [PATCH 15/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5175b002..e4f39182 100644 --- a/README.md +++ b/README.md @@ -103,3 +103,4 @@ We <3 contributions big and small: - 13 - 14 - 15 +- 16 From af631b2ffdc0882bf61314ac68780c66cfce3a64 Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 17:39:04 +0100 Subject: [PATCH 16/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e4f39182..6fc2f14e 100644 --- a/README.md +++ b/README.md @@ -104,3 +104,4 @@ We <3 contributions big and small: - 14 - 15 - 16 +- 17 From c4aa49ac3962f28097aa976e998b257f5cecea88 Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 17:46:00 +0100 Subject: [PATCH 17/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6fc2f14e..f2b9fbb2 100644 --- a/README.md +++ b/README.md @@ -105,3 +105,4 @@ We <3 contributions big and small: - 15 - 16 - 17 +- 18 From caad8c6a9d6e62bf94eae47a653ac1fd89bfc636 Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 17:51:30 +0100 Subject: [PATCH 18/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f2b9fbb2..054ba30c 100644 --- a/README.md +++ b/README.md @@ -106,3 +106,4 @@ We <3 contributions big and small: - 16 - 17 - 18 +- 20 From 338b39b8668fb69b6663fcbb9f7674bfa6b07fb9 Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 16:51:59 +0000 Subject: [PATCH 19/71] Add api tests generated by Chapter --- .../validation/test_post_api-access-login.py | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 chapter_api_tests/0.2.0/validation/test_post_api-access-login.py diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py new file mode 100644 index 00000000..a5f7c582 --- /dev/null +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -0,0 +1,120 @@ +import os +import pytest +import httpx + +API_BASE_URL = os.getenv('API_BASE_URL') + + +@pytest.mark.asyncio +async def test_login_success(): + url = f'{API_BASE_URL}/api/access/login' + payload = {'username': 'testuser', 'password': 'testpass'} + response = await httpx.post(url, json=payload) + + assert response.status_code == 201 + assert response.headers['Content-Type'] == 'application/json' + assert 'access_token' in response.json() + assert 'token_type' in response.json() + + +@pytest.mark.asyncio +async def test_login_missing_username(): + url = f'{API_BASE_URL}/api/access/login' + payload = {'password': 'testpass'} + response = await httpx.post(url, json=payload) + + assert response.status_code == 400 + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' + + +@pytest.mark.asyncio +async def test_login_missing_password(): + url = f'{API_BASE_URL}/api/access/login' + payload = {'username': 'testuser'} + response = await httpx.post(url, json=payload) + + assert response.status_code == 400 + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' + + +@pytest.mark.asyncio +async def test_login_empty_username(): + url = f'{API_BASE_URL}/api/access/login' + payload = {'username': '', 'password': 'testpass'} + response = await httpx.post(url, json=payload) + + assert response.status_code == 400 + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' + + +@pytest.mark.asyncio +async def test_login_empty_password(): + url = f'{API_BASE_URL}/api/access/login' + payload = {'username': 'testuser', 'password': ''} + response = await httpx.post(url, json=payload) + + assert response.status_code == 400 + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' + + +@pytest.mark.asyncio +async def test_login_invalid_credentials(): + url = f'{API_BASE_URL}/api/access/login' + payload = {'username': 'invaliduser', 'password': 'wrongpass'} + response = await httpx.post(url, json=payload) + + assert response.status_code == 400 + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' + + +@pytest.mark.asyncio +async def test_login_large_payload(): + url = f'{API_BASE_URL}/api/access/login' + payload = {'username': 'testuser', 'password': 'testpass' * 1000} + response = await httpx.post(url, json=payload) + + assert response.status_code == 400 + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' + + +@pytest.mark.asyncio +async def test_login_unauthorized(): + url = f'{API_BASE_URL}/api/access/login' + payload = {'username': 'testuser', 'password': 'wrongpass'} + response = await httpx.post(url, json=payload) + + assert response.status_code == 401 + + +@pytest.mark.asyncio +async def test_login_forbidden(): + url = f'{API_BASE_URL}/api/access/login' + payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} + response = await httpx.post(url, json=payload) + + assert response.status_code == 403 + + +@pytest.mark.asyncio +async def test_login_malformed_request(): + url = f'{API_BASE_URL}/api/access/login' + response = await httpx.post(url, data='malformed data') + + assert response.status_code == 400 + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' + + +@pytest.mark.asyncio +async def test_login_server_error(): + url = f'{API_BASE_URL}/api/access/login' + # Simulate server error by sending a request to an invalid endpoint + response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) + + assert response.status_code == 500 From fba7fc5d948c45d59db405020210e0fa753836bf Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 16:52:25 +0000 Subject: [PATCH 20/71] Add api tests generated by Chapter --- .../validation/test_post_api-access-login.py | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index a5f7c582..03adccc2 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -40,7 +40,7 @@ async def test_login_missing_password(): @pytest.mark.asyncio -async def test_login_empty_username(): +async def test_login_invalid_username(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': '', 'password': 'testpass'} response = await httpx.post(url, json=payload) @@ -51,7 +51,7 @@ async def test_login_empty_username(): @pytest.mark.asyncio -async def test_login_empty_password(): +async def test_login_invalid_password(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser', 'password': ''} response = await httpx.post(url, json=payload) @@ -64,7 +64,16 @@ async def test_login_empty_password(): @pytest.mark.asyncio async def test_login_invalid_credentials(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'invaliduser', 'password': 'wrongpass'} + payload = {'username': 'invaliduser', 'password': 'invalidpass'} + response = await httpx.post(url, json=payload) + + assert response.status_code == 401 + + +@pytest.mark.asyncio +async def test_login_empty_payload(): + url = f'{API_BASE_URL}/api/access/login' + payload = {} response = await httpx.post(url, json=payload) assert response.status_code == 400 @@ -95,26 +104,17 @@ async def test_login_unauthorized(): @pytest.mark.asyncio async def test_login_forbidden(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} + # Assuming there's a mechanism to block certain users + payload = {'username': 'blockeduser', 'password': 'testpass'} response = await httpx.post(url, json=payload) assert response.status_code == 403 -@pytest.mark.asyncio -async def test_login_malformed_request(): - url = f'{API_BASE_URL}/api/access/login' - response = await httpx.post(url, data='malformed data') - - assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' - - @pytest.mark.asyncio async def test_login_server_error(): url = f'{API_BASE_URL}/api/access/login' - # Simulate server error by sending a request to an invalid endpoint - response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) + # Simulate server error by sending a malformed request + response = await httpx.post(url, data='malformed data') assert response.status_code == 500 From 3147d9672408d91ffb235eaa45fde6f47c93083b Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 16:52:52 +0000 Subject: [PATCH 21/71] Add api tests generated by Chapter --- .../validation/test_post_api-access-login.py | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index 03adccc2..7d4dcbe1 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -40,7 +40,7 @@ async def test_login_missing_password(): @pytest.mark.asyncio -async def test_login_invalid_username(): +async def test_login_empty_username(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': '', 'password': 'testpass'} response = await httpx.post(url, json=payload) @@ -51,7 +51,7 @@ async def test_login_invalid_username(): @pytest.mark.asyncio -async def test_login_invalid_password(): +async def test_login_empty_password(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser', 'password': ''} response = await httpx.post(url, json=payload) @@ -67,15 +67,6 @@ async def test_login_invalid_credentials(): payload = {'username': 'invaliduser', 'password': 'invalidpass'} response = await httpx.post(url, json=payload) - assert response.status_code == 401 - - -@pytest.mark.asyncio -async def test_login_empty_payload(): - url = f'{API_BASE_URL}/api/access/login' - payload = {} - response = await httpx.post(url, json=payload) - assert response.status_code == 400 assert response.json()['status_code'] == 400 assert response.json()['detail'] == 'Bad Request' @@ -104,17 +95,26 @@ async def test_login_unauthorized(): @pytest.mark.asyncio async def test_login_forbidden(): url = f'{API_BASE_URL}/api/access/login' - # Assuming there's a mechanism to block certain users - payload = {'username': 'blockeduser', 'password': 'testpass'} + payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} response = await httpx.post(url, json=payload) assert response.status_code == 403 @pytest.mark.asyncio -async def test_login_server_error(): +async def test_login_malformed_request(): url = f'{API_BASE_URL}/api/access/login' - # Simulate server error by sending a malformed request response = await httpx.post(url, data='malformed data') + assert response.status_code == 400 + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' + + +@pytest.mark.asyncio +async def test_login_server_error(): + url = f'{API_BASE_URL}/api/access/login' + # Simulate server error by sending a request to an invalid endpoint + response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) + assert response.status_code == 500 From 42d12b7634a547d921b9a24ef8787861640cbee0 Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 16:53:20 +0000 Subject: [PATCH 22/71] Add api tests generated by Chapter --- .../validation/test_post_api-access-login.py | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index 7d4dcbe1..64629151 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -64,7 +64,7 @@ async def test_login_empty_password(): @pytest.mark.asyncio async def test_login_invalid_credentials(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'invaliduser', 'password': 'invalidpass'} + payload = {'username': 'invaliduser', 'password': 'wrongpass'} response = await httpx.post(url, json=payload) assert response.status_code == 400 @@ -86,8 +86,10 @@ async def test_login_large_payload(): @pytest.mark.asyncio async def test_login_unauthorized(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'testuser', 'password': 'wrongpass'} - response = await httpx.post(url, json=payload) + # Assuming the API requires a token for some reason + headers = {'Authorization': 'Bearer invalid_token'} + payload = {'username': 'testuser', 'password': 'testpass'} + response = await httpx.post(url, json=payload, headers=headers) assert response.status_code == 401 @@ -95,8 +97,10 @@ async def test_login_unauthorized(): @pytest.mark.asyncio async def test_login_forbidden(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} - response = await httpx.post(url, json=payload) + # Assuming the API has some role-based access + headers = {'Authorization': 'Bearer forbidden_token'} + payload = {'username': 'testuser', 'password': 'testpass'} + response = await httpx.post(url, json=payload, headers=headers) assert response.status_code == 403 @@ -104,7 +108,7 @@ async def test_login_forbidden(): @pytest.mark.asyncio async def test_login_malformed_request(): url = f'{API_BASE_URL}/api/access/login' - response = await httpx.post(url, data='malformed data') + response = await httpx.post(url, data='malformed_data') assert response.status_code == 400 assert response.json()['status_code'] == 400 @@ -114,7 +118,9 @@ async def test_login_malformed_request(): @pytest.mark.asyncio async def test_login_server_error(): url = f'{API_BASE_URL}/api/access/login' - # Simulate server error by sending a request to an invalid endpoint - response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) + # Simulate a server error by sending a request that triggers it + payload = {'username': 'testuser', 'password': 'testpass'} + response = await httpx.post(url, json=payload) + # Assuming the server is down or there's an internal error assert response.status_code == 500 From e4a7e5f77c441d2e7ffc38ce84f5a2ef6073a6e2 Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 16:54:51 +0000 Subject: [PATCH 23/71] Add api tests generated by Chapter --- .../validation/test_post_api-access-login.py | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index 64629151..a5f7c582 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -86,10 +86,8 @@ async def test_login_large_payload(): @pytest.mark.asyncio async def test_login_unauthorized(): url = f'{API_BASE_URL}/api/access/login' - # Assuming the API requires a token for some reason - headers = {'Authorization': 'Bearer invalid_token'} - payload = {'username': 'testuser', 'password': 'testpass'} - response = await httpx.post(url, json=payload, headers=headers) + payload = {'username': 'testuser', 'password': 'wrongpass'} + response = await httpx.post(url, json=payload) assert response.status_code == 401 @@ -97,10 +95,8 @@ async def test_login_unauthorized(): @pytest.mark.asyncio async def test_login_forbidden(): url = f'{API_BASE_URL}/api/access/login' - # Assuming the API has some role-based access - headers = {'Authorization': 'Bearer forbidden_token'} - payload = {'username': 'testuser', 'password': 'testpass'} - response = await httpx.post(url, json=payload, headers=headers) + payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} + response = await httpx.post(url, json=payload) assert response.status_code == 403 @@ -108,7 +104,7 @@ async def test_login_forbidden(): @pytest.mark.asyncio async def test_login_malformed_request(): url = f'{API_BASE_URL}/api/access/login' - response = await httpx.post(url, data='malformed_data') + response = await httpx.post(url, data='malformed data') assert response.status_code == 400 assert response.json()['status_code'] == 400 @@ -118,9 +114,7 @@ async def test_login_malformed_request(): @pytest.mark.asyncio async def test_login_server_error(): url = f'{API_BASE_URL}/api/access/login' - # Simulate a server error by sending a request that triggers it - payload = {'username': 'testuser', 'password': 'testpass'} - response = await httpx.post(url, json=payload) + # Simulate server error by sending a request to an invalid endpoint + response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) - # Assuming the server is down or there's an internal error assert response.status_code == 500 From b199378ee44653b306c353a44a7e4c8af678b2c7 Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 16:55:22 +0000 Subject: [PATCH 24/71] Add api tests generated by Chapter From fe4b1759e8378a02d22e34a186a4e7ddc96bcf09 Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 16:56:05 +0000 Subject: [PATCH 25/71] Add api tests generated by Chapter --- .../0.2.0/validation/test_post_api-access-login.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index a5f7c582..7d4dcbe1 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -64,7 +64,7 @@ async def test_login_empty_password(): @pytest.mark.asyncio async def test_login_invalid_credentials(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'invaliduser', 'password': 'wrongpass'} + payload = {'username': 'invaliduser', 'password': 'invalidpass'} response = await httpx.post(url, json=payload) assert response.status_code == 400 From d0118db524da1e1a13f3f682776c10ce7f437ae7 Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 16:56:36 +0000 Subject: [PATCH 26/71] Add api tests generated by Chapter --- .../validation/test_post_api-access-login.py | 61 +++++++++---------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index 7d4dcbe1..7a141f40 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -10,11 +10,11 @@ async def test_login_success(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser', 'password': 'testpass'} response = await httpx.post(url, json=payload) - assert response.status_code == 201 assert response.headers['Content-Type'] == 'application/json' - assert 'access_token' in response.json() - assert 'token_type' in response.json() + data = response.json() + assert 'access_token' in data + assert 'token_type' in data @pytest.mark.asyncio @@ -22,10 +22,11 @@ async def test_login_missing_username(): url = f'{API_BASE_URL}/api/access/login' payload = {'password': 'testpass'} response = await httpx.post(url, json=payload) - assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -33,10 +34,11 @@ async def test_login_missing_password(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser'} response = await httpx.post(url, json=payload) - assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -44,10 +46,11 @@ async def test_login_empty_username(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': '', 'password': 'testpass'} response = await httpx.post(url, json=payload) - assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -55,21 +58,20 @@ async def test_login_empty_password(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser', 'password': ''} response = await httpx.post(url, json=payload) - assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' @pytest.mark.asyncio async def test_login_invalid_credentials(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'invaliduser', 'password': 'invalidpass'} + payload = {'username': 'invaliduser', 'password': 'wrongpass'} response = await httpx.post(url, json=payload) - - assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert response.status_code == 401 + assert response.headers['Content-Type'] == 'application/json' @pytest.mark.asyncio @@ -77,19 +79,16 @@ async def test_login_large_payload(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser', 'password': 'testpass' * 1000} response = await httpx.post(url, json=payload) - assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert response.headers['Content-Type'] == 'application/json' @pytest.mark.asyncio async def test_login_unauthorized(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'testuser', 'password': 'wrongpass'} - response = await httpx.post(url, json=payload) - - assert response.status_code == 401 + response = await httpx.post(url, json={}) + assert response.status_code == 400 + assert response.headers['Content-Type'] == 'application/json' @pytest.mark.asyncio @@ -97,18 +96,16 @@ async def test_login_forbidden(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} response = await httpx.post(url, json=payload) - assert response.status_code == 403 + assert response.headers['Content-Type'] == 'application/json' @pytest.mark.asyncio async def test_login_malformed_request(): url = f'{API_BASE_URL}/api/access/login' response = await httpx.post(url, data='malformed data') - assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert response.headers['Content-Type'] == 'application/json' @pytest.mark.asyncio @@ -116,5 +113,5 @@ async def test_login_server_error(): url = f'{API_BASE_URL}/api/access/login' # Simulate server error by sending a request to an invalid endpoint response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) - assert response.status_code == 500 + assert response.headers['Content-Type'] == 'application/json' From 133861af52bf9f82a56d2a952b27480226d45eff Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 16:57:08 +0000 Subject: [PATCH 27/71] Add api tests generated by Chapter --- .../validation/test_post_api-access-login.py | 47 ++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index 7a141f40..1518bb63 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -10,6 +10,7 @@ async def test_login_success(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser', 'password': 'testpass'} response = await httpx.post(url, json=payload) + assert response.status_code == 201 assert response.headers['Content-Type'] == 'application/json' data = response.json() @@ -22,6 +23,7 @@ async def test_login_missing_username(): url = f'{API_BASE_URL}/api/access/login' payload = {'password': 'testpass'} response = await httpx.post(url, json=payload) + assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' data = response.json() @@ -34,6 +36,7 @@ async def test_login_missing_password(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser'} response = await httpx.post(url, json=payload) + assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' data = response.json() @@ -46,6 +49,7 @@ async def test_login_empty_username(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': '', 'password': 'testpass'} response = await httpx.post(url, json=payload) + assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' data = response.json() @@ -58,6 +62,7 @@ async def test_login_empty_password(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser', 'password': ''} response = await httpx.post(url, json=payload) + assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' data = response.json() @@ -70,48 +75,58 @@ async def test_login_invalid_credentials(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'invaliduser', 'password': 'wrongpass'} response = await httpx.post(url, json=payload) - assert response.status_code == 401 + + assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' @pytest.mark.asyncio async def test_login_large_payload(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'testuser', 'password': 'testpass' * 1000} + payload = {'username': 'testuser', 'password': 'testpass', 'extra_field': 'x' * 10000} response = await httpx.post(url, json=payload) + assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' @pytest.mark.asyncio async def test_login_unauthorized(): url = f'{API_BASE_URL}/api/access/login' - response = await httpx.post(url, json={}) + response = await httpx.post(url, json={}) # No credentials + assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' @pytest.mark.asyncio -async def test_login_forbidden(): +async def test_login_invalid_json(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} - response = await httpx.post(url, json=payload) - assert response.status_code == 403 - assert response.headers['Content-Type'] == 'application/json' - + response = await httpx.post(url, data='invalid_json') -@pytest.mark.asyncio -async def test_login_malformed_request(): - url = f'{API_BASE_URL}/api/access/login' - response = await httpx.post(url, data='malformed data') assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' @pytest.mark.asyncio async def test_login_server_error(): url = f'{API_BASE_URL}/api/access/login' - # Simulate server error by sending a request to an invalid endpoint - response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) - assert response.status_code == 500 + # Simulate server error by sending a request that triggers it + payload = {'username': 'testuser', 'password': 'trigger_error'} + response = await httpx.post(url, json=payload) + + assert response.status_code == 500 # Assuming this triggers a server error assert response.headers['Content-Type'] == 'application/json' + From 7d7535f5fb211f854e234c7ebfa94c7ca721857f Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 16:57:42 +0000 Subject: [PATCH 28/71] Add api tests generated by Chapter --- .../validation/test_post_api-access-login.py | 74 ++++++++++--------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index 1518bb63..f73c35f0 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -13,9 +13,8 @@ async def test_login_success(): assert response.status_code == 201 assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert 'access_token' in data - assert 'token_type' in data + assert 'access_token' in response.json() + assert 'token_type' in response.json() @pytest.mark.asyncio @@ -26,9 +25,8 @@ async def test_login_missing_username(): assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' + assert response.json()['status_code'] == 400 + assert 'detail' in response.json() @pytest.mark.asyncio @@ -39,9 +37,8 @@ async def test_login_missing_password(): assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' + assert response.json()['status_code'] == 400 + assert 'detail' in response.json() @pytest.mark.asyncio @@ -52,9 +49,8 @@ async def test_login_empty_username(): assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' + assert response.json()['status_code'] == 400 + assert 'detail' in response.json() @pytest.mark.asyncio @@ -65,9 +61,8 @@ async def test_login_empty_password(): assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' + assert response.json()['status_code'] == 400 + assert 'detail' in response.json() @pytest.mark.asyncio @@ -78,55 +73,62 @@ async def test_login_invalid_credentials(): assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' + assert response.json()['status_code'] == 400 + assert 'detail' in response.json() @pytest.mark.asyncio async def test_login_large_payload(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'testuser', 'password': 'testpass', 'extra_field': 'x' * 10000} + payload = {'username': 'testuser', 'password': 'testpass' * 1000} response = await httpx.post(url, json=payload) assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' + assert response.json()['status_code'] == 400 + assert 'detail' in response.json() @pytest.mark.asyncio async def test_login_unauthorized(): url = f'{API_BASE_URL}/api/access/login' - response = await httpx.post(url, json={}) # No credentials + payload = {'username': 'testuser', 'password': 'wrongpass'} + response = await httpx.post(url, json=payload) assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' + assert response.json()['status_code'] == 400 + assert 'detail' in response.json() @pytest.mark.asyncio -async def test_login_invalid_json(): +async def test_login_forbidden(): url = f'{API_BASE_URL}/api/access/login' - response = await httpx.post(url, data='invalid_json') + payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} + response = await httpx.post(url, json=payload) assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' + assert response.json()['status_code'] == 400 + assert 'detail' in response.json() @pytest.mark.asyncio -async def test_login_server_error(): +async def test_login_malformed_request(): url = f'{API_BASE_URL}/api/access/login' - # Simulate server error by sending a request that triggers it - payload = {'username': 'testuser', 'password': 'trigger_error'} - response = await httpx.post(url, json=payload) + response = await httpx.post(url, data='malformed data') - assert response.status_code == 500 # Assuming this triggers a server error + assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' + assert response.json()['status_code'] == 400 + assert 'detail' in response.json() + +@pytest.mark.asyncio +async def test_login_server_error(): + url = f'{API_BASE_URL}/api/access/login' + # Simulate server error by sending a request to an invalid endpoint + response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) + + assert response.status_code == 404 + assert response.headers['Content-Type'] == 'application/json' From e6be66b168af03794e034ac917ac25e52fb660f7 Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 16:58:15 +0000 Subject: [PATCH 29/71] Add api tests generated by Chapter --- .../validation/test_post_api-access-login.py | 81 ++++++++++--------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index f73c35f0..e29e25a0 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -13,8 +13,9 @@ async def test_login_success(): assert response.status_code == 201 assert response.headers['Content-Type'] == 'application/json' - assert 'access_token' in response.json() - assert 'token_type' in response.json() + data = response.json() + assert 'access_token' in data + assert 'token_type' in data @pytest.mark.asyncio @@ -25,8 +26,10 @@ async def test_login_missing_username(): assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' - assert response.json()['status_code'] == 400 - assert 'detail' in response.json() + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' + assert 'extra' in data @pytest.mark.asyncio @@ -37,8 +40,10 @@ async def test_login_missing_password(): assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' - assert response.json()['status_code'] == 400 - assert 'detail' in response.json() + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' + assert 'extra' in data @pytest.mark.asyncio @@ -49,8 +54,10 @@ async def test_login_empty_username(): assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' - assert response.json()['status_code'] == 400 - assert 'detail' in response.json() + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' + assert 'extra' in data @pytest.mark.asyncio @@ -61,8 +68,10 @@ async def test_login_empty_password(): assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' - assert response.json()['status_code'] == 400 - assert 'detail' in response.json() + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' + assert 'extra' in data @pytest.mark.asyncio @@ -71,10 +80,10 @@ async def test_login_invalid_credentials(): payload = {'username': 'invaliduser', 'password': 'wrongpass'} response = await httpx.post(url, json=payload) - assert response.status_code == 400 + assert response.status_code == 401 assert response.headers['Content-Type'] == 'application/json' - assert response.json()['status_code'] == 400 - assert 'detail' in response.json() + data = response.json() + assert 'detail' in data @pytest.mark.asyncio @@ -85,50 +94,44 @@ async def test_login_large_payload(): assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' - assert response.json()['status_code'] == 400 - assert 'detail' in response.json() + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' + assert 'extra' in data @pytest.mark.asyncio async def test_login_unauthorized(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'testuser', 'password': 'wrongpass'} - response = await httpx.post(url, json=payload) - - assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - assert response.json()['status_code'] == 400 - assert 'detail' in response.json() - - -@pytest.mark.asyncio -async def test_login_forbidden(): - url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} - response = await httpx.post(url, json=payload) + response = await httpx.post(url) assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' - assert response.json()['status_code'] == 400 - assert 'detail' in response.json() + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' + assert 'extra' in data @pytest.mark.asyncio -async def test_login_malformed_request(): +async def test_login_invalid_json(): url = f'{API_BASE_URL}/api/access/login' - response = await httpx.post(url, data='malformed data') + response = await httpx.post(url, data='invalid_json') assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' - assert response.json()['status_code'] == 400 - assert 'detail' in response.json() + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' + assert 'extra' in data @pytest.mark.asyncio -async def test_login_server_error(): +async def test_login_server_error(mocker): url = f'{API_BASE_URL}/api/access/login' - # Simulate server error by sending a request to an invalid endpoint - response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) + mocker.patch('httpx.post', side_effect=httpx.HTTPStatusError('Server Error', request=None, response=httpx.Response(500))) + payload = {'username': 'testuser', 'password': 'testpass'} + response = await httpx.post(url, json=payload) - assert response.status_code == 404 + assert response.status_code == 500 assert response.headers['Content-Type'] == 'application/json' From 43f22c412d12884ff51788343fb9793a9f002c8e Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 17:00:27 +0000 Subject: [PATCH 30/71] Add api tests generated by Chapter --- .../validation/test_post_api-access-login.py | 85 ++++++++----------- 1 file changed, 34 insertions(+), 51 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index e29e25a0..a5f7c582 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -13,9 +13,8 @@ async def test_login_success(): assert response.status_code == 201 assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert 'access_token' in data - assert 'token_type' in data + assert 'access_token' in response.json() + assert 'token_type' in response.json() @pytest.mark.asyncio @@ -25,11 +24,8 @@ async def test_login_missing_username(): response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' - assert 'extra' in data + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -39,11 +35,8 @@ async def test_login_missing_password(): response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' - assert 'extra' in data + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -53,11 +46,8 @@ async def test_login_empty_username(): response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' - assert 'extra' in data + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -67,11 +57,8 @@ async def test_login_empty_password(): response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' - assert 'extra' in data + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -80,10 +67,9 @@ async def test_login_invalid_credentials(): payload = {'username': 'invaliduser', 'password': 'wrongpass'} response = await httpx.post(url, json=payload) - assert response.status_code == 401 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert 'detail' in data + assert response.status_code == 400 + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -93,45 +79,42 @@ async def test_login_large_payload(): response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' - assert 'extra' in data + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio async def test_login_unauthorized(): url = f'{API_BASE_URL}/api/access/login' - response = await httpx.post(url) + payload = {'username': 'testuser', 'password': 'wrongpass'} + response = await httpx.post(url, json=payload) - assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' - assert 'extra' in data + assert response.status_code == 401 @pytest.mark.asyncio -async def test_login_invalid_json(): +async def test_login_forbidden(): url = f'{API_BASE_URL}/api/access/login' - response = await httpx.post(url, data='invalid_json') + payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} + response = await httpx.post(url, json=payload) + + assert response.status_code == 403 + + +@pytest.mark.asyncio +async def test_login_malformed_request(): + url = f'{API_BASE_URL}/api/access/login' + response = await httpx.post(url, data='malformed data') assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' - assert 'extra' in data + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio -async def test_login_server_error(mocker): +async def test_login_server_error(): url = f'{API_BASE_URL}/api/access/login' - mocker.patch('httpx.post', side_effect=httpx.HTTPStatusError('Server Error', request=None, response=httpx.Response(500))) - payload = {'username': 'testuser', 'password': 'testpass'} - response = await httpx.post(url, json=payload) + # Simulate server error by sending a request to an invalid endpoint + response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) assert response.status_code == 500 - assert response.headers['Content-Type'] == 'application/json' From aa615920e5083f8c0af424eab8d3ab4c37a196a6 Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 19:13:56 +0100 Subject: [PATCH 31/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 054ba30c..c9b855ea 100644 --- a/README.md +++ b/README.md @@ -107,3 +107,4 @@ We <3 contributions big and small: - 17 - 18 - 20 +- 21 From 33e80d870dc8832f1e2bc339884531a58ab6f44f Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 19:19:03 +0100 Subject: [PATCH 32/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c9b855ea..3dc163c7 100644 --- a/README.md +++ b/README.md @@ -108,3 +108,4 @@ We <3 contributions big and small: - 18 - 20 - 21 +- 22 From c5362b08319974dde59f229c4d3d485c5cf9b859 Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 19:27:32 +0100 Subject: [PATCH 33/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3dc163c7..f42f86a0 100644 --- a/README.md +++ b/README.md @@ -109,3 +109,4 @@ We <3 contributions big and small: - 20 - 21 - 22 +- 23 From 002e652a701833eedd920297a90f87548d0b6dee Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 19:31:55 +0100 Subject: [PATCH 34/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f42f86a0..1b2d0af2 100644 --- a/README.md +++ b/README.md @@ -110,3 +110,4 @@ We <3 contributions big and small: - 21 - 22 - 23 +- 24 From 386fbe2d92ca86348db255385fbd916414283d70 Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 19:47:02 +0100 Subject: [PATCH 35/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1b2d0af2..31bd6b18 100644 --- a/README.md +++ b/README.md @@ -111,3 +111,4 @@ We <3 contributions big and small: - 22 - 23 - 24 +- 25 From 642ea52b01440794d67fd3b645db7306ac4b2e30 Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 19:51:20 +0100 Subject: [PATCH 36/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 31bd6b18..38f0e2bb 100644 --- a/README.md +++ b/README.md @@ -112,3 +112,4 @@ We <3 contributions big and small: - 23 - 24 - 25 +- 26 From 1489cea53dee023c68688650d1cdd136535ca203 Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 19:54:02 +0100 Subject: [PATCH 37/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 38f0e2bb..771d31b0 100644 --- a/README.md +++ b/README.md @@ -113,3 +113,4 @@ We <3 contributions big and small: - 24 - 25 - 26 +- 27 From d05488348bd45db9ef0c3e5db2553e83deabe1fa Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 20:22:55 +0100 Subject: [PATCH 38/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 771d31b0..771ea17a 100644 --- a/README.md +++ b/README.md @@ -114,3 +114,4 @@ We <3 contributions big and small: - 25 - 26 - 27 +- 28 From d7a7fe2ce4f080be35543b59c1ffec5b6884b009 Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 19:23:27 +0000 Subject: [PATCH 39/71] test(api): add tests generated by Chapter --- .../validation/test_post_api-access-login.py | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index a5f7c582..e4db33e3 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -86,8 +86,10 @@ async def test_login_large_payload(): @pytest.mark.asyncio async def test_login_unauthorized(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'testuser', 'password': 'wrongpass'} - response = await httpx.post(url, json=payload) + # Assuming the API requires a token for some reason + headers = {'Authorization': 'Bearer invalid_token'} + payload = {'username': 'testuser', 'password': 'testpass'} + response = await httpx.post(url, json=payload, headers=headers) assert response.status_code == 401 @@ -95,8 +97,10 @@ async def test_login_unauthorized(): @pytest.mark.asyncio async def test_login_forbidden(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} - response = await httpx.post(url, json=payload) + # Assuming the API has some roles and this user is not allowed to login + headers = {'Authorization': 'Bearer forbidden_token'} + payload = {'username': 'testuser', 'password': 'testpass'} + response = await httpx.post(url, json=payload, headers=headers) assert response.status_code == 403 @@ -104,7 +108,7 @@ async def test_login_forbidden(): @pytest.mark.asyncio async def test_login_malformed_request(): url = f'{API_BASE_URL}/api/access/login' - response = await httpx.post(url, data='malformed data') + response = await httpx.post(url, data='malformed_data') assert response.status_code == 400 assert response.json()['status_code'] == 400 @@ -114,7 +118,9 @@ async def test_login_malformed_request(): @pytest.mark.asyncio async def test_login_server_error(): url = f'{API_BASE_URL}/api/access/login' - # Simulate server error by sending a request to an invalid endpoint - response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) + # Simulate a server error by sending a request that triggers it + payload = {'username': 'testuser', 'password': 'testpass'} + with httpx.MockTransport(lambda request: httpx.Response(500)): + response = await httpx.post(url, json=payload) assert response.status_code == 500 From a82dd5aed3f4304912617e600bb42a7997fc2439 Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 19:23:58 +0000 Subject: [PATCH 40/71] test(api): add tests generated by Chapter --- .../validation/test_post_api-access-login.py | 54 +++++++++++-------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index e4db33e3..f73c35f0 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -24,8 +24,9 @@ async def test_login_missing_username(): response = await httpx.post(url, json=payload) assert response.status_code == 400 + assert response.headers['Content-Type'] == 'application/json' assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert 'detail' in response.json() @pytest.mark.asyncio @@ -35,8 +36,9 @@ async def test_login_missing_password(): response = await httpx.post(url, json=payload) assert response.status_code == 400 + assert response.headers['Content-Type'] == 'application/json' assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert 'detail' in response.json() @pytest.mark.asyncio @@ -46,8 +48,9 @@ async def test_login_empty_username(): response = await httpx.post(url, json=payload) assert response.status_code == 400 + assert response.headers['Content-Type'] == 'application/json' assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert 'detail' in response.json() @pytest.mark.asyncio @@ -57,8 +60,9 @@ async def test_login_empty_password(): response = await httpx.post(url, json=payload) assert response.status_code == 400 + assert response.headers['Content-Type'] == 'application/json' assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert 'detail' in response.json() @pytest.mark.asyncio @@ -68,8 +72,9 @@ async def test_login_invalid_credentials(): response = await httpx.post(url, json=payload) assert response.status_code == 400 + assert response.headers['Content-Type'] == 'application/json' assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert 'detail' in response.json() @pytest.mark.asyncio @@ -79,48 +84,51 @@ async def test_login_large_payload(): response = await httpx.post(url, json=payload) assert response.status_code == 400 + assert response.headers['Content-Type'] == 'application/json' assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert 'detail' in response.json() @pytest.mark.asyncio async def test_login_unauthorized(): url = f'{API_BASE_URL}/api/access/login' - # Assuming the API requires a token for some reason - headers = {'Authorization': 'Bearer invalid_token'} - payload = {'username': 'testuser', 'password': 'testpass'} - response = await httpx.post(url, json=payload, headers=headers) + payload = {'username': 'testuser', 'password': 'wrongpass'} + response = await httpx.post(url, json=payload) - assert response.status_code == 401 + assert response.status_code == 400 + assert response.headers['Content-Type'] == 'application/json' + assert response.json()['status_code'] == 400 + assert 'detail' in response.json() @pytest.mark.asyncio async def test_login_forbidden(): url = f'{API_BASE_URL}/api/access/login' - # Assuming the API has some roles and this user is not allowed to login - headers = {'Authorization': 'Bearer forbidden_token'} - payload = {'username': 'testuser', 'password': 'testpass'} - response = await httpx.post(url, json=payload, headers=headers) + payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} + response = await httpx.post(url, json=payload) - assert response.status_code == 403 + assert response.status_code == 400 + assert response.headers['Content-Type'] == 'application/json' + assert response.json()['status_code'] == 400 + assert 'detail' in response.json() @pytest.mark.asyncio async def test_login_malformed_request(): url = f'{API_BASE_URL}/api/access/login' - response = await httpx.post(url, data='malformed_data') + response = await httpx.post(url, data='malformed data') assert response.status_code == 400 + assert response.headers['Content-Type'] == 'application/json' assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert 'detail' in response.json() @pytest.mark.asyncio async def test_login_server_error(): url = f'{API_BASE_URL}/api/access/login' - # Simulate a server error by sending a request that triggers it - payload = {'username': 'testuser', 'password': 'testpass'} - with httpx.MockTransport(lambda request: httpx.Response(500)): - response = await httpx.post(url, json=payload) + # Simulate server error by sending a request to an invalid endpoint + response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) - assert response.status_code == 500 + assert response.status_code == 404 + assert response.headers['Content-Type'] == 'application/json' From d9f03b599a93f4937248a41114b0fe1932048f16 Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 19:24:31 +0000 Subject: [PATCH 41/71] test(api): add tests generated by Chapter --- .../validation/test_post_api-access-login.py | 59 +++++++++++-------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index f73c35f0..ac7df7ea 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -13,8 +13,9 @@ async def test_login_success(): assert response.status_code == 201 assert response.headers['Content-Type'] == 'application/json' - assert 'access_token' in response.json() - assert 'token_type' in response.json() + data = response.json() + assert 'access_token' in data + assert 'token_type' in data @pytest.mark.asyncio @@ -25,8 +26,9 @@ async def test_login_missing_username(): assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' - assert response.json()['status_code'] == 400 - assert 'detail' in response.json() + data = response.json() + assert data['status_code'] == 400 + assert 'detail' in data @pytest.mark.asyncio @@ -37,8 +39,9 @@ async def test_login_missing_password(): assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' - assert response.json()['status_code'] == 400 - assert 'detail' in response.json() + data = response.json() + assert data['status_code'] == 400 + assert 'detail' in data @pytest.mark.asyncio @@ -49,8 +52,9 @@ async def test_login_empty_username(): assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' - assert response.json()['status_code'] == 400 - assert 'detail' in response.json() + data = response.json() + assert data['status_code'] == 400 + assert 'detail' in data @pytest.mark.asyncio @@ -61,8 +65,9 @@ async def test_login_empty_password(): assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' - assert response.json()['status_code'] == 400 - assert 'detail' in response.json() + data = response.json() + assert data['status_code'] == 400 + assert 'detail' in data @pytest.mark.asyncio @@ -71,10 +76,10 @@ async def test_login_invalid_credentials(): payload = {'username': 'invaliduser', 'password': 'wrongpass'} response = await httpx.post(url, json=payload) - assert response.status_code == 400 + assert response.status_code == 401 assert response.headers['Content-Type'] == 'application/json' - assert response.json()['status_code'] == 400 - assert 'detail' in response.json() + data = response.json() + assert 'detail' in data @pytest.mark.asyncio @@ -85,20 +90,21 @@ async def test_login_large_payload(): assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' - assert response.json()['status_code'] == 400 - assert 'detail' in response.json() + data = response.json() + assert data['status_code'] == 400 + assert 'detail' in data @pytest.mark.asyncio async def test_login_unauthorized(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'testuser', 'password': 'wrongpass'} - response = await httpx.post(url, json=payload) + response = await httpx.post(url, json={}) assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' - assert response.json()['status_code'] == 400 - assert 'detail' in response.json() + data = response.json() + assert data['status_code'] == 400 + assert 'detail' in data @pytest.mark.asyncio @@ -107,10 +113,10 @@ async def test_login_forbidden(): payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} response = await httpx.post(url, json=payload) - assert response.status_code == 400 + assert response.status_code == 403 assert response.headers['Content-Type'] == 'application/json' - assert response.json()['status_code'] == 400 - assert 'detail' in response.json() + data = response.json() + assert 'detail' in data @pytest.mark.asyncio @@ -120,8 +126,9 @@ async def test_login_malformed_request(): assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' - assert response.json()['status_code'] == 400 - assert 'detail' in response.json() + data = response.json() + assert data['status_code'] == 400 + assert 'detail' in data @pytest.mark.asyncio @@ -130,5 +137,7 @@ async def test_login_server_error(): # Simulate server error by sending a request to an invalid endpoint response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) - assert response.status_code == 404 + assert response.status_code == 500 assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert 'detail' in data From 577cf82e6dc41f58f189e72d4366db2f2fae05ea Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 19:26:08 +0000 Subject: [PATCH 42/71] test(api): add tests generated by Chapter --- .../validation/test_post_api-access-login.py | 63 ++++++------------- 1 file changed, 20 insertions(+), 43 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index ac7df7ea..a5f7c582 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -13,9 +13,8 @@ async def test_login_success(): assert response.status_code == 201 assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert 'access_token' in data - assert 'token_type' in data + assert 'access_token' in response.json() + assert 'token_type' in response.json() @pytest.mark.asyncio @@ -25,10 +24,8 @@ async def test_login_missing_username(): response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert 'detail' in data + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -38,10 +35,8 @@ async def test_login_missing_password(): response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert 'detail' in data + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -51,10 +46,8 @@ async def test_login_empty_username(): response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert 'detail' in data + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -64,10 +57,8 @@ async def test_login_empty_password(): response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert 'detail' in data + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -76,10 +67,9 @@ async def test_login_invalid_credentials(): payload = {'username': 'invaliduser', 'password': 'wrongpass'} response = await httpx.post(url, json=payload) - assert response.status_code == 401 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert 'detail' in data + assert response.status_code == 400 + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -89,22 +79,17 @@ async def test_login_large_payload(): response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert 'detail' in data + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio async def test_login_unauthorized(): url = f'{API_BASE_URL}/api/access/login' - response = await httpx.post(url, json={}) + payload = {'username': 'testuser', 'password': 'wrongpass'} + response = await httpx.post(url, json=payload) - assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert 'detail' in data + assert response.status_code == 401 @pytest.mark.asyncio @@ -114,9 +99,6 @@ async def test_login_forbidden(): response = await httpx.post(url, json=payload) assert response.status_code == 403 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert 'detail' in data @pytest.mark.asyncio @@ -125,10 +107,8 @@ async def test_login_malformed_request(): response = await httpx.post(url, data='malformed data') assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert 'detail' in data + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -138,6 +118,3 @@ async def test_login_server_error(): response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) assert response.status_code == 500 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert 'detail' in data From ae2a7991c1bb64ffc3e9060247c0c988562e133c Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 19:26:36 +0000 Subject: [PATCH 43/71] test(api): add tests generated by Chapter --- .../validation/test_post_api-access-login.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index a5f7c582..580af56d 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -86,8 +86,10 @@ async def test_login_large_payload(): @pytest.mark.asyncio async def test_login_unauthorized(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'testuser', 'password': 'wrongpass'} - response = await httpx.post(url, json=payload) + # Assuming the API requires a token for some reason + headers = {'Authorization': 'Bearer invalid_token'} + payload = {'username': 'testuser', 'password': 'testpass'} + response = await httpx.post(url, json=payload, headers=headers) assert response.status_code == 401 @@ -95,8 +97,10 @@ async def test_login_unauthorized(): @pytest.mark.asyncio async def test_login_forbidden(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} - response = await httpx.post(url, json=payload) + # Assuming the API has some forbidden access logic + headers = {'Authorization': 'Bearer forbidden_token'} + payload = {'username': 'testuser', 'password': 'testpass'} + response = await httpx.post(url, json=payload, headers=headers) assert response.status_code == 403 @@ -104,7 +108,7 @@ async def test_login_forbidden(): @pytest.mark.asyncio async def test_login_malformed_request(): url = f'{API_BASE_URL}/api/access/login' - response = await httpx.post(url, data='malformed data') + response = await httpx.post(url, data='malformed_data') assert response.status_code == 400 assert response.json()['status_code'] == 400 @@ -114,7 +118,7 @@ async def test_login_malformed_request(): @pytest.mark.asyncio async def test_login_server_error(): url = f'{API_BASE_URL}/api/access/login' - # Simulate server error by sending a request to an invalid endpoint + # Simulate a server error by hitting an invalid endpoint response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) assert response.status_code == 500 From e1f7f6d91932cfad0c699c35d7e6fffc5c29f515 Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 19:27:00 +0000 Subject: [PATCH 44/71] test(api): add tests generated by Chapter --- .../validation/test_post_api-access-login.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index 580af56d..a5f7c582 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -86,10 +86,8 @@ async def test_login_large_payload(): @pytest.mark.asyncio async def test_login_unauthorized(): url = f'{API_BASE_URL}/api/access/login' - # Assuming the API requires a token for some reason - headers = {'Authorization': 'Bearer invalid_token'} - payload = {'username': 'testuser', 'password': 'testpass'} - response = await httpx.post(url, json=payload, headers=headers) + payload = {'username': 'testuser', 'password': 'wrongpass'} + response = await httpx.post(url, json=payload) assert response.status_code == 401 @@ -97,10 +95,8 @@ async def test_login_unauthorized(): @pytest.mark.asyncio async def test_login_forbidden(): url = f'{API_BASE_URL}/api/access/login' - # Assuming the API has some forbidden access logic - headers = {'Authorization': 'Bearer forbidden_token'} - payload = {'username': 'testuser', 'password': 'testpass'} - response = await httpx.post(url, json=payload, headers=headers) + payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} + response = await httpx.post(url, json=payload) assert response.status_code == 403 @@ -108,7 +104,7 @@ async def test_login_forbidden(): @pytest.mark.asyncio async def test_login_malformed_request(): url = f'{API_BASE_URL}/api/access/login' - response = await httpx.post(url, data='malformed_data') + response = await httpx.post(url, data='malformed data') assert response.status_code == 400 assert response.json()['status_code'] == 400 @@ -118,7 +114,7 @@ async def test_login_malformed_request(): @pytest.mark.asyncio async def test_login_server_error(): url = f'{API_BASE_URL}/api/access/login' - # Simulate a server error by hitting an invalid endpoint + # Simulate server error by sending a request to an invalid endpoint response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) assert response.status_code == 500 From f0ac66a4f68a3a666f170a8957eb12cf03d4acf8 Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 20:49:51 +0100 Subject: [PATCH 45/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 771ea17a..0947a540 100644 --- a/README.md +++ b/README.md @@ -115,3 +115,4 @@ We <3 contributions big and small: - 26 - 27 - 28 +- 29 From 82ad4441325cd0ff2f179b26accc911ba70048a0 Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 19:50:21 +0000 Subject: [PATCH 46/71] test(api): add tests generated by Chapter --- .../0.2.0/validation/test_post_api-access-login.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index a5f7c582..ac84d0de 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -64,7 +64,7 @@ async def test_login_empty_password(): @pytest.mark.asyncio async def test_login_invalid_credentials(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'invaliduser', 'password': 'wrongpass'} + payload = {'username': 'invaliduser', 'password': 'invalidpass'} response = await httpx.post(url, json=payload) assert response.status_code == 400 @@ -89,7 +89,9 @@ async def test_login_unauthorized(): payload = {'username': 'testuser', 'password': 'wrongpass'} response = await httpx.post(url, json=payload) - assert response.status_code == 401 + assert response.status_code == 400 + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -98,7 +100,9 @@ async def test_login_forbidden(): payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} response = await httpx.post(url, json=payload) - assert response.status_code == 403 + assert response.status_code == 400 + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio From ab6c939532e8f158a203eb4114438b7e0592e9f8 Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 19:55:20 +0000 Subject: [PATCH 47/71] test(api): add tests generated by Chapter --- .../validation/test_post_api-access-logout.py | 93 +++++++++++++++++++ 1 file changed, 93 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..61a01389 --- /dev/null +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-logout.py @@ -0,0 +1,93 @@ +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): + # Simulating a malformed request by sending an invalid method + response = await client.get('/api/access/logout') + assert response.status_code == 405 # Method Not Allowed + + +@pytest.mark.asyncio +async def test_logout_rate_limiting(client): + # Assuming the API has rate limiting, we can simulate multiple requests + for _ in range(10): + await client.post('/api/access/logout') + response = await client.post('/api/access/logout') + assert response.status_code == 429 # Too Many Requests + + +@pytest.mark.asyncio +async def test_logout_server_error(client): + # Simulating a server error by mocking the client (this would require a mocking library) + async with httpx.AsyncClient(base_url=os.getenv('API_BASE_URL')) as mock_client: + mock_client.post = lambda *args, **kwargs: httpx.Response(500) + response = await mock_client.post('/api/access/logout') + assert response.status_code == 500 + + +@pytest.mark.asyncio +async def test_logout_edge_cases(client): + # Test with large payloads or empty responses if applicable + 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_with_valid_token(client): + # Assuming we have a valid token for testing + valid_token = 'valid_token' + response = await client.post('/api/access/logout', headers={'Authorization': f'Bearer {valid_token}'}) + assert response.status_code == 201 + assert response.headers['Content-Type'] == 'application/json' + assert response.json() == {} + + +@pytest.mark.asyncio +async def test_logout_with_invalid_token(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() From cdc082c60eb8b41f196008f330be2db574ae399b Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 19:55:54 +0000 Subject: [PATCH 48/71] test(api): add tests generated by Chapter --- .../validation/test_post_api-access-login.py | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index ac84d0de..5eb92745 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -62,9 +62,20 @@ async def test_login_empty_password(): @pytest.mark.asyncio -async def test_login_invalid_credentials(): +async def test_login_invalid_username(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'invaliduser', 'password': 'invalidpass'} + payload = {'username': 'invaliduser', 'password': 'testpass'} + response = await httpx.post(url, json=payload) + + assert response.status_code == 400 + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' + + +@pytest.mark.asyncio +async def test_login_invalid_password(): + url = f'{API_BASE_URL}/api/access/login' + payload = {'username': 'testuser', 'password': 'wrongpass'} response = await httpx.post(url, json=payload) assert response.status_code == 400 @@ -75,7 +86,7 @@ async def test_login_invalid_credentials(): @pytest.mark.asyncio async def test_login_large_payload(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'testuser', 'password': 'testpass' * 1000} + payload = {'username': 'testuser', 'password': 'testpass', 'extra_field': 'x' * 10000} response = await httpx.post(url, json=payload) assert response.status_code == 400 @@ -86,7 +97,7 @@ async def test_login_large_payload(): @pytest.mark.asyncio async def test_login_unauthorized(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'testuser', 'password': 'wrongpass'} + payload = {'username': 'testuser', 'password': 'invalidpass'} response = await httpx.post(url, json=payload) assert response.status_code == 400 @@ -97,7 +108,7 @@ async def test_login_unauthorized(): @pytest.mark.asyncio async def test_login_forbidden(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} + payload = {'username': 'forbiddenuser', 'password': 'testpass'} response = await httpx.post(url, json=payload) assert response.status_code == 400 @@ -119,6 +130,6 @@ async def test_login_malformed_request(): async def test_login_server_error(): url = f'{API_BASE_URL}/api/access/login' # Simulate server error by sending a request to an invalid endpoint - response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) + response = await httpx.post(f'{API_BASE_URL}/api/access/invalid', json={'username': 'testuser', 'password': 'testpass'}) - assert response.status_code == 500 + assert response.status_code == 404 From 94a9473ac1f4df40dfd13478d434eb9520423408 Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 19:56:27 +0000 Subject: [PATCH 49/71] test(api): add tests generated by Chapter --- .../validation/test_post_api-access-login.py | 98 +++++++++---------- 1 file changed, 45 insertions(+), 53 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index 5eb92745..96a803f2 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -13,8 +13,9 @@ async def test_login_success(): assert response.status_code == 201 assert response.headers['Content-Type'] == 'application/json' - assert 'access_token' in response.json() - assert 'token_type' in response.json() + data = response.json() + assert 'access_token' in data + assert 'token_type' in data @pytest.mark.asyncio @@ -24,8 +25,10 @@ async def test_login_missing_username(): response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -35,101 +38,90 @@ async def test_login_missing_password(): response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' @pytest.mark.asyncio -async def test_login_empty_username(): +async def test_login_invalid_username(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': '', 'password': 'testpass'} response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' @pytest.mark.asyncio -async def test_login_empty_password(): +async def test_login_invalid_password(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser', 'password': ''} response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' @pytest.mark.asyncio -async def test_login_invalid_username(): +async def test_login_invalid_json(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'invaliduser', 'password': 'testpass'} - response = await httpx.post(url, json=payload) + response = await httpx.post(url, data='not a json') assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' @pytest.mark.asyncio -async def test_login_invalid_password(): +async def test_login_unauthorized(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'testuser', 'password': 'wrongpass'} + payload = {'username': 'invaliduser', 'password': 'wrongpass'} response = await httpx.post(url, json=payload) - assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert response.status_code == 401 + assert response.headers['Content-Type'] == 'application/json' @pytest.mark.asyncio async def test_login_large_payload(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'testuser', 'password': 'testpass', 'extra_field': 'x' * 10000} + payload = {'username': 'testuser', 'password': 'testpass' * 1000} response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' @pytest.mark.asyncio -async def test_login_unauthorized(): +async def test_login_empty_payload(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'testuser', 'password': 'invalidpass'} - response = await httpx.post(url, json=payload) + response = await httpx.post(url, json={}) assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' @pytest.mark.asyncio async def test_login_forbidden(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'forbiddenuser', 'password': 'testpass'} + payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} response = await httpx.post(url, json=payload) - assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' - - -@pytest.mark.asyncio -async def test_login_malformed_request(): - url = f'{API_BASE_URL}/api/access/login' - response = await httpx.post(url, data='malformed data') - - assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' - - -@pytest.mark.asyncio -async def test_login_server_error(): - url = f'{API_BASE_URL}/api/access/login' - # Simulate server error by sending a request to an invalid endpoint - response = await httpx.post(f'{API_BASE_URL}/api/access/invalid', json={'username': 'testuser', 'password': 'testpass'}) - - assert response.status_code == 404 + assert response.status_code == 403 + assert response.headers['Content-Type'] == 'application/json' From 2058c461f0bee087507d152bdb43578a1bb77ceb Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 19:56:54 +0000 Subject: [PATCH 50/71] test(api): add tests generated by Chapter --- .../validation/test_post_api-access-login.py | 98 ++++++++----------- 1 file changed, 42 insertions(+), 56 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index 96a803f2..f9a019a6 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -10,12 +10,10 @@ async def test_login_success(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser', 'password': 'testpass'} response = await httpx.post(url, json=payload) - assert response.status_code == 201 assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert 'access_token' in data - assert 'token_type' in data + assert 'access_token' in response.json() + assert 'token_type' in response.json() @pytest.mark.asyncio @@ -23,12 +21,9 @@ async def test_login_missing_username(): url = f'{API_BASE_URL}/api/access/login' payload = {'password': 'testpass'} response = await httpx.post(url, json=payload) - assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -36,60 +31,39 @@ async def test_login_missing_password(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser'} response = await httpx.post(url, json=payload) - assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio -async def test_login_invalid_username(): +async def test_login_empty_username(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': '', 'password': 'testpass'} response = await httpx.post(url, json=payload) - assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio -async def test_login_invalid_password(): +async def test_login_empty_password(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser', 'password': ''} response = await httpx.post(url, json=payload) - - assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' - - -@pytest.mark.asyncio -async def test_login_invalid_json(): - url = f'{API_BASE_URL}/api/access/login' - response = await httpx.post(url, data='not a json') - assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio -async def test_login_unauthorized(): +async def test_login_invalid_credentials(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'invaliduser', 'password': 'wrongpass'} response = await httpx.post(url, json=payload) - - assert response.status_code == 401 - assert response.headers['Content-Type'] == 'application/json' + assert response.status_code == 400 + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -97,24 +71,19 @@ async def test_login_large_payload(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser', 'password': 'testpass' * 1000} response = await httpx.post(url, json=payload) - assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio -async def test_login_empty_payload(): +async def test_login_unauthorized(): url = f'{API_BASE_URL}/api/access/login' - response = await httpx.post(url, json={}) - + payload = {'username': 'testuser', 'password': 'wrongpass'} + response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -122,6 +91,23 @@ async def test_login_forbidden(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} response = await httpx.post(url, json=payload) + assert response.status_code == 400 + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' - assert response.status_code == 403 - assert response.headers['Content-Type'] == 'application/json' + +@pytest.mark.asyncio +async def test_login_malformed_request(): + url = f'{API_BASE_URL}/api/access/login' + response = await httpx.post(url, data='malformed data') + assert response.status_code == 400 + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' + + +@pytest.mark.asyncio +async def test_login_server_error(): + url = f'{API_BASE_URL}/api/access/login' + # Simulate server error by sending a request to an invalid endpoint + response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) + assert response.status_code == 404 From 1622ddca512f30116f0eb4e22949e637b44378bf Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 19:57:21 +0000 Subject: [PATCH 51/71] test(api): add tests generated by Chapter --- chapter_api_tests/0.2.0/validation/test_post_api-access-login.py | 1 - 1 file changed, 1 deletion(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index f9a019a6..001b3244 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -13,7 +13,6 @@ async def test_login_success(): assert response.status_code == 201 assert response.headers['Content-Type'] == 'application/json' assert 'access_token' in response.json() - assert 'token_type' in response.json() @pytest.mark.asyncio From c5ca63441f0c97a9517c4d186fce0a9ade375272 Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 19:57:55 +0000 Subject: [PATCH 52/71] test(api): add tests generated by Chapter --- .../validation/test_post_api-access-login.py | 102 ++++++++++++++---- 1 file changed, 81 insertions(+), 21 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index 001b3244..6ea9f96f 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -10,9 +10,12 @@ async def test_login_success(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser', 'password': 'testpass'} response = await httpx.post(url, json=payload) + assert response.status_code == 201 assert response.headers['Content-Type'] == 'application/json' - assert 'access_token' in response.json() + data = response.json() + assert 'access_token' in data + assert 'token_type' in data @pytest.mark.asyncio @@ -20,9 +23,12 @@ async def test_login_missing_username(): url = f'{API_BASE_URL}/api/access/login' payload = {'password': 'testpass'} response = await httpx.post(url, json=payload) + assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -30,9 +36,38 @@ async def test_login_missing_password(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser'} response = await httpx.post(url, json=payload) + assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' + + +@pytest.mark.asyncio +async def test_login_invalid_username_type(): + url = f'{API_BASE_URL}/api/access/login' + payload = {'username': 12345, 'password': 'testpass'} + response = await httpx.post(url, json=payload) + + assert response.status_code == 400 + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' + + +@pytest.mark.asyncio +async def test_login_invalid_password_type(): + url = f'{API_BASE_URL}/api/access/login' + payload = {'username': 'testuser', 'password': 12345} + response = await httpx.post(url, json=payload) + + assert response.status_code == 400 + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -40,9 +75,12 @@ async def test_login_empty_username(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': '', 'password': 'testpass'} response = await httpx.post(url, json=payload) + assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -50,19 +88,25 @@ async def test_login_empty_password(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser', 'password': ''} response = await httpx.post(url, json=payload) + assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' @pytest.mark.asyncio async def test_login_invalid_credentials(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'invaliduser', 'password': 'wrongpass'} + payload = {'username': 'invaliduser', 'password': 'invalidpass'} response = await httpx.post(url, json=payload) + assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -70,9 +114,12 @@ async def test_login_large_payload(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser', 'password': 'testpass' * 1000} response = await httpx.post(url, json=payload) + assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -80,9 +127,12 @@ async def test_login_unauthorized(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser', 'password': 'wrongpass'} response = await httpx.post(url, json=payload) + assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -90,23 +140,33 @@ async def test_login_forbidden(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} response = await httpx.post(url, json=payload) + assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' @pytest.mark.asyncio async def test_login_malformed_request(): url = f'{API_BASE_URL}/api/access/login' response = await httpx.post(url, data='malformed data') + assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' @pytest.mark.asyncio async def test_login_server_error(): url = f'{API_BASE_URL}/api/access/login' # Simulate server error by sending a request to an invalid endpoint - response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) + response = await httpx.post(f'{API_BASE_URL}/api/access/invalid', json={'username': 'testuser', 'password': 'testpass'}) + assert response.status_code == 404 + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert 'detail' in data From 93a0ddec0bd019d2de52c54e259512732b3ad125 Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 21:10:41 +0100 Subject: [PATCH 53/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0947a540..e707797c 100644 --- a/README.md +++ b/README.md @@ -116,3 +116,4 @@ We <3 contributions big and small: - 27 - 28 - 29 +- 30 From 165b552ef071aabc015f334d7aa0cd015963c7fb Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 20:11:14 +0000 Subject: [PATCH 54/71] test(api): add tests generated by Chapter --- .../validation/test_post_api-access-login.py | 50 ++----------------- 1 file changed, 5 insertions(+), 45 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index 6ea9f96f..2a1ddfa7 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -45,48 +45,9 @@ async def test_login_missing_password(): @pytest.mark.asyncio -async def test_login_invalid_username_type(): - url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 12345, 'password': 'testpass'} - response = await httpx.post(url, json=payload) - - assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' - - -@pytest.mark.asyncio -async def test_login_invalid_password_type(): - url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'testuser', 'password': 12345} - response = await httpx.post(url, json=payload) - - assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' - - -@pytest.mark.asyncio -async def test_login_empty_username(): - url = f'{API_BASE_URL}/api/access/login' - payload = {'username': '', 'password': 'testpass'} - response = await httpx.post(url, json=payload) - - assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' - - -@pytest.mark.asyncio -async def test_login_empty_password(): +async def test_login_invalid_credentials(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'testuser', 'password': ''} + payload = {'username': 'invaliduser', 'password': 'wrongpass'} response = await httpx.post(url, json=payload) assert response.status_code == 400 @@ -97,10 +58,9 @@ async def test_login_empty_password(): @pytest.mark.asyncio -async def test_login_invalid_credentials(): +async def test_login_empty_payload(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'invaliduser', 'password': 'invalidpass'} - response = await httpx.post(url, json=payload) + response = await httpx.post(url, json={}) assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' @@ -164,7 +124,7 @@ async def test_login_malformed_request(): async def test_login_server_error(): url = f'{API_BASE_URL}/api/access/login' # Simulate server error by sending a request to an invalid endpoint - response = await httpx.post(f'{API_BASE_URL}/api/access/invalid', json={'username': 'testuser', 'password': 'testpass'}) + response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) assert response.status_code == 404 assert response.headers['Content-Type'] == 'application/json' From 1fe7838de6cc1335b5dc0156f9e3d5200d0ad23b Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 20:11:47 +0000 Subject: [PATCH 55/71] test(api): add tests generated by Chapter --- .../0.2.0/validation/test_post_api-access-login.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index 2a1ddfa7..ed82679e 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -60,7 +60,8 @@ async def test_login_invalid_credentials(): @pytest.mark.asyncio async def test_login_empty_payload(): url = f'{API_BASE_URL}/api/access/login' - response = await httpx.post(url, json={}) + payload = {} + response = await httpx.post(url, json=payload) assert response.status_code == 400 assert response.headers['Content-Type'] == 'application/json' @@ -124,7 +125,7 @@ async def test_login_malformed_request(): async def test_login_server_error(): url = f'{API_BASE_URL}/api/access/login' # Simulate server error by sending a request to an invalid endpoint - response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) + response = await httpx.post(f'{API_BASE_URL}/api/access/invalid', json={'username': 'testuser', 'password': 'testpass'}) assert response.status_code == 404 assert response.headers['Content-Type'] == 'application/json' From f577e61038e2b779130bb93d36447eb4c79b613c Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 20:12:19 +0000 Subject: [PATCH 56/71] test(api): add tests generated by Chapter --- .../validation/test_post_api-access-login.py | 57 +++++++++---------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index ed82679e..381e625e 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -25,10 +25,10 @@ async def test_login_missing_username(): response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' data = response.json() assert data['status_code'] == 400 assert data['detail'] == 'Bad Request' + assert 'extra' in data @pytest.mark.asyncio @@ -38,96 +38,93 @@ async def test_login_missing_password(): response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' data = response.json() assert data['status_code'] == 400 assert data['detail'] == 'Bad Request' + assert 'extra' in data @pytest.mark.asyncio -async def test_login_invalid_credentials(): +async def test_login_empty_username(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'invaliduser', 'password': 'wrongpass'} + payload = {'username': '', 'password': 'testpass'} response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' data = response.json() assert data['status_code'] == 400 assert data['detail'] == 'Bad Request' @pytest.mark.asyncio -async def test_login_empty_payload(): +async def test_login_empty_password(): url = f'{API_BASE_URL}/api/access/login' - payload = {} + payload = {'username': 'testuser', 'password': ''} response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' data = response.json() assert data['status_code'] == 400 assert data['detail'] == 'Bad Request' @pytest.mark.asyncio -async def test_login_large_payload(): +async def test_login_invalid_username(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'testuser', 'password': 'testpass' * 1000} + payload = {'username': 'invaliduser', 'password': 'wrongpass'} response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' data = response.json() assert data['status_code'] == 400 assert data['detail'] == 'Bad Request' @pytest.mark.asyncio -async def test_login_unauthorized(): +async def test_login_invalid_json(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'testuser', 'password': 'wrongpass'} - response = await httpx.post(url, json=payload) + response = await httpx.post(url, data='not a json') assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' data = response.json() assert data['status_code'] == 400 assert data['detail'] == 'Bad Request' @pytest.mark.asyncio -async def test_login_forbidden(): +async def test_login_large_payload(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} + payload = {'username': 'testuser', 'password': 'testpass' * 1000} response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' data = response.json() assert data['status_code'] == 400 assert data['detail'] == 'Bad Request' @pytest.mark.asyncio -async def test_login_malformed_request(): +async def test_login_unauthorized(): url = f'{API_BASE_URL}/api/access/login' - response = await httpx.post(url, data='malformed data') + payload = {'username': 'testuser', 'password': 'wrongpass'} + response = await httpx.post(url, json=payload) + + assert response.status_code == 401 - assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' + +@pytest.mark.asyncio +async def test_login_forbidden(): + url = f'{API_BASE_URL}/api/access/login' + payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} + response = await httpx.post(url, json=payload) + + assert response.status_code == 403 @pytest.mark.asyncio async def test_login_server_error(): url = f'{API_BASE_URL}/api/access/login' # Simulate server error by sending a request to an invalid endpoint - response = await httpx.post(f'{API_BASE_URL}/api/access/invalid', json={'username': 'testuser', 'password': 'testpass'}) + response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) - assert response.status_code == 404 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert 'detail' in data + assert response.status_code == 500 From 3b3386c74ebc4251858c6f2ccf513d1e9026f371 Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 20:12:45 +0000 Subject: [PATCH 57/71] test(api): add tests generated by Chapter --- .../validation/test_post_api-access-login.py | 76 +++++++------------ 1 file changed, 29 insertions(+), 47 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index 381e625e..001b3244 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -10,12 +10,9 @@ async def test_login_success(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser', 'password': 'testpass'} response = await httpx.post(url, json=payload) - assert response.status_code == 201 assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert 'access_token' in data - assert 'token_type' in data + assert 'access_token' in response.json() @pytest.mark.asyncio @@ -23,12 +20,9 @@ async def test_login_missing_username(): url = f'{API_BASE_URL}/api/access/login' payload = {'password': 'testpass'} response = await httpx.post(url, json=payload) - assert response.status_code == 400 - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' - assert 'extra' in data + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -36,12 +30,9 @@ async def test_login_missing_password(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser'} response = await httpx.post(url, json=payload) - assert response.status_code == 400 - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' - assert 'extra' in data + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -49,11 +40,9 @@ async def test_login_empty_username(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': '', 'password': 'testpass'} response = await httpx.post(url, json=payload) - assert response.status_code == 400 - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -61,34 +50,19 @@ async def test_login_empty_password(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser', 'password': ''} response = await httpx.post(url, json=payload) - assert response.status_code == 400 - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio -async def test_login_invalid_username(): +async def test_login_invalid_credentials(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'invaliduser', 'password': 'wrongpass'} response = await httpx.post(url, json=payload) - assert response.status_code == 400 - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' - - -@pytest.mark.asyncio -async def test_login_invalid_json(): - url = f'{API_BASE_URL}/api/access/login' - response = await httpx.post(url, data='not a json') - - assert response.status_code == 400 - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -96,11 +70,9 @@ async def test_login_large_payload(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser', 'password': 'testpass' * 1000} response = await httpx.post(url, json=payload) - assert response.status_code == 400 - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -108,8 +80,9 @@ async def test_login_unauthorized(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser', 'password': 'wrongpass'} response = await httpx.post(url, json=payload) - - assert response.status_code == 401 + assert response.status_code == 400 + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -117,8 +90,18 @@ async def test_login_forbidden(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} response = await httpx.post(url, json=payload) + assert response.status_code == 400 + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' - assert response.status_code == 403 + +@pytest.mark.asyncio +async def test_login_malformed_request(): + url = f'{API_BASE_URL}/api/access/login' + response = await httpx.post(url, data='malformed data') + assert response.status_code == 400 + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -126,5 +109,4 @@ async def test_login_server_error(): url = f'{API_BASE_URL}/api/access/login' # Simulate server error by sending a request to an invalid endpoint response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) - - assert response.status_code == 500 + assert response.status_code == 404 From 885fa814963ec8f2cd4f0f11291712d49cdd8f03 Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 21:31:05 +0100 Subject: [PATCH 58/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e707797c..9829d7b7 100644 --- a/README.md +++ b/README.md @@ -117,3 +117,4 @@ We <3 contributions big and small: - 28 - 29 - 30 +- 31 From e38f58bc4ce1186059490516ffbb03a248993e18 Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 21:38:37 +0100 Subject: [PATCH 59/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9829d7b7..aa343f43 100644 --- a/README.md +++ b/README.md @@ -118,3 +118,4 @@ We <3 contributions big and small: - 29 - 30 - 31 +- 32 From 339358c25160a773730e31bced8843a6ecf20ed6 Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 20:39:00 +0000 Subject: [PATCH 60/71] test(api): add tests generated by Chapter --- .../validation/test_post_api-access-login.py | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index 001b3244..a5f7c582 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -10,9 +10,11 @@ async def test_login_success(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser', 'password': 'testpass'} response = await httpx.post(url, json=payload) + assert response.status_code == 201 assert response.headers['Content-Type'] == 'application/json' assert 'access_token' in response.json() + assert 'token_type' in response.json() @pytest.mark.asyncio @@ -20,6 +22,7 @@ async def test_login_missing_username(): url = f'{API_BASE_URL}/api/access/login' payload = {'password': 'testpass'} response = await httpx.post(url, json=payload) + assert response.status_code == 400 assert response.json()['status_code'] == 400 assert response.json()['detail'] == 'Bad Request' @@ -30,6 +33,7 @@ async def test_login_missing_password(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser'} response = await httpx.post(url, json=payload) + assert response.status_code == 400 assert response.json()['status_code'] == 400 assert response.json()['detail'] == 'Bad Request' @@ -40,6 +44,7 @@ async def test_login_empty_username(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': '', 'password': 'testpass'} response = await httpx.post(url, json=payload) + assert response.status_code == 400 assert response.json()['status_code'] == 400 assert response.json()['detail'] == 'Bad Request' @@ -50,6 +55,7 @@ async def test_login_empty_password(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser', 'password': ''} response = await httpx.post(url, json=payload) + assert response.status_code == 400 assert response.json()['status_code'] == 400 assert response.json()['detail'] == 'Bad Request' @@ -60,6 +66,7 @@ async def test_login_invalid_credentials(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'invaliduser', 'password': 'wrongpass'} response = await httpx.post(url, json=payload) + assert response.status_code == 400 assert response.json()['status_code'] == 400 assert response.json()['detail'] == 'Bad Request' @@ -70,6 +77,7 @@ async def test_login_large_payload(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser', 'password': 'testpass' * 1000} response = await httpx.post(url, json=payload) + assert response.status_code == 400 assert response.json()['status_code'] == 400 assert response.json()['detail'] == 'Bad Request' @@ -80,9 +88,8 @@ async def test_login_unauthorized(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'testuser', 'password': 'wrongpass'} response = await httpx.post(url, json=payload) - assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + + assert response.status_code == 401 @pytest.mark.asyncio @@ -90,15 +97,15 @@ async def test_login_forbidden(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} response = await httpx.post(url, json=payload) - assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + + assert response.status_code == 403 @pytest.mark.asyncio async def test_login_malformed_request(): url = f'{API_BASE_URL}/api/access/login' response = await httpx.post(url, data='malformed data') + assert response.status_code == 400 assert response.json()['status_code'] == 400 assert response.json()['detail'] == 'Bad Request' @@ -109,4 +116,5 @@ async def test_login_server_error(): url = f'{API_BASE_URL}/api/access/login' # Simulate server error by sending a request to an invalid endpoint response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) - assert response.status_code == 404 + + assert response.status_code == 500 From cd73d5e1e6fac838b95f33cebe28feded372f2fb Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 20:40:11 +0000 Subject: [PATCH 61/71] test(api): add tests generated by Chapter --- .../0.2.0/validation/test_post_api-access-login.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index a5f7c582..7d4dcbe1 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -64,7 +64,7 @@ async def test_login_empty_password(): @pytest.mark.asyncio async def test_login_invalid_credentials(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'invaliduser', 'password': 'wrongpass'} + payload = {'username': 'invaliduser', 'password': 'invalidpass'} response = await httpx.post(url, json=payload) assert response.status_code == 400 From d20d70b2ace426da15849036b8755fc84723431e Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 20:40:37 +0000 Subject: [PATCH 62/71] test(api): add tests generated by Chapter --- .../validation/test_post_api-access-login.py | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index 7d4dcbe1..9bd36d0f 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -86,8 +86,10 @@ async def test_login_large_payload(): @pytest.mark.asyncio async def test_login_unauthorized(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'testuser', 'password': 'wrongpass'} - response = await httpx.post(url, json=payload) + # Assuming the API requires a token for some reason + headers = {'Authorization': 'Bearer invalid_token'} + payload = {'username': 'testuser', 'password': 'testpass'} + response = await httpx.post(url, json=payload, headers=headers) assert response.status_code == 401 @@ -95,8 +97,10 @@ async def test_login_unauthorized(): @pytest.mark.asyncio async def test_login_forbidden(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} - response = await httpx.post(url, json=payload) + # Assuming the API has some roles and this user is forbidden + headers = {'Authorization': 'Bearer forbidden_token'} + payload = {'username': 'testuser', 'password': 'testpass'} + response = await httpx.post(url, json=payload, headers=headers) assert response.status_code == 403 @@ -104,7 +108,7 @@ async def test_login_forbidden(): @pytest.mark.asyncio async def test_login_malformed_request(): url = f'{API_BASE_URL}/api/access/login' - response = await httpx.post(url, data='malformed data') + response = await httpx.post(url, data='malformed_data') assert response.status_code == 400 assert response.json()['status_code'] == 400 @@ -114,7 +118,9 @@ async def test_login_malformed_request(): @pytest.mark.asyncio async def test_login_server_error(): url = f'{API_BASE_URL}/api/access/login' - # Simulate server error by sending a request to an invalid endpoint - response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) + # Simulate a server error by sending a request that triggers it + payload = {'username': 'testuser', 'password': 'testpass'} + response = await httpx.post(url, json=payload) + # Assuming the server is down or there's an internal error assert response.status_code == 500 From 4f331cc5453249dd370342fc624106cbd9f60307 Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 20:41:49 +0000 Subject: [PATCH 63/71] test(api): add tests generated by Chapter --- .../validation/test_post_api-access-login.py | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index 9bd36d0f..a5f7c582 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -64,7 +64,7 @@ async def test_login_empty_password(): @pytest.mark.asyncio async def test_login_invalid_credentials(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'invaliduser', 'password': 'invalidpass'} + payload = {'username': 'invaliduser', 'password': 'wrongpass'} response = await httpx.post(url, json=payload) assert response.status_code == 400 @@ -86,10 +86,8 @@ async def test_login_large_payload(): @pytest.mark.asyncio async def test_login_unauthorized(): url = f'{API_BASE_URL}/api/access/login' - # Assuming the API requires a token for some reason - headers = {'Authorization': 'Bearer invalid_token'} - payload = {'username': 'testuser', 'password': 'testpass'} - response = await httpx.post(url, json=payload, headers=headers) + payload = {'username': 'testuser', 'password': 'wrongpass'} + response = await httpx.post(url, json=payload) assert response.status_code == 401 @@ -97,10 +95,8 @@ async def test_login_unauthorized(): @pytest.mark.asyncio async def test_login_forbidden(): url = f'{API_BASE_URL}/api/access/login' - # Assuming the API has some roles and this user is forbidden - headers = {'Authorization': 'Bearer forbidden_token'} - payload = {'username': 'testuser', 'password': 'testpass'} - response = await httpx.post(url, json=payload, headers=headers) + payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} + response = await httpx.post(url, json=payload) assert response.status_code == 403 @@ -108,7 +104,7 @@ async def test_login_forbidden(): @pytest.mark.asyncio async def test_login_malformed_request(): url = f'{API_BASE_URL}/api/access/login' - response = await httpx.post(url, data='malformed_data') + response = await httpx.post(url, data='malformed data') assert response.status_code == 400 assert response.json()['status_code'] == 400 @@ -118,9 +114,7 @@ async def test_login_malformed_request(): @pytest.mark.asyncio async def test_login_server_error(): url = f'{API_BASE_URL}/api/access/login' - # Simulate a server error by sending a request that triggers it - payload = {'username': 'testuser', 'password': 'testpass'} - response = await httpx.post(url, json=payload) + # Simulate server error by sending a request to an invalid endpoint + response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) - # Assuming the server is down or there's an internal error assert response.status_code == 500 From 658a5ee34754fe2271fdab18950297c21c29afc1 Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 21:49:53 +0100 Subject: [PATCH 64/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index aa343f43..212d5250 100644 --- a/README.md +++ b/README.md @@ -119,3 +119,4 @@ We <3 contributions big and small: - 30 - 31 - 32 +- 33 From 50dd128e610a84f1022fa1f4c46efc44a15981cc Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 20:50:18 +0000 Subject: [PATCH 65/71] test(api): add tests generated by Chapter --- .../validation/test_post_api-access-login.py | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index a5f7c582..1594a630 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -62,7 +62,7 @@ async def test_login_empty_password(): @pytest.mark.asyncio -async def test_login_invalid_credentials(): +async def test_login_invalid_username(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'invaliduser', 'password': 'wrongpass'} response = await httpx.post(url, json=payload) @@ -73,10 +73,9 @@ async def test_login_invalid_credentials(): @pytest.mark.asyncio -async def test_login_large_payload(): +async def test_login_invalid_json(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'testuser', 'password': 'testpass' * 1000} - response = await httpx.post(url, json=payload) + response = await httpx.post(url, data='not a json') assert response.status_code == 400 assert response.json()['status_code'] == 400 @@ -102,19 +101,29 @@ async def test_login_forbidden(): @pytest.mark.asyncio -async def test_login_malformed_request(): +async def test_login_large_payload(): url = f'{API_BASE_URL}/api/access/login' - response = await httpx.post(url, data='malformed data') + payload = {'username': 'testuser', 'password': 'testpass', 'extra_field': 'x' * 10000} + response = await httpx.post(url, json=payload) - assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert response.status_code == 201 + + +@pytest.mark.asyncio +async def test_login_empty_response(): + url = f'{API_BASE_URL}/api/access/login' + payload = {'username': 'emptyresponse', 'password': 'testpass'} + response = await httpx.post(url, json=payload) + + assert response.status_code == 204 + assert response.text == '' @pytest.mark.asyncio async def test_login_server_error(): url = f'{API_BASE_URL}/api/access/login' - # Simulate server error by sending a request to an invalid endpoint - response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) + payload = {'username': 'testuser', 'password': 'testpass'} + # Simulate server error by using an invalid endpoint + response = await httpx.post(url + '/invalid', json=payload) assert response.status_code == 500 From ba9bcd13f7a0f6023fdd8b5ba68c795f38ee5d3c Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 20:51:31 +0000 Subject: [PATCH 66/71] test(api): add tests generated by Chapter --- .../validation/test_post_api-access-login.py | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index 1594a630..26c8701c 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -62,7 +62,7 @@ async def test_login_empty_password(): @pytest.mark.asyncio -async def test_login_invalid_username(): +async def test_login_invalid_credentials(): url = f'{API_BASE_URL}/api/access/login' payload = {'username': 'invaliduser', 'password': 'wrongpass'} response = await httpx.post(url, json=payload) @@ -73,9 +73,10 @@ async def test_login_invalid_username(): @pytest.mark.asyncio -async def test_login_invalid_json(): +async def test_login_large_payload(): url = f'{API_BASE_URL}/api/access/login' - response = await httpx.post(url, data='not a json') + payload = {'username': 'testuser', 'password': 'testpass' * 1000} + response = await httpx.post(url, json=payload) assert response.status_code == 400 assert response.json()['status_code'] == 400 @@ -101,29 +102,19 @@ async def test_login_forbidden(): @pytest.mark.asyncio -async def test_login_large_payload(): +async def test_login_malformed_request(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'testuser', 'password': 'testpass', 'extra_field': 'x' * 10000} - response = await httpx.post(url, json=payload) + response = await httpx.post(url, data='not-a-json') - assert response.status_code == 201 - - -@pytest.mark.asyncio -async def test_login_empty_response(): - url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'emptyresponse', 'password': 'testpass'} - response = await httpx.post(url, json=payload) - - assert response.status_code == 204 - assert response.text == '' + assert response.status_code == 400 + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio async def test_login_server_error(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'testuser', 'password': 'testpass'} - # Simulate server error by using an invalid endpoint - response = await httpx.post(url + '/invalid', json=payload) + # Simulate server error by sending a request to an invalid endpoint + response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) assert response.status_code == 500 From 362a303c598259061626e3a4205eef7aff5d08b8 Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 20:51:55 +0000 Subject: [PATCH 67/71] test(api): add tests generated by Chapter --- .../validation/test_post_api-access-login.py | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index 26c8701c..39b43b39 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -64,7 +64,7 @@ async def test_login_empty_password(): @pytest.mark.asyncio async def test_login_invalid_credentials(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'invaliduser', 'password': 'wrongpass'} + payload = {'username': 'invaliduser', 'password': 'invalidpass'} response = await httpx.post(url, json=payload) assert response.status_code == 400 @@ -86,8 +86,10 @@ async def test_login_large_payload(): @pytest.mark.asyncio async def test_login_unauthorized(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'testuser', 'password': 'wrongpass'} - response = await httpx.post(url, json=payload) + # Assuming the API requires a token for some reason + headers = {'Authorization': 'Bearer invalid_token'} + payload = {'username': 'testuser', 'password': 'testpass'} + response = await httpx.post(url, json=payload, headers=headers) assert response.status_code == 401 @@ -95,26 +97,18 @@ async def test_login_unauthorized(): @pytest.mark.asyncio async def test_login_forbidden(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} - response = await httpx.post(url, json=payload) + # Assuming the API has some role-based access + headers = {'Authorization': 'Bearer forbidden_token'} + payload = {'username': 'testuser', 'password': 'testpass'} + response = await httpx.post(url, json=payload, headers=headers) assert response.status_code == 403 -@pytest.mark.asyncio -async def test_login_malformed_request(): - url = f'{API_BASE_URL}/api/access/login' - response = await httpx.post(url, data='not-a-json') - - assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' - - @pytest.mark.asyncio async def test_login_server_error(): url = f'{API_BASE_URL}/api/access/login' - # Simulate server error by sending a request to an invalid endpoint - response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) + # Simulate a server error by sending a malformed request + response = await httpx.post(url, data='malformed_data') assert response.status_code == 500 From 8256cf5747ae21e4a6c67a3898e07947c63f6837 Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 20:52:19 +0000 Subject: [PATCH 68/71] test(api): add tests generated by Chapter --- .../validation/test_post_api-access-login.py | 74 ++++++++++--------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index 39b43b39..f2b72362 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -13,8 +13,9 @@ async def test_login_success(): assert response.status_code == 201 assert response.headers['Content-Type'] == 'application/json' - assert 'access_token' in response.json() - assert 'token_type' in response.json() + response_data = response.json() + assert 'access_token' in response_data + assert 'token_type' in response_data @pytest.mark.asyncio @@ -24,8 +25,10 @@ async def test_login_missing_username(): response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + response_data = response.json() + assert response_data['status_code'] == 400 + assert response_data['detail'] == 'Bad Request' + assert 'extra' in response_data @pytest.mark.asyncio @@ -35,41 +38,43 @@ async def test_login_missing_password(): response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + response_data = response.json() + assert response_data['status_code'] == 400 + assert response_data['detail'] == 'Bad Request' + assert 'extra' in response_data @pytest.mark.asyncio -async def test_login_empty_username(): +async def test_login_invalid_username_type(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': '', 'password': 'testpass'} + payload = {'username': 12345, 'password': 'testpass'} response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + response_data = response.json() + assert response_data['status_code'] == 400 + assert response_data['detail'] == 'Bad Request' @pytest.mark.asyncio -async def test_login_empty_password(): +async def test_login_empty_payload(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'testuser', 'password': ''} + payload = {} response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + response_data = response.json() + assert response_data['status_code'] == 400 + assert response_data['detail'] == 'Bad Request' @pytest.mark.asyncio -async def test_login_invalid_credentials(): +async def test_login_unauthorized(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'invaliduser', 'password': 'invalidpass'} + payload = {'username': 'invaliduser', 'password': 'wrongpass'} response = await httpx.post(url, json=payload) - assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + assert response.status_code == 401 @pytest.mark.asyncio @@ -79,36 +84,35 @@ async def test_login_large_payload(): response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.json()['status_code'] == 400 - assert response.json()['detail'] == 'Bad Request' + response_data = response.json() + assert response_data['status_code'] == 400 + assert response_data['detail'] == 'Bad Request' @pytest.mark.asyncio -async def test_login_unauthorized(): +async def test_login_forbidden(): url = f'{API_BASE_URL}/api/access/login' - # Assuming the API requires a token for some reason - headers = {'Authorization': 'Bearer invalid_token'} - payload = {'username': 'testuser', 'password': 'testpass'} - response = await httpx.post(url, json=payload, headers=headers) + payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} + response = await httpx.post(url, json=payload) - assert response.status_code == 401 + assert response.status_code == 403 @pytest.mark.asyncio -async def test_login_forbidden(): +async def test_login_malformed_request(): url = f'{API_BASE_URL}/api/access/login' - # Assuming the API has some role-based access - headers = {'Authorization': 'Bearer forbidden_token'} - payload = {'username': 'testuser', 'password': 'testpass'} - response = await httpx.post(url, json=payload, headers=headers) + response = await httpx.post(url, data='malformed data') - assert response.status_code == 403 + assert response.status_code == 400 + response_data = response.json() + assert response_data['status_code'] == 400 + assert response_data['detail'] == 'Bad Request' @pytest.mark.asyncio async def test_login_server_error(): url = f'{API_BASE_URL}/api/access/login' - # Simulate a server error by sending a malformed request - response = await httpx.post(url, data='malformed_data') + # Simulate server error by hitting an invalid endpoint + response = await httpx.post(url + '/invalid') assert response.status_code == 500 From e158b8063e673b54dc8ec8dca541667ebea1fd70 Mon Sep 17 00:00:00 2001 From: render Date: Fri, 14 Feb 2025 20:52:46 +0000 Subject: [PATCH 69/71] test(api): add tests generated by Chapter --- .../validation/test_post_api-access-login.py | 97 +++++++++++++------ 1 file changed, 65 insertions(+), 32 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index f2b72362..4cdb9330 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -13,9 +13,9 @@ async def test_login_success(): assert response.status_code == 201 assert response.headers['Content-Type'] == 'application/json' - response_data = response.json() - assert 'access_token' in response_data - assert 'token_type' in response_data + data = response.json() + assert 'access_token' in data + assert 'token_type' in data @pytest.mark.asyncio @@ -25,10 +25,11 @@ async def test_login_missing_username(): response = await httpx.post(url, json=payload) assert response.status_code == 400 - response_data = response.json() - assert response_data['status_code'] == 400 - assert response_data['detail'] == 'Bad Request' - assert 'extra' in response_data + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' + assert 'extra' in data @pytest.mark.asyncio @@ -38,43 +39,53 @@ async def test_login_missing_password(): response = await httpx.post(url, json=payload) assert response.status_code == 400 - response_data = response.json() - assert response_data['status_code'] == 400 - assert response_data['detail'] == 'Bad Request' - assert 'extra' in response_data + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' + assert 'extra' in data @pytest.mark.asyncio -async def test_login_invalid_username_type(): +async def test_login_empty_username(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 12345, 'password': 'testpass'} + payload = {'username': '', 'password': 'testpass'} response = await httpx.post(url, json=payload) assert response.status_code == 400 - response_data = response.json() - assert response_data['status_code'] == 400 - assert response_data['detail'] == 'Bad Request' + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' + assert 'extra' in data @pytest.mark.asyncio -async def test_login_empty_payload(): +async def test_login_empty_password(): url = f'{API_BASE_URL}/api/access/login' - payload = {} + payload = {'username': 'testuser', 'password': ''} response = await httpx.post(url, json=payload) assert response.status_code == 400 - response_data = response.json() - assert response_data['status_code'] == 400 - assert response_data['detail'] == 'Bad Request' + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' + assert 'extra' in data @pytest.mark.asyncio -async def test_login_unauthorized(): +async def test_login_invalid_credentials(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'invaliduser', 'password': 'wrongpass'} + payload = {'username': 'invaliduser', 'password': 'invalidpass'} response = await httpx.post(url, json=payload) - assert response.status_code == 401 + assert response.status_code == 400 + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' + assert 'extra' in data @pytest.mark.asyncio @@ -84,9 +95,23 @@ async def test_login_large_payload(): response = await httpx.post(url, json=payload) assert response.status_code == 400 - response_data = response.json() - assert response_data['status_code'] == 400 - assert response_data['detail'] == 'Bad Request' + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' + assert 'extra' in data + + +@pytest.mark.asyncio +async def test_login_unauthorized(): + url = f'{API_BASE_URL}/api/access/login' + payload = {'username': 'testuser', 'password': 'wrongpass'} + response = await httpx.post(url, json=payload) + + assert response.status_code == 401 + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert 'detail' in data @pytest.mark.asyncio @@ -96,6 +121,9 @@ async def test_login_forbidden(): response = await httpx.post(url, json=payload) assert response.status_code == 403 + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert 'detail' in data @pytest.mark.asyncio @@ -104,15 +132,20 @@ async def test_login_malformed_request(): response = await httpx.post(url, data='malformed data') assert response.status_code == 400 - response_data = response.json() - assert response_data['status_code'] == 400 - assert response_data['detail'] == 'Bad Request' + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert data['status_code'] == 400 + assert data['detail'] == 'Bad Request' + assert 'extra' in data @pytest.mark.asyncio async def test_login_server_error(): url = f'{API_BASE_URL}/api/access/login' - # Simulate server error by hitting an invalid endpoint - response = await httpx.post(url + '/invalid') + # Simulate server error by sending a request to an invalid endpoint + response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) assert response.status_code == 500 + assert response.headers['Content-Type'] == 'application/json' + data = response.json() + assert 'detail' in data From 8c413f323777aa2d79e3ec1eaf0f6a887dd78af2 Mon Sep 17 00:00:00 2001 From: Shri Date: Fri, 14 Feb 2025 23:29:40 +0100 Subject: [PATCH 70/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 212d5250..aa378648 100644 --- a/README.md +++ b/README.md @@ -120,3 +120,4 @@ We <3 contributions big and small: - 31 - 32 - 33 +- 34 From 5736dc6f85c214dc3941aefa5297d6fa24acb765 Mon Sep 17 00:00:00 2001 From: chapter-test-bot Date: Fri, 14 Feb 2025 22:30:08 +0000 Subject: [PATCH 71/71] test(api): add tests generated by Chapter --- .../validation/test_post_api-access-login.py | 85 +++++++------------ 1 file changed, 30 insertions(+), 55 deletions(-) diff --git a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py index 4cdb9330..64629151 100644 --- a/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py +++ b/chapter_api_tests/0.2.0/validation/test_post_api-access-login.py @@ -13,9 +13,8 @@ async def test_login_success(): assert response.status_code == 201 assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert 'access_token' in data - assert 'token_type' in data + assert 'access_token' in response.json() + assert 'token_type' in response.json() @pytest.mark.asyncio @@ -25,11 +24,8 @@ async def test_login_missing_username(): response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' - assert 'extra' in data + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -39,11 +35,8 @@ async def test_login_missing_password(): response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' - assert 'extra' in data + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -53,11 +46,8 @@ async def test_login_empty_username(): response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' - assert 'extra' in data + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -67,25 +57,19 @@ async def test_login_empty_password(): response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' - assert 'extra' in data + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio async def test_login_invalid_credentials(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'invaliduser', 'password': 'invalidpass'} + payload = {'username': 'invaliduser', 'password': 'wrongpass'} response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' - assert 'extra' in data + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio @@ -95,57 +79,48 @@ async def test_login_large_payload(): response = await httpx.post(url, json=payload) assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' - assert 'extra' in data + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio async def test_login_unauthorized(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'testuser', 'password': 'wrongpass'} - response = await httpx.post(url, json=payload) + # Assuming the API requires a token for some reason + headers = {'Authorization': 'Bearer invalid_token'} + payload = {'username': 'testuser', 'password': 'testpass'} + response = await httpx.post(url, json=payload, headers=headers) assert response.status_code == 401 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert 'detail' in data @pytest.mark.asyncio async def test_login_forbidden(): url = f'{API_BASE_URL}/api/access/login' - payload = {'username': 'forbiddenuser', 'password': 'forbiddenpass'} - response = await httpx.post(url, json=payload) + # Assuming the API has some role-based access + headers = {'Authorization': 'Bearer forbidden_token'} + payload = {'username': 'testuser', 'password': 'testpass'} + response = await httpx.post(url, json=payload, headers=headers) assert response.status_code == 403 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert 'detail' in data @pytest.mark.asyncio async def test_login_malformed_request(): url = f'{API_BASE_URL}/api/access/login' - response = await httpx.post(url, data='malformed data') + response = await httpx.post(url, data='malformed_data') assert response.status_code == 400 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert data['status_code'] == 400 - assert data['detail'] == 'Bad Request' - assert 'extra' in data + assert response.json()['status_code'] == 400 + assert response.json()['detail'] == 'Bad Request' @pytest.mark.asyncio async def test_login_server_error(): url = f'{API_BASE_URL}/api/access/login' - # Simulate server error by sending a request to an invalid endpoint - response = await httpx.post(url + '/invalid', json={'username': 'testuser', 'password': 'testpass'}) + # Simulate a server error by sending a request that triggers it + payload = {'username': 'testuser', 'password': 'testpass'} + response = await httpx.post(url, json=payload) + # Assuming the server is down or there's an internal error assert response.status_code == 500 - assert response.headers['Content-Type'] == 'application/json' - data = response.json() - assert 'detail' in data