26 lines
1.2 KiB
Python
26 lines
1.2 KiB
Python
import unittest
|
|
from types import SimpleNamespace
|
|
from unittest.mock import Mock, patch
|
|
from fastapi import HTTPException
|
|
import app as gateway
|
|
|
|
|
|
class ReadinessTests(unittest.TestCase):
|
|
def test_readiness_requires_auth_and_actual_kubernetes_query(self):
|
|
core = Mock()
|
|
with patch.object(gateway, 'TOKEN', 'x' * 32), patch.object(gateway.app.state, 'core', core, create=True):
|
|
with self.assertRaises(HTTPException) as rejected:
|
|
gateway.ready('Bearer wrong')
|
|
self.assertEqual(401, rejected.exception.status_code)
|
|
core.list_namespaced_pod.assert_not_called()
|
|
self.assertTrue(gateway.ready('Bearer ' + 'x' * 32)['ready'])
|
|
core.list_namespaced_pod.assert_called_once()
|
|
|
|
def test_kubernetes_failure_is_not_ready(self):
|
|
core = Mock()
|
|
core.list_namespaced_pod.side_effect = RuntimeError('fixture')
|
|
with patch.object(gateway, 'TOKEN', 'x' * 32), patch.object(gateway.app.state, 'core', core, create=True):
|
|
with self.assertRaises(HTTPException) as failed:
|
|
gateway.ready('Bearer ' + 'x' * 32)
|
|
self.assertEqual(503, failed.exception.status_code)
|