Refactor code layout
[pti/o2.git] / tests / integration / test_clientdriver_fake_stx_sa.py
1 # Copyright (C) 2021 Wind River Systems, Inc.\r
2 #\r
3 #  Licensed under the Apache License, Version 2.0 (the "License");\r
4 #  you may not use this file except in compliance with the License.\r
5 #  You may obtain a copy of the License at\r
6 #\r
7 #      http://www.apache.org/licenses/LICENSE-2.0\r
8 #\r
9 #  Unless required by applicable law or agreed to in writing, software\r
10 #  distributed under the License is distributed on an "AS IS" BASIS,\r
11 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12 #  See the License for the specific language governing permissions and\r
13 #  limitations under the License.\r
14 \r
15 from datetime import date, datetime\r
16 import sys\r
17 import pytest\r
18 from o2ims.adapter import ocloud_repository as repository\r
19 from o2ims.domain import ocloud\r
20 from o2common.config import config\r
21 import logging\r
22 import uuid\r
23 import json\r
24 from o2ims.adapter.clients.ocloud_sa_client import StxSaOcloudClient\r
25 from o2ims.domain import stx_object as ocloudModel\r
26 from o2ims.domain.resource_type import ResourceTypeEnum\r
27 \r
28 # pytestmark = pytest.mark.usefixtures("mappers")\r
29 \r
30 \r
31 class FakeStxSaClientImp(object):\r
32     def __init__(self):\r
33         super().__init__()\r
34 \r
35     def getInstanceInfo(self) -> ocloudModel.StxGenericModel:\r
36         model = ocloudModel.StxGenericModel(ResourceTypeEnum.OCLOUD)\r
37         model.id = uuid.uuid4()\r
38         model.name = "stx1"\r
39         model.updatetime = datetime.now\r
40         model.createtime = datetime.now\r
41         model.content = json.dumps({})\r
42         return model\r
43 \r
44 \r
45 @pytest.fixture\r
46 def fake_driver_imp():\r
47     fakedriver = FakeStxSaClientImp()\r
48     yield fakedriver\r
49 \r
50 \r
51 def test_get_instanceinfo(fake_driver_imp):\r
52     logger = logging.getLogger(__name__)\r
53     stxclientimp = StxSaOcloudClient(fake_driver_imp)\r
54     assert stxclientimp is not None\r
55     systeminfo = stxclientimp.get(None)\r
56     assert systeminfo is not None\r
57     assert systeminfo.id is not None\r
58     assert systeminfo.name == "stx1"\r
59     assert systeminfo.content == json.dumps({})\r