aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_aai_pnf.py78
-rw-r--r--tests/test_dmaap.py24
-rw-r--r--tests/test_version.py2
3 files changed, 97 insertions, 7 deletions
diff --git a/tests/test_aai_pnf.py b/tests/test_aai_pnf.py
index 9c417ba..adb5a56 100644
--- a/tests/test_aai_pnf.py
+++ b/tests/test_aai_pnf.py
@@ -15,11 +15,10 @@ from unittest import mock
import pytest
-from onapsdk.aai.business import PnfInstance, pnf, ServiceInstance
-from onapsdk.exceptions import ResourceNotFound
+from onapsdk.aai.business import PnfInstance, ServiceInstance, pnf
+from onapsdk.exceptions import ResourceNotFound, APIError, ConnectionFailed
from onapsdk.so.deletion import PnfDeletionRequest
-
PNF_INSTANCE = {
"pnf-name": "blablabla",
"pnf-id": "546b282b-2ff7-41a4-9329-55c9a2888477",
@@ -151,3 +150,76 @@ def test_pnf_instance_pnf():
def test_pnf_count(mock_send_message_json):
mock_send_message_json.return_value = COUNT
assert PnfInstance.count() == 12
+
+@mock.patch.object(PnfInstance,"send_message")
+def test_delete_from_aai_success(mock_send_message):
+
+ delete_response = mock.MagicMock()
+ delete_response.status_code = 204 #success case
+
+ mock_send_message.return_value= delete_response
+ pnf_instance = PnfInstance(service_instance=None,
+ pnf_id="test_pnf_id",
+ pnf_name="test_pnf_name",
+ serial_number="test_serial_number",
+ in_maint=False)
+ try:
+ pnf_instance.delete_from_aai()
+ except APIError:
+ assert False # Exception is not expected
+
+@mock.patch.object(PnfInstance,"send_message")
+def test_delete_from_aai_failure(mock_send_message):
+
+ mock_send_message.side_effect = ConnectionFailed('Can not connect to AAI')
+
+ pnf_instance = PnfInstance(service_instance=None,
+ pnf_id="test_pnf_id",
+ pnf_name="test_pnf_name",
+ serial_number="test_serial_number",
+ in_maint=False)
+ with pytest.raises(ConnectionFailed):
+ pnf_instance.delete_from_aai()
+
+@mock.patch.object(PnfInstance,"send_message")
+def test_put_in_aai_success(mock_send_message):
+ put_response = mock.MagicMock()
+ put_response.status_code = 201 #success case
+
+ mock_send_message.return_value = put_response
+ pnf_instance = PnfInstance(service_instance=None,
+ pnf_id="test_pnf_id",
+ pnf_name="test_pnf_name",
+ serial_number="test_serial_number",
+ in_maint=False)
+ try:
+ pnf_instance.put_in_aai()
+ except APIError:
+ assert False # Exception is not expected
+
+@mock.patch.object(PnfInstance,"send_message")
+def test_put_in_aai_success_with_none_attribute(mock_send_message):
+ put_response = mock.MagicMock()
+ put_response.status_code = 201 #success case
+
+ mock_send_message.return_value = put_response
+ pnf_instance = PnfInstance(service_instance=None,
+ pnf_id="test_pnf_id",
+ pnf_name="test_pnf_name",
+ serial_number=None,
+ in_maint=False)
+ try:
+ pnf_instance.put_in_aai()
+ except APIError:
+ assert False # Exception is not expected
+
+@mock.patch.object(PnfInstance,"send_message")
+def test_put_in_aai_failure(mock_send_message):
+ mock_send_message.side_effect = ConnectionFailed('Can not connect to AAI')
+ pnf_instance = PnfInstance(service_instance=None,
+ pnf_id="test_pnf_id",
+ pnf_name="test_pnf_name",
+ serial_number="test_serial_number",
+ in_maint=False)
+ with pytest.raises(ConnectionFailed):
+ pnf_instance.put_in_aai() \ No newline at end of file
diff --git a/tests/test_dmaap.py b/tests/test_dmaap.py
index 28165bc..84ab581 100644
--- a/tests/test_dmaap.py
+++ b/tests/test_dmaap.py
@@ -11,10 +11,12 @@
# 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.
+from unittest import mock
from unittest.mock import patch
-
-from onapsdk.dmaap.dmaap import Dmaap, ACTION, GET_HTTP_METHOD
-
+from requests import RequestException
+from onapsdk.dmaap.dmaap import ACTION, GET_HTTP_METHOD, Dmaap
+from onapsdk.exceptions import APIError, ConnectionFailed
+import pytest
TOPIC = "fault"
DMAAP_EVENTS_URL = "http://dmaap.api.simpledemo.onap.org:3904/events"
@@ -45,3 +47,19 @@ def verify_send_event_to_ves_called(send_message_mock, dmaap_url):
basic_auth=BASIC_AUTH
)
+@patch.object(Dmaap, "send_message")
+def test_post_event_success(send_message_mock):
+ post_response = mock.MagicMock()
+ post_response.status_code = 200 #success case
+ send_message_mock.return_value = post_response
+ try:
+ Dmaap.post_event("test_topic", "test_event")
+ except RequestException:
+ assert False # Exception is not expected
+
+
+@patch.object(Dmaap, "send_message")
+def test_post_event_failure(send_message_mock):
+ send_message_mock.side_effect = ConnectionFailed('Can not connect to dmaap')
+ with pytest.raises(ConnectionFailed):
+ Dmaap.post_event("test_topic", "test_event")
diff --git a/tests/test_version.py b/tests/test_version.py
index 264f488..5df9deb 100644
--- a/tests/test_version.py
+++ b/tests/test_version.py
@@ -17,4 +17,4 @@ import onapsdk.version as version
def test_version():
"""Check version is the right one."""
- assert version.__version__ == '12.6.1'
+ assert version.__version__ == '12.7.0'