Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
a94080e
Update README.md
shrir Feb 13, 2025
1c15f7d
Update README.md
shrir Feb 13, 2025
ee17dc9
Update README.md
shrir Feb 14, 2025
362863c
Update README.md
shrir Feb 14, 2025
ea34be3
Update README.md
shrir Feb 14, 2025
ca4693c
Update README.md
shrir Feb 14, 2025
8946767
Update README.md
shrir Feb 14, 2025
125ad84
Update README.md
shrir Feb 14, 2025
ade696d
Update README.md
shrir Feb 14, 2025
e072b5f
Update README.md
shrir Feb 14, 2025
14a639e
Update README.md
shrir Feb 14, 2025
e5a4328
Update README.md
shrir Feb 14, 2025
c955c4b
Update README.md
shrir Feb 14, 2025
a19a82c
Update README.md
shrir Feb 14, 2025
136c628
Update README.md
shrir Feb 14, 2025
af631b2
Update README.md
shrir Feb 14, 2025
c4aa49a
Update README.md
shrir Feb 14, 2025
caad8c6
Update README.md
shrir Feb 14, 2025
338b39b
Add api tests generated by Chapter
Feb 14, 2025
fba7fc5
Add api tests generated by Chapter
Feb 14, 2025
3147d96
Add api tests generated by Chapter
Feb 14, 2025
42d12b7
Add api tests generated by Chapter
Feb 14, 2025
e4a7e5f
Add api tests generated by Chapter
Feb 14, 2025
b199378
Add api tests generated by Chapter
Feb 14, 2025
fe4b175
Add api tests generated by Chapter
Feb 14, 2025
d0118db
Add api tests generated by Chapter
Feb 14, 2025
133861a
Add api tests generated by Chapter
Feb 14, 2025
7d7535f
Add api tests generated by Chapter
Feb 14, 2025
e6be66b
Add api tests generated by Chapter
Feb 14, 2025
43f22c4
Add api tests generated by Chapter
Feb 14, 2025
aa61592
Update README.md
shrir Feb 14, 2025
33e80d8
Update README.md
shrir Feb 14, 2025
c5362b0
Update README.md
shrir Feb 14, 2025
002e652
Update README.md
shrir Feb 14, 2025
386fbe2
Update README.md
shrir Feb 14, 2025
642ea52
Update README.md
shrir Feb 14, 2025
1489cea
Update README.md
shrir Feb 14, 2025
d054883
Update README.md
shrir Feb 14, 2025
d7a7fe2
test(api): add tests generated by Chapter
Feb 14, 2025
a82dd5a
test(api): add tests generated by Chapter
Feb 14, 2025
d9f03b5
test(api): add tests generated by Chapter
Feb 14, 2025
577cf82
test(api): add tests generated by Chapter
Feb 14, 2025
ae2a799
test(api): add tests generated by Chapter
Feb 14, 2025
e1f7f6d
test(api): add tests generated by Chapter
Feb 14, 2025
f0ac66a
Update README.md
shrir Feb 14, 2025
82ad444
test(api): add tests generated by Chapter
Feb 14, 2025
ab6c939
test(api): add tests generated by Chapter
Feb 14, 2025
cdc082c
test(api): add tests generated by Chapter
Feb 14, 2025
94a9473
test(api): add tests generated by Chapter
Feb 14, 2025
2058c46
test(api): add tests generated by Chapter
Feb 14, 2025
1622ddc
test(api): add tests generated by Chapter
Feb 14, 2025
c5ca634
test(api): add tests generated by Chapter
Feb 14, 2025
93a0dde
Update README.md
shrir Feb 14, 2025
165b552
test(api): add tests generated by Chapter
Feb 14, 2025
1fe7838
test(api): add tests generated by Chapter
Feb 14, 2025
f577e61
test(api): add tests generated by Chapter
Feb 14, 2025
3b3386c
test(api): add tests generated by Chapter
Feb 14, 2025
885fa81
Update README.md
shrir Feb 14, 2025
e38f58b
Update README.md
shrir Feb 14, 2025
339358c
test(api): add tests generated by Chapter
Feb 14, 2025
cd73d5e
test(api): add tests generated by Chapter
Feb 14, 2025
d20d70b
test(api): add tests generated by Chapter
Feb 14, 2025
4f331cc
test(api): add tests generated by Chapter
Feb 14, 2025
658a5ee
Update README.md
shrir Feb 14, 2025
50dd128
test(api): add tests generated by Chapter
Feb 14, 2025
ba9bcd1
test(api): add tests generated by Chapter
Feb 14, 2025
362a303
test(api): add tests generated by Chapter
Feb 14, 2025
8256cf5
test(api): add tests generated by Chapter
Feb 14, 2025
e158b80
test(api): add tests generated by Chapter
Feb 14, 2025
8c413f3
Update README.md
shrir Feb 14, 2025
5736dc6
test(api): add tests generated by Chapter
Feb 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,38 @@ 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
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
126 changes: 126 additions & 0 deletions chapter_api_tests/0.2.0/validation/test_post_api-access-login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
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'
# 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


@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)

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 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
93 changes: 93 additions & 0 deletions chapter_api_tests/0.2.0/validation/test_post_api-access-logout.py
Original file line number Diff line number Diff line change
@@ -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()