From 80fa98028c8777aba706a2a71c60c540c55b9cc7 Mon Sep 17 00:00:00 2001 From: JunsongDu Date: Wed, 30 Oct 2024 15:09:45 +0100 Subject: [PATCH] chore: implement a test for tenant creation --- filip/clients/ngsi_ld/cb.py | 4 ++-- tests/clients/test_ngsi_ld_cb.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/filip/clients/ngsi_ld/cb.py b/filip/clients/ngsi_ld/cb.py index df02a798..8368a408 100644 --- a/filip/clients/ngsi_ld/cb.py +++ b/filip/clients/ngsi_ld/cb.py @@ -62,7 +62,7 @@ def __init__(self, #base_http_client overwrites empty header with FiwareHeader instead of FiwareLD init_header = FiwareLDHeader() if fiware_header: - init_header=fiware_header + init_header = fiware_header super().__init__(url=url, session=session, @@ -71,7 +71,7 @@ def __init__(self, # set the version specific url-pattern self._url_version = NgsiURLVersion.ld_url # init Content-Type header , account for @context field further down - self.headers.update({'Content-Type':'application/json'}) + self.headers.update({'Content-Type': 'application/json'}) if init_header.ngsild_tenant is not None: self.__make_tenant() diff --git a/tests/clients/test_ngsi_ld_cb.py b/tests/clients/test_ngsi_ld_cb.py index 2f9a6b7f..b688f406 100644 --- a/tests/clients/test_ngsi_ld_cb.py +++ b/tests/clients/test_ngsi_ld_cb.py @@ -85,6 +85,22 @@ def test_management_endpoints(self): self.assertIsNotNone(self.client.get_version()) # TODO: check whether there are other "management" endpoints + @unittest.skip("Only for local testing environment") + def test_not_existing_tenant(self): + """ + Test the expected behavior of the client when the tenant does not exist + This test will not be included in the CI/CD pipeline. For local testing please + comment out the decorator. + """ + # create uuid for the tenant + import uuid + tenant = str(uuid.uuid4()).split('-')[0] + fiware_header = FiwareLDHeader(ngsild_tenant=tenant) + client = ContextBrokerLDClient(fiware_header=fiware_header, + url=settings.LD_CB_URL) + entities = client.get_entity_list() + self.assertEqual(len(entities), 0) + def test_statistics(self): """ Test statistics of context broker client