the beginning of the idiots
This commit is contained in:
		
							
								
								
									
										0
									
								
								qwen/python/merchants_of_hope/tests/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								qwen/python/merchants_of_hope/tests/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										59
									
								
								qwen/python/merchants_of_hope/tests/conftest.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								qwen/python/merchants_of_hope/tests/conftest.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,59 @@
 | 
			
		||||
"""
 | 
			
		||||
Test configuration and fixtures
 | 
			
		||||
"""
 | 
			
		||||
import pytest
 | 
			
		||||
from fastapi.testclient import TestClient
 | 
			
		||||
from sqlalchemy import create_engine
 | 
			
		||||
from sqlalchemy.orm import sessionmaker
 | 
			
		||||
from sqlalchemy.pool import StaticPool
 | 
			
		||||
 | 
			
		||||
from merchants_of_hope.main import app
 | 
			
		||||
from merchants_of_hope.database import Base, get_db
 | 
			
		||||
from merchants_of_hope.models import User, Tenant
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Create test database
 | 
			
		||||
SQLALCHEMY_DATABASE_URL = "sqlite:///./test.db"
 | 
			
		||||
 | 
			
		||||
engine = create_engine(
 | 
			
		||||
    SQLALCHEMY_DATABASE_URL,
 | 
			
		||||
    connect_args={"check_same_thread": False},
 | 
			
		||||
    poolclass=StaticPool,
 | 
			
		||||
)
 | 
			
		||||
TestingSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@pytest.fixture(scope="module")
 | 
			
		||||
def test_db():
 | 
			
		||||
    """Create test database"""
 | 
			
		||||
    Base.metadata.create_all(bind=engine)
 | 
			
		||||
    yield engine
 | 
			
		||||
    Base.metadata.drop_all(bind=engine)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@pytest.fixture(scope="function")
 | 
			
		||||
def db_session(test_db):
 | 
			
		||||
    """Create test database session"""
 | 
			
		||||
    connection = test_db.connect()
 | 
			
		||||
    transaction = connection.begin()
 | 
			
		||||
    session = TestingSessionLocal(bind=connection)
 | 
			
		||||
    
 | 
			
		||||
    yield session
 | 
			
		||||
    
 | 
			
		||||
    session.close()
 | 
			
		||||
    transaction.rollback()
 | 
			
		||||
    connection.close()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@pytest.fixture(scope="module")
 | 
			
		||||
def client(db_session):
 | 
			
		||||
    """Create test client"""
 | 
			
		||||
    def override_get_db():
 | 
			
		||||
        try:
 | 
			
		||||
            yield db_session
 | 
			
		||||
        finally:
 | 
			
		||||
            pass
 | 
			
		||||
    
 | 
			
		||||
    app.dependency_overrides[get_db] = override_get_db
 | 
			
		||||
    with TestClient(app) as test_client:
 | 
			
		||||
        yield test_client
 | 
			
		||||
							
								
								
									
										22
									
								
								qwen/python/merchants_of_hope/tests/test_api.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								qwen/python/merchants_of_hope/tests/test_api.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
"""
 | 
			
		||||
Tests for API endpoints
 | 
			
		||||
"""
 | 
			
		||||
import pytest
 | 
			
		||||
from fastapi.testclient import TestClient
 | 
			
		||||
 | 
			
		||||
def test_root_endpoint(client):
 | 
			
		||||
    """Test root endpoint"""
 | 
			
		||||
    response = client.get("/")
 | 
			
		||||
    assert response.status_code == 200
 | 
			
		||||
    data = response.json()
 | 
			
		||||
    assert "message" in data
 | 
			
		||||
    assert "Welcome to MerchantsOfHope" in data["message"]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_health_endpoint(client):
 | 
			
		||||
    """Test health check endpoint"""
 | 
			
		||||
    response = client.get("/health")
 | 
			
		||||
    assert response.status_code == 200
 | 
			
		||||
    data = response.json()
 | 
			
		||||
    assert data["status"] == "healthy"
 | 
			
		||||
    assert "version" in data
 | 
			
		||||
							
								
								
									
										38
									
								
								qwen/python/merchants_of_hope/tests/test_tenants.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								qwen/python/merchants_of_hope/tests/test_tenants.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,38 @@
 | 
			
		||||
