You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.8 KiB
Python
92 lines
2.8 KiB
Python
import unittest
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
from admin_app.api.dependencies import get_current_staff_principal
|
|
from admin_app.app_factory import create_app
|
|
from admin_app.core.settings import AdminSettings
|
|
from shared.contracts import StaffRole
|
|
|
|
|
|
class AdminAppBootstrapTests(unittest.TestCase):
|
|
def test_admin_app_root_endpoint_returns_json_for_non_browser_requests(self):
|
|
app = create_app(AdminSettings(admin_environment="staging"))
|
|
client = TestClient(app)
|
|
|
|
response = client.get("/")
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(
|
|
response.json(),
|
|
{
|
|
"service": "orquestrador-admin",
|
|
"status": "ok",
|
|
"message": "Servico administrativo inicializado.",
|
|
"environment": "staging",
|
|
},
|
|
)
|
|
|
|
def test_admin_app_root_endpoint_redirects_browser_to_login(self):
|
|
app = create_app(AdminSettings())
|
|
client = TestClient(app)
|
|
|
|
response = client.get("/", headers={"accept": "text/html"}, follow_redirects=False)
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
self.assertTrue(response.headers["location"].endswith("/login"))
|
|
|
|
def test_admin_app_health_endpoint(self):
|
|
app = create_app(AdminSettings(admin_version="1.2.3"))
|
|
client = TestClient(app)
|
|
|
|
response = client.get("/health")
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(
|
|
response.json(),
|
|
{"service": "orquestrador-admin", "status": "ok", "version": "1.2.3"},
|
|
)
|
|
|
|
def test_admin_app_system_info_endpoint(self):
|
|
settings = AdminSettings(
|
|
admin_app_name="Admin Interno",
|
|
admin_environment="development",
|
|
admin_version="0.9.0",
|
|
admin_api_prefix="/admin",
|
|
admin_debug=True,
|
|
)
|
|
app = create_app(settings)
|
|
app.dependency_overrides[get_current_staff_principal] = lambda: type(
|
|
"Principal",
|
|
(),
|
|
{
|
|
"id": 1,
|
|
"email": "colaborador@empresa.com",
|
|
"display_name": "Colaborador",
|
|
"role": StaffRole.COLABORADOR,
|
|
"is_active": True,
|
|
},
|
|
)()
|
|
client = TestClient(app)
|
|
|
|
response = client.get("/admin/system/info")
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(
|
|
response.json(),
|
|
{
|
|
"service": "orquestrador-admin",
|
|
"app_name": "Admin Interno",
|
|
"environment": "development",
|
|
"version": "0.9.0",
|
|
"api_prefix": "/admin",
|
|
"debug": True,
|
|
},
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|
|
|
|
|