blob: 9ffd009572430602bf6a0ffd5a3b9e3fc71bbacf [file] [log] [blame]
BjornMagnussonXA86810722020-09-23 08:53:27 +02001# ============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
19import sys
20import os
21import pytest
22
23#Server port and base path
24PORT_NUMBER="2222"
25HOST_IP="localhost"
26SERVER_URL="http://"+HOST_IP+":"+PORT_NUMBER+"/"
27
28#Dir for json test data files
29testdata=""
30
31def 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"
BjornMagnussonXA24ee2702021-09-30 08:43:45 +020043 os.environ['DUPLICATE_CHECK'] = "0"
BjornMagnussonXA86810722020-09-23 08:53:27 +020044
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
51def get_testdata_dir():
52 return testdata
53
54#Test client for rest calls
55@pytest.fixture
56def client():
57 from main import app
58 with app.app.test_client() as c:
59 yield c