Connect platform tenant creation to tenant-engine
This commit is contained in:
parent
6589294ae7
commit
c0da589dbe
2 changed files with 56 additions and 8 deletions
44
tests/test_tenant_management_adapter.py
Normal file
44
tests/test_tenant_management_adapter.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue