44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
import io
|
|
import json
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from user_engine.adapters.tenant_management import HTTPTenantManagementAdapter
|
|
|
|
|
|
class _Response(io.BytesIO):
|
|
def __enter__(self):
|
|
return self
|
|
|
|
def __exit__(self, *_args):
|
|
self.close()
|
|
|
|
|
|
class TenantManagementAdapterTests(unittest.TestCase):
|
|
def test_uses_tenant_engine_contract(self):
|
|
body = _Response(json.dumps({
|
|
"tenant_id": "tenant:friendly:new",
|
|
"identifier": "tenant:friendly:new",
|
|
"grouping": "friendly",
|
|
}).encode())
|
|
adapter = HTTPTenantManagementAdapter(
|
|
base_url="http://tenant-engine", bearer_token="opaque"
|
|
)
|
|
with patch("user_engine.adapters.tenant_management.urlopen", return_value=body) as call:
|
|
result = adapter.create_tenant(
|
|
tenant="tenant:friendly:new", display_name="New",
|
|
idempotency_key="tenant-create-123", correlation_id="corr-1",
|
|
)
|
|
request = call.call_args.args[0]
|
|
self.assertEqual(request.full_url, "http://tenant-engine/tenants")
|
|
self.assertEqual(json.loads(request.data), {
|
|
"tenant_id": "tenant:friendly:new",
|
|
"identifier": "tenant:friendly:new",
|
|
"actor": "tenant-engine",
|
|
})
|
|
self.assertEqual(result.status, "created")
|
|
self.assertEqual(result.external_ref, "tenant:friendly:new")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|