mirror of
https://github.com/wekan/wekan.git
synced 2026-01-05 09:08:49 +01:00
Refactor login tests to improve structure and readability
This commit is contained in:
parent
4df57d54df
commit
a1bf146fed
1 changed files with 55 additions and 11 deletions
|
|
@ -1,16 +1,60 @@
|
|||
import pytest
|
||||
import requests
|
||||
import os
|
||||
|
||||
BASE_URL = os.getenv('WEKAN_URL', 'http://localhost:3000')
|
||||
TEST_USERNAME = 'testuser'
|
||||
TEST_PASSWORD = 'testpass123'
|
||||
TEST_EMAIL = 'test@example.com'
|
||||
base_url = "http://10.0.0.17"
|
||||
|
||||
base_url="http://10.0.0.17/"
|
||||
class TestLogin:
|
||||
def test_health_check(self):
|
||||
"""Test basic health check"""
|
||||
response = requests.get(f"{base_url}")
|
||||
assert response.status_code == 200
|
||||
|
||||
def test_health_check(self):
|
||||
"""Test basic health check"""
|
||||
response = requests.get(f"{base_url}")
|
||||
assert response.status_code == 200
|
||||
def test_login_page_accessible(self):
|
||||
"""Test that login page is accessible"""
|
||||
response = requests.get(f"{base_url}/sign-in")
|
||||
assert response.status_code == 200
|
||||
|
||||
def test_login_with_valid_username(self):
|
||||
"""Test login with valid username credentials"""
|
||||
login_data = {
|
||||
'username': 'omriza5',
|
||||
'password': '123456'
|
||||
}
|
||||
|
||||
response = requests.post(f"{base_url}/users/login", data=login_data)
|
||||
|
||||
assert response.status_code == 200
|
||||
json_response = response.json()
|
||||
assert 'token' in json_response
|
||||
assert isinstance(json_response['token'], str)
|
||||
assert len(json_response['token']) > 0
|
||||
|
||||
def test_login_with_invalid_email(self):
|
||||
"""Test login with invalid email credentials"""
|
||||
login_data = {
|
||||
'email': 'nonexistent@invalid.com',
|
||||
'password': 'invalid_password'
|
||||
}
|
||||
|
||||
response = requests.post(
|
||||
f"{base_url}/users/login",
|
||||
data=login_data,
|
||||
)
|
||||
|
||||
assert response.status_code in [400, 401, 404]
|
||||
json_response = response.json()
|
||||
assert 'error' in json_response
|
||||
assert json_response['error'] == 'not-found'
|
||||
assert 'reason' in json_response
|
||||
assert 'not found' in json_response['reason'].lower()
|
||||
|
||||
def test_api_requires_authentication(self):
|
||||
"""Test that API endpoints require authentication"""
|
||||
# Try to access boards without authentication
|
||||
response = requests.get(f"{base_url}/api/boards")
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
json_response = response.json()
|
||||
assert 'error' in json_response
|
||||
assert json_response['error'] == 'Unauthorized'
|
||||
assert json_response['statusCode'] == 401
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue