X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=near-rt-ric-simulator%2Ftests%2Funittest_setup.py;fp=near-rt-ric-simulator%2Ftests%2Funittest_setup.py;h=0dbbd22cc2dcf420e68d1915f6bd289124051817;hb=868107297d275a6f50790a5e6d3de6c65cbd4a3e;hp=0000000000000000000000000000000000000000;hpb=e9f743a0db7d3a024e868a671f95cbb96cd0632d;p=sim%2Fa1-interface.git diff --git a/near-rt-ric-simulator/tests/unittest_setup.py b/near-rt-ric-simulator/tests/unittest_setup.py new file mode 100644 index 0000000..0dbbd22 --- /dev/null +++ b/near-rt-ric-simulator/tests/unittest_setup.py @@ -0,0 +1,58 @@ +# ============LICENSE_START=============================================== +# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# ======================================================================== +# 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. +# ============LICENSE_END================================================= +# + +# Setting up dir and env for unit test of simualators +import sys +import os +import pytest + +#Server port and base path +PORT_NUMBER="2222" +HOST_IP="localhost" +SERVER_URL="http://"+HOST_IP+":"+PORT_NUMBER+"/" + +#Dir for json test data files +testdata="" + +def setup_env(interface_version): + global testdata + cwd=os.getcwd()+"/" + # Env TESTS_BASE_PATH is set when executed via tox.ini + # If basic test is executed from cmd line, that env var is not needed + if 'TESTS_BASE_PATH' in os.environ: + cwd=os.environ['TESTS_BASE_PATH']+"/" + testdata=cwd+"../test/"+interface_version+"/jsonfiles/" + + #Env var to setup version and host logging + os.environ['APIPATH'] = cwd+"../api/"+interface_version + os.environ['REMOTE_HOSTS_LOGGING'] = "ON" + + # Paths need to run the sim, including needed source file dirs + sys.path.append(os.path.abspath(cwd+'../src/common')) + sys.path.append(os.path.abspath(cwd+'../test/common')) + sys.path.append(os.path.abspath(cwd+'../src/'+interface_version)) + os.chdir(cwd+"../src/"+interface_version) + +def get_testdata_dir(): + return testdata + +#Test client for rest calls +@pytest.fixture +def client(): + from main import app + with app.app.test_client() as c: + yield c \ No newline at end of file