A1-Simulator - Align with OSC Near-RT-RIC A1 Mediator
[sim/a1-interface.git] / near-rt-ric-simulator / tests / unittest_setup.py
1 #  ============LICENSE_START===============================================
2 #  Copyright (C) 2020 Nordix Foundation. All rights reserved.
3 #  ========================================================================
4 #  Licensed under the Apache License, Version 2.0 (the "License");
5 #  you may not use this file except in compliance with the License.
6 #  You may obtain a copy of the License at
7 #
8 #       http://www.apache.org/licenses/LICENSE-2.0
9 #
10 #  Unless required by applicable law or agreed to in writing, software
11 #  distributed under the License is distributed on an "AS IS" BASIS,
12 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 #  See the License for the specific language governing permissions and
14 #  limitations under the License.
15 #  ============LICENSE_END=================================================
16 #
17
18 # Setting up dir and env for unit test of simualators
19 import sys
20 import os
21 import pytest
22
23 #Server port and base path
24 PORT_NUMBER="2222"
25 HOST_IP="localhost"
26 SERVER_URL="http://"+HOST_IP+":"+PORT_NUMBER+"/"
27
28 # Dir for json test data files
29 testdata=""
30
31 def setup_env(interface_version):
32     global testdata
33     cwd=os.getcwd()+"/"
34     # Env TESTS_BASE_PATH is set when executed via tox.ini
35     # If basic test is executed from cmd line, that env var is not needed
36     if 'TESTS_BASE_PATH' in os.environ:
37         cwd=os.environ['TESTS_BASE_PATH']+"/"
38     testdata=cwd+"../test/"+interface_version+"/jsonfiles/"
39
40     #Env var to setup version and host logging
41     os.environ['APIPATH'] = cwd+"../api/"+interface_version
42     os.environ['REMOTE_HOSTS_LOGGING'] = "ON"
43     os.environ['DUPLICATE_CHECK'] = "0"
44
45     # Paths need to run the sim, including needed source file dirs
46     sys.path.append(os.path.abspath(cwd+'../src/common'))
47     sys.path.append(os.path.abspath(cwd+'../test/common'))
48     sys.path.append(os.path.abspath(cwd+'../src/'+interface_version))
49     os.chdir(cwd+"../src/"+interface_version)
50
51 def get_testdata_dir():
52     return testdata
53
54 # Test client for rest calls
55 @pytest.fixture
56 def client():
57     from main import app
58     with app.app.test_client() as client:
59         yield client
60
61 # # Run the Flask app in a separate thread for testing
62 # def run_flask_app():
63 #     from main import app
64 #     app.app.run(port=8085, host="127.0.0.1", threaded=True)