X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=tests%2Fconftest.py;h=447351b49a4e07d3e22de0fa60e27c3acfcf2be7;hb=f19e210d02bfe198549730c496f5642236ed3700;hp=d09ba1ca7d746fb8c80c331ffe437637ca3779d2;hpb=d2f6cc674bf3623caf114a8d7709e70d55ec9340;p=pti%2Fo2.git diff --git a/tests/conftest.py b/tests/conftest.py index d09ba1c..447351b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,21 @@ +# Copyright (C) 2022-2024 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. + # pylint: disable=redefined-outer-name import shutil import subprocess +import sys import time from pathlib import Path @@ -13,19 +28,34 @@ from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker, clear_mappers from tenacity import retry, stop_after_delay from unittest.mock import MagicMock - -from o2common.config import config - -from o2ims.adapter.orm import metadata, start_o2ims_mappers -# from o2ims.adapter.clients.orm_stx import start_o2ims_stx_mappers - -from o2app.adapter import unit_of_work -from o2ims.views import configure_namespace +from mock_alchemy.mocking import UnifiedAlchemyMagicMock + +# Mock cgtsclient, dcmanagerclient, fmclient +modules_to_mock = [ + 'cgtsclient', + 'cgtsclient.client', + 'cgtsclient.exc', + 'dcmanagerclient', + 'dcmanagerclient.api', + 'dcmanagerclient.api.client', + 'fmclient', + 'fmclient.client', + 'fmclient.common', + 'fmclient.common.exceptions' +] + +for module_name in modules_to_mock: + sys.modules[module_name] = MagicMock() from o2app.bootstrap import bootstrap +from o2ims.views import configure_namespace +from o2app.adapter import unit_of_work +from o2ims.adapter.orm import metadata, start_o2ims_mappers +from o2common.config import config -#import os -#os.environ['ALARM_YAML'] = 'configs/alarm.yaml' +# import os +# os.environ['O2APP_CONFIG'] = 'configs/o2app.conf' +# os.environ['ALARM_YAML'] = 'configs/alarm.yaml' @pytest.fixture @@ -35,6 +65,13 @@ def mock_uow(): return session, uow +@pytest.fixture +def mock_alchemy_uow(): + session = UnifiedAlchemyMagicMock() + uow = unit_of_work.SqlAlchemyUnitOfWork(session_factory=session) + return session, uow + + @pytest.fixture def mock_flask_uow(mock_uow): session, uow = mock_uow