Add test with fake stx client implementation 55/6955/5
authorBin Yang <bin.yang@windriver.com>
Thu, 28 Oct 2021 08:11:46 +0000 (16:11 +0800)
committerBin Yang <bin.yang@windriver.com>
Fri, 29 Oct 2021 01:50:35 +0000 (01:50 +0000)
Issue-ID: INF-196

Signed-off-by: Bin Yang <bin.yang@windriver.com>
Change-Id: Iaf71af39270c5d17ac7cabeed1d9ea91eb85f9d2

o2ims/domain/stx_object.py
tests/integration/test_clientdriver_fake_stx_sa.py [new file with mode: 0644]

index ee4f718..0a17092 100644 (file)
@@ -18,12 +18,13 @@ import json
 \r
 \r
 class StxGenericModel:\r
-    def __init__(self, api_response: dict) -> None:\r
-        self.id = api_response.uuid\r
-        self.content = json.dumps(api_response.to_dict())\r
-        self.updatetime = api_response.updated_at\r
-        self.createtime = api_response.created_at\r
-        self.name = api_response.name\r
+    def __init__(self, api_response: dict = None) -> None:\r
+        if api_response:\r
+            self.id = api_response.uuid\r
+            self.content = json.dumps(api_response.to_dict())\r
+            self.updatetime = api_response.updated_at\r
+            self.createtime = api_response.created_at\r
+            self.name = api_response.name\r
 \r
     # def __init__(self, id: str, name: str,\r
     #              lastupdate: datetime, content: str) -> None:\r
diff --git a/tests/integration/test_clientdriver_fake_stx_sa.py b/tests/integration/test_clientdriver_fake_stx_sa.py
new file mode 100644 (file)
index 0000000..177546c
--- /dev/null
@@ -0,0 +1,57 @@
+# Copyright (C) 2021 Wind River Systems, Inc.\r
+#\r
+#  Licensed under the Apache License, Version 2.0 (the "License");\r
+#  you may not use this file except in compliance with the License.\r
+#  You may obtain a copy of the License at\r
+#\r
+#      http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+#  Unless required by applicable law or agreed to in writing, software\r
+#  distributed under the License is distributed on an "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+#  See the License for the specific language governing permissions and\r
+#  limitations under the License.\r
+\r
+from datetime import date, datetime\r
+import sys\r
+import pytest\r
+from o2ims.adapter import ocloud_repository as repository\r
+from o2ims.domain import ocloud\r
+from o2ims import config\r
+import logging\r
+import uuid\r
+import json\r
+from o2ims.adapter.clients.ocloud_sa_client import StxSaOcloudClient\r
+from o2ims.domain import stx_object as ocloudModel\r
+\r
+# pytestmark = pytest.mark.usefixtures("mappers")\r
+\r
+class FakeStxSaClientImp(object):\r
+    def __init__(self):\r
+        super().__init__()\r
+\r
+    def getInstanceInfo(self) -> ocloudModel.StxGenericModel:\r
+        model = ocloudModel.StxGenericModel()\r
+        model.id = uuid.uuid4()\r
+        model.name = "stx1"\r
+        model.updatetime = datetime.now\r
+        model.createtime = datetime.now\r
+        model.content = json.dumps({})\r
+        return model\r
+\r
+\r
+@pytest.fixture\r
+def fake_driver_imp():\r
+    fakedriver = FakeStxSaClientImp()\r
+    yield fakedriver\r
+\r
+\r
+def test_get_instanceinfo(fake_driver_imp):\r
+    logger = logging.getLogger(__name__)\r
+    stxclientimp = StxSaOcloudClient(fake_driver_imp)\r
+    assert stxclientimp is not None\r
+    systeminfo = stxclientimp.get(None)\r
+    assert systeminfo is not None\r
+    assert systeminfo.id is not None\r
+    assert systeminfo.name == "stx1"\r
+    assert systeminfo.content == json.dumps({})\r