"""
 | 
			
		||||
Tests for tenant functionality
 | 
			
		||||
"""
 | 
			
		||||
import pytest
 | 
			
		||||
from fastapi.testclient import TestClient
 | 
			
		||||
from merchants_of_hope.models import Tenant
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_create_tenant(client, db_session):
 | 
			
		||||
    """Test creating a tenant"""
 | 
			
		||||
    tenant_data = {
 | 
			
		||||
        "name": "Test Tenant",
 | 
			
		||||
        "subdomain": "test"
 | 
			
		||||
    }
 | 
			
		||||
    response = client.post("/api/v1/tenants/", json=tenant_data)
 | 
			
		||||
    assert response.status_code == 200
 | 
			
		||||
    data = response.json()
 | 
			
		||||
    assert data["name"] == tenant_data["name"]
 | 
			
		||||
    assert data["subdomain"] == tenant_data["subdomain"]
 | 
			
		||||
    assert data["is_active"] is True
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_get_tenant(client, db_session):
 | 
			
		||||
    """Test getting a tenant"""
 | 
			
		||||
    # First create a tenant
 | 
			
		||||
    tenant_data = {
 | 
			
		||||
        "name": "Test Tenant 2",
 | 
			
		||||
        "subdomain": "test2"
 | 
			
		||||
    }
 | 
			
		||||
    create_response = client.post("/api/v1/tenants/", json=tenant_data)
 | 
			
		||||
    assert create_response.status_code == 200
 | 
			
		||||
    created_tenant = create_response.json()
 | 
			
		||||
    
 | 
			
		||||
    # Then get the tenant
 | 
			
		||||
    response = client.get(f"/api/v1/tenants/{created_tenant['id']}")
 | 
			
		||||
    assert response.status_code == 200
 | 
			
		||||
    data = response.json()
 | 
			
		||||
    assert data["name"] == tenant_data["name"]
 | 
			
		||||
							
								
								
									
										42
									
								
								qwen/python/merchants_of_hope/tests/test_users.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								qwen/python/merchants_of_hope/tests/test_users.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,42 @@
 | 
			
		||||
"""
 | 
			
		||||
Tests for user functionality
 | 
			
		||||
"""
 | 
			
		||||
import pytest
 | 
			
		||||
from fastapi.testclient import TestClient
 | 
			
		||||
from merchants_of_hope.models import User, UserRole
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_create_user(client, db_session):
 | 
			
		||||
    """Test creating a user"""
 | 
			
		||||
    user_data = {
 | 
			
		||||
        "email": "test@example.com",
 | 
			
		||||
        "username": "testuser",
 | 
			
		||||
        "password": "testpassword",
 | 
			
		||||
        "role": "job_seeker"
 | 
			
		||||
    }
 | 
			
		||||
    response = client.post("/api/v1/users/", json=user_data)
 | 
			
		||||
    assert response.status_code == 200
 | 
			
		||||
    data = response.json()
 | 
			
		||||
    assert data["email"] == user_data["email"]
 | 
			
		||||
    assert data["username"] == user_data["username"]
 | 
			
		||||
    assert data["role"] == user_data["role"]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_get_user(client, db_session):
 | 
			
		||||
    """Test getting a user"""
 | 
			
		||||
    # First create a user
 | 
			
		||||
    user_data = {
 | 
			
		||||
        "email": "test2@example.com",
 | 
			
		||||
        "username": "testuser2",
 | 
			
		||||
        "password": "testpassword",
 | 
			
		||||
        "role": "job_provider"
 | 
			
		||||
    }
 | 
			
		||||
    create_response = client.post("/api/v1/users/", json=user_data)
 | 
			
		||||
    assert create_response.status_code == 200
 | 
			
		||||
    created_user = create_response.json()
 | 
			
		||||
    
 | 
			
		||||
    # Then get the user
 | 
			
		||||
    response = client.get(f"/api/v1/users/{created_user['id']}")
 | 
			
		||||
    assert response.status_code == 200
 | 
			
		||||
    data = response.json()
 | 
			
		||||
    assert data["email"] == user_data["email"]
 | 
			
		||||
		Reference in New Issue
	
	Block a user