38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
"""
|
|
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"] |