blob: cb0a73a18c3277873f51ca4bc593c09621847424 [file] [log] [blame]
deepanshuk588acf12021-01-06 16:10:44 +05301# ==================================================================================
2# Copyright (c) 2020 HCL Technologies Limited.
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# ==================================================================================
Deepanshu Karnwal77f7c382022-12-10 16:23:18 +053016import json
17from src import main
deepanshuk588acf12021-01-06 16:10:44 +053018from ricxappframe.xapp_frame import Xapp
19from contextlib import suppress
deepanshuk588acf12021-01-06 16:10:44 +053020
21
deepanshuk91624d72021-07-06 13:07:04 +053022def test_database_connection(monkeypatch):
Deepanshu Karnwal77f7c382022-12-10 16:23:18 +053023 # start ad
deepanshuk91624d72021-07-06 13:07:04 +053024 main.connectdb(thread=True)
deepanshuk588acf12021-01-06 16:10:44 +053025
26
deepanshuk91624d72021-07-06 13:07:04 +053027def test_trainModel(monkeypatch):
Deepanshu Karnwal77f7c382022-12-10 16:23:18 +053028 main.train_model()
deepanshuk91624d72021-07-06 13:07:04 +053029
30
31def test_predict_anomaly(monkeypatch, ad_ue):
Deepanshu Karnwal77f7c382022-12-10 16:23:18 +053032 main.load_model()
deepanshuk91624d72021-07-06 13:07:04 +053033 main.predict_anomaly(monkeypatch, ad_ue)
deepanshuk588acf12021-01-06 16:10:44 +053034
35
36def test_msg_to_ts(monkeypatch, ad_to_ts):
37
38 def mock_ad_entry(self):
39 val = json.dumps(ad_to_ts).encode()
40 self.rmr_send(val, 30003)
41 global mock_ad_xapp
42 mock_ad_xapp = Xapp(entrypoint=mock_ad_entry, rmr_port=4564, use_fake_sdl=True)
43 mock_ad_xapp.run() # this will return since mock_ad_entry isn't a loop # this will return since mock_ad_entry isn't a loop
44
45
46def teardown_module():
47 """
48 this is like a "finally"; the name of this function is pytest magic
49 safer to put down here since certain failures above can lead to pytest never returning
50 for example if an exception gets raised before stop is called in any test function above,
51 pytest will hang forever
52 """
53 with suppress(Exception):
54 mock_ad_xapp.stop()