tests for controller
"""
# ==================================================================================
-# Copyright (c) 2019 Nokia
-# Copyright (c) 2018-2019 AT&T Intellectual Property.
+# Copyright (c) 2019-2020 Nokia
+# Copyright (c) 2018-2020 AT&T Intellectual Property.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==================================================================================
-
import time
import json
-from rmr.rmr_mocks import rmr_mocks
-from a1 import a1rmr
+from ricxappframe.rmr.rmr_mocks import rmr_mocks
+from ricxappframe.xapp_sdl import SDLWrapper
+from ricsdl.exceptions import RejectedByBackend, NotConnected, BackendError
+from a1 import a1rmr, data
RCV_ID = "test_receiver"
ADM_CRTL_TID = 6660666
def _test_put_patch(monkeypatch):
rmr_mocks.patch_rmr(monkeypatch)
# assert that rmr bad states don't cause problems
- monkeypatch.setattr("rmr.rmr.rmr_send_msg", rmr_mocks.send_mock_generator(10))
+ monkeypatch.setattr("ricxappframe.rmr.rmr.rmr_send_msg", rmr_mocks.send_mock_generator(10))
def _no_ac(client):
def setup_module():
"""module level setup"""
+ # swap sdl for the fake backend
+ data.SDL = SDLWrapper(use_fake_sdl=True)
+
def noop():
pass
"""
test a full A1 workflow
"""
+
+ # put type and instance
_put_ac_type(client, adm_type_good)
_put_ac_instance(client, monkeypatch, adm_instance_good)
res = client.delete(ADM_CTRL_TYPE)
assert res.status_code == 204
+ # test 503 handlers
+
+ def monkey_set(ns, key, value):
+ # set a key override function that throws sdl errors on certain keys
+ if key == "a1.policy_type.111":
+ raise RejectedByBackend()
+ if key == "a1.policy_type.112":
+ raise NotConnected()
+ if key == "a1.policy_type.113":
+ raise BackendError()
+
+ monkeypatch.setattr("a1.data.SDL.set", monkey_set)
+
+ res = client.put("/a1-p/policytypes/111", json=adm_type_good)
+ assert res.status_code == 503
+ res = client.put("/a1-p/policytypes/112", json=adm_type_good)
+ assert res.status_code == 503
+ res = client.put("/a1-p/policytypes/113", json=adm_type_good)
+ assert res.status_code == 503
+
def test_illegal_types(client, adm_type_good):
"""