Some checks failed
System Monitoring / Health Checks (push) Has been cancelled
System Monitoring / Performance Monitoring (push) Has been cancelled
System Monitoring / Database Monitoring (push) Has been cancelled
System Monitoring / Cache Monitoring (push) Has been cancelled
System Monitoring / Log Monitoring (push) Has been cancelled
System Monitoring / Resource Monitoring (push) Has been cancelled
System Monitoring / Uptime Monitoring (push) Has been cancelled
System Monitoring / Backup Monitoring (push) Has been cancelled
System Monitoring / Security Monitoring (push) Has been cancelled
System Monitoring / Monitoring Dashboard (push) Has been cancelled
System Monitoring / Alerting (push) Has been cancelled
Security Scanning / Dependency Scanning (push) Has been cancelled
Security Scanning / Code Security Scanning (push) Has been cancelled
Security Scanning / Secrets Scanning (push) Has been cancelled
Security Scanning / Container Security Scanning (push) Has been cancelled
Security Scanning / Compliance Checking (push) Has been cancelled
Security Scanning / Security Dashboard (push) Has been cancelled
Security Scanning / Security Remediation (push) Has been cancelled
145 lines
4.6 KiB
Python
145 lines
4.6 KiB
Python
"""
|
|
Contract test for GET /tenants endpoint.
|
|
This test MUST fail before implementation.
|
|
"""
|
|
|
|
import pytest
|
|
from django.test import TestCase
|
|
from django.urls import reverse
|
|
from rest_framework.test import APIClient
|
|
from rest_framework import status
|
|
import json
|
|
|
|
|
|
class TenantsGetContractTest(TestCase):
|
|
def setUp(self):
|
|
self.client = APIClient()
|
|
self.tenants_url = '/api/v1/tenants/'
|
|
|
|
# Admin authentication header
|
|
self.admin_auth = {'HTTP_AUTHORIZATION': 'Bearer admin_token'}
|
|
|
|
def test_get_tenants_success(self):
|
|
"""Test successful retrieval of tenants list."""
|
|
response = self.client.get(
|
|
self.tenants_url,
|
|
**self.admin_auth
|
|
)
|
|
|
|
# This should fail before implementation
|
|
assert response.status_code == status.HTTP_200_OK
|
|
|
|
data = response.json()
|
|
assert 'tenants' in data
|
|
assert isinstance(data['tenants'], list)
|
|
|
|
# Check pagination structure
|
|
assert 'pagination' in data
|
|
pagination = data['pagination']
|
|
assert 'page' in pagination
|
|
assert 'limit' in pagination
|
|
assert 'total' in pagination
|
|
assert 'pages' in pagination
|
|
|
|
def test_get_tenants_unauthorized(self):
|
|
"""Test tenants list retrieval without authentication."""
|
|
response = self.client.get(self.tenants_url)
|
|
|
|
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|
|
|
|
def test_get_tenants_forbidden(self):
|
|
"""Test tenants list retrieval by non-admin user."""
|
|
non_admin_auth = {'HTTP_AUTHORIZATION': 'Bearer user_token'}
|
|
|
|
response = self.client.get(
|
|
self.tenants_url,
|
|
**non_admin_auth
|
|
)
|
|
|
|
assert response.status_code == status.HTTP_403_FORBIDDEN
|
|
|
|
def test_get_tenants_with_pagination(self):
|
|
"""Test tenants list retrieval with pagination parameters."""
|
|
params = {
|
|
'page': 2,
|
|
'limit': 10
|
|
}
|
|
|
|
response = self.client.get(
|
|
self.tenants_url,
|
|
data=params,
|
|
**self.admin_auth
|
|
)
|
|
|
|
assert response.status_code == status.HTTP_200_OK
|
|
|
|
data = response.json()
|
|
assert data['pagination']['page'] == 2
|
|
assert data['pagination']['limit'] == 10
|
|
|
|
def test_get_tenants_with_search(self):
|
|
"""Test tenants list retrieval with search parameter."""
|
|
params = {
|
|
'search': 'test'
|
|
}
|
|
|
|
response = self.client.get(
|
|
self.tenants_url,
|
|
data=params,
|
|
**self.admin_auth
|
|
)
|
|
|
|
assert response.status_code == status.HTTP_200_OK
|
|
|
|
data = response.json()
|
|
# All returned tenants should match search criteria
|
|
for tenant in data['tenants']:
|
|
assert 'test' in tenant['name'].lower()
|
|
|
|
def test_get_tenants_filter_by_status(self):
|
|
"""Test tenants list retrieval filtered by status."""
|
|
params = {
|
|
'status': 'ACTIVE'
|
|
}
|
|
|
|
response = self.client.get(
|
|
self.tenants_url,
|
|
data=params,
|
|
**self.admin_auth
|
|
)
|
|
|
|
assert response.status_code == status.HTTP_200_OK
|
|
|
|
data = response.json()
|
|
# All returned tenants should have the specified status
|
|
for tenant in data['tenants']:
|
|
assert tenant['status'] == 'ACTIVE'
|
|
|
|
def test_get_tenants_data_structure(self):
|
|
"""Test that tenant data structure matches the contract."""
|
|
response = self.client.get(
|
|
self.tenants_url,
|
|
**self.admin_auth
|
|
)
|
|
|
|
if response.status_code == status.HTTP_200_OK and len(response.json()['tenants']) > 0:
|
|
tenant = response.json()['tenants'][0]
|
|
|
|
# Required fields according to contract
|
|
required_fields = [
|
|
'id', 'name', 'slug', 'email', 'phone', 'business_type',
|
|
'subscription_plan', 'pricing_model', 'status', 'created_at'
|
|
]
|
|
|
|
for field in required_fields:
|
|
assert field in tenant
|
|
|
|
# Field types
|
|
assert isinstance(tenant['id'], str)
|
|
assert isinstance(tenant['name'], str)
|
|
assert isinstance(tenant['slug'], str)
|
|
assert isinstance(tenant['email'], str)
|
|
assert tenant['business_type'] in ['RETAIL', 'HEALTHCARE', 'EDUCATION', 'LOGISTICS', 'BEAUTY']
|
|
assert tenant['subscription_plan'] in ['STARTER', 'GROWTH', 'PRO', 'ENTERPRISE']
|
|
assert tenant['pricing_model'] in ['SUBSCRIPTION', 'PERPETUAL']
|
|
assert tenant['status'] in ['PENDING', 'ACTIVE', 'SUSPENDED', 'TERMINATED'] |