From 249a0dc9a44d8d515f186093bbd05bec330b7d09 Mon Sep 17 00:00:00 2001 From: Bin Yang Date: Thu, 28 Oct 2021 16:11:46 +0800 Subject: [PATCH] Add test with fake stx client implementation Issue-ID: INF-196 Signed-off-by: Bin Yang Change-Id: Iaf71af39270c5d17ac7cabeed1d9ea91eb85f9d2 --- o2ims/domain/stx_object.py | 13 ++--- tests/integration/test_clientdriver_fake_stx_sa.py | 57 ++++++++++++++++++++++ 2 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 tests/integration/test_clientdriver_fake_stx_sa.py diff --git a/o2ims/domain/stx_object.py b/o2ims/domain/stx_object.py index ee4f718..0a17092 100644 --- a/o2ims/domain/stx_object.py +++ b/o2ims/domain/stx_object.py @@ -18,12 +18,13 @@ import json class StxGenericModel: - def __init__(self, api_response: dict) -> None: - self.id = api_response.uuid - self.content = json.dumps(api_response.to_dict()) - self.updatetime = api_response.updated_at - self.createtime = api_response.created_at - self.name = api_response.name + def __init__(self, api_response: dict = None) -> None: + if api_response: + self.id = api_response.uuid + self.content = json.dumps(api_response.to_dict()) + self.updatetime = api_response.updated_at + self.createtime = api_response.created_at + self.name = api_response.name # def __init__(self, id: str, name: str, # lastupdate: datetime, content: str) -> None: diff --git a/tests/integration/test_clientdriver_fake_stx_sa.py b/tests/integration/test_clientdriver_fake_stx_sa.py new file mode 100644 index 0000000..177546c --- /dev/null +++ b/tests/integration/test_clientdriver_fake_stx_sa.py @@ -0,0 +1,57 @@ +# Copyright (C) 2021 Wind River Systems, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from datetime import date, datetime +import sys +import pytest +from o2ims.adapter import ocloud_repository as repository +from o2ims.domain import ocloud +from o2ims import config +import logging +import uuid +import json +from o2ims.adapter.clients.ocloud_sa_client import StxSaOcloudClient +from o2ims.domain import stx_object as ocloudModel + +# pytestmark = pytest.mark.usefixtures("mappers") + +class FakeStxSaClientImp(object): + def __init__(self): + super().__init__() + + def getInstanceInfo(self) -> ocloudModel.StxGenericModel: + model = ocloudModel.StxGenericModel() + model.id = uuid.uuid4() + model.name = "stx1" + model.updatetime = datetime.now + model.createtime = datetime.now + model.content = json.dumps({}) + return model + + +@pytest.fixture +def fake_driver_imp(): + fakedriver = FakeStxSaClientImp() + yield fakedriver + + +def test_get_instanceinfo(fake_driver_imp): + logger = logging.getLogger(__name__) + stxclientimp = StxSaOcloudClient(fake_driver_imp) + assert stxclientimp is not None + systeminfo = stxclientimp.get(None) + assert systeminfo is not None + assert systeminfo.id is not None + assert systeminfo.name == "stx1" + assert systeminfo.content == json.dumps({}) -- 2.16.6