forked from xhgit/webup-cloud
Initial import of WebUp Cloud
This commit is contained in:
commit
db82325ed7
216 files changed
+33718
No files matched your search
@@ -0,0 +1,25 @@
|
||||
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)
|
||||
Reference in new issue
Block a user