Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
120 changes: 120 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,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
11 changes: 0 additions & 11 deletions src/app/domain/companies/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,6 @@ def __post_init__(self) -> None:
if self.url:
self.profile_pic_url = get_logo_dev_link(self.url)

# TODO: Fetch app details but the methods are async
"""
if self.ios_app_url:
ios_app_details = get_ios_app_details(self.ios_app_url)
self.ios_app_details = AppDetails(**ios_app_details)

if self.android_app_url:
android_app_details = get_android_app_details(self.android_app_url)
self.android_app_details = AppDetails(**android_app_details)
"""


class CompanyCreate(CamelizedBaseStruct):
"""A company create schema."""
Expand Down
11 changes: 0 additions & 11 deletions src/app/domain/opportunities/controllers/opportunities.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,6 @@ async def list_opportunities(
if opportunity.company and opportunity.company.url:
opportunity.company.profile_pic_url = get_logo_dev_link(opportunity.company.url)

"""
# Get latest app details
if opportunity.company.ios_app_url:
ios_app_details = await get_ios_app_details(opportunity.company.ios_app_url)
opportunity.company.ios_app_details = AppDetails(**ios_app_details)

if opportunity.company.android_app_url:
android_app_details = await get_android_app_details(opportunity.company.android_app_url)
opportunity.company.android_app_details = AppDetails(**android_app_details)
"""

return paginated_response

@post(
Expand Down
Loading