diff options
author | 2017-07-27 15:04:07 +0000 | |
---|---|---|
committer | 2017-07-27 15:04:07 +0000 | |
commit | 162c03ef301396072c1934e7e7e0c40a841b4fe2 (patch) | |
tree | 7a2a2781949252436450ff5832962785061a774a /app/test/api/responders_test/resource/test_messages.py | |
parent | b88c78e3cf2bef22aa2f1c4d0bf305e303bc15f0 (diff) | |
parent | 7e83d0876ddb84a45e130eeba28bc40ef53c074b (diff) |
Merge "Calipso initial release for OPNFV"
Diffstat (limited to 'app/test/api/responders_test/resource/test_messages.py')
-rw-r--r-- | app/test/api/responders_test/resource/test_messages.py | 236 |
1 files changed, 236 insertions, 0 deletions
diff --git a/app/test/api/responders_test/resource/test_messages.py b/app/test/api/responders_test/resource/test_messages.py new file mode 100644 index 0000000..6999cee --- /dev/null +++ b/app/test/api/responders_test/resource/test_messages.py @@ -0,0 +1,236 @@ +############################################################################### +# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) # +# and others # +# # +# All rights reserved. This program and the accompanying materials # +# are made available under the terms of the Apache License, Version 2.0 # +# which accompanies this distribution, and is available at # +# http://www.apache.org/licenses/LICENSE-2.0 # +############################################################################### +from test.api.test_base import TestBase +from test.api.responders_test.test_data import base +from test.api.responders_test.test_data import messages +from unittest.mock import patch + + +class TestMessage(TestBase): + + def test_get_messages_list_without_env_name(self): + self.validate_get_request(messages.URL, + params={}, + expected_code=base.BAD_REQUEST_CODE) + + def test_get_messages_list_with_invalid_filter(self): + self.validate_get_request(messages.URL, + params={ + 'invalid': 'invalid' + }, + expected_code=base.BAD_REQUEST_CODE) + + def test_get_messages_list_with_wrong_format_start_time(self): + self.validate_get_request(messages.URL, + params={ + 'env_name': base.ENV_NAME, + 'start_time': messages.WRONG_FORMAT_TIME + }, + expected_code=base.BAD_REQUEST_CODE) + + @patch(base.RESPONDER_BASE_READ) + def test_get_messages_list_with_correct_format_start_time(self, read): + self.validate_get_request(messages.URL, + params={ + 'env_name': base.ENV_NAME, + 'start_time': messages.CORRECT_FORMAT_TIME + }, + mocks={ + read: messages.MESSAGES_WITH_SPECIFIC_TIME + }, + expected_code=base.SUCCESSFUL_CODE, + expected_response= + messages.MESSAGES_WITH_SPECIFIC_TIME_RESPONSE + ) + + def test_get_messages_list_with_wrong_format_end_time(self): + self.validate_get_request(messages.URL, + params={ + 'env_name': base.ENV_NAME, + 'end_time': messages.WRONG_FORMAT_TIME + }, + expected_code=base.BAD_REQUEST_CODE) + + @patch(base.RESPONDER_BASE_READ) + def test_get_messages_list_with_correct_format_end_time(self, read): + self.validate_get_request(messages.URL, + params={ + 'env_name': base.ENV_NAME, + 'end_time': messages.CORRECT_FORMAT_TIME + }, + mocks={ + read: messages.MESSAGES_WITH_SPECIFIC_TIME + }, + expected_code=base.SUCCESSFUL_CODE, + expected_response= + messages.MESSAGES_WITH_SPECIFIC_TIME_RESPONSE + ) + + def test_get_messages_list_with_wrong_level(self): + self.validate_get_request(messages.URL, + params={ + 'env_name': base.ENV_NAME, + 'level': messages.WRONG_SEVERITY + }, + expected_code=base.BAD_REQUEST_CODE) + + @patch(base.RESPONDER_BASE_READ) + def test_get_messages_list_with_level(self, read): + self.validate_get_request(messages.URL, + params={ + 'env_name': base.ENV_NAME, + 'level': messages.CORRECT_SEVERITY + }, + mocks={ + read: messages.MESSAGES_WITH_SPECIFIC_SEVERITY + }, + expected_code=base.SUCCESSFUL_CODE, + expected_response=messages. + MESSAGES_WITH_SPECIFIC_SEVERITY_RESPONSE + ) + + def test_get_messages_list_with_wrong_related_object_type(self): + self.validate_get_request(messages.URL, + params={ + 'env_name': base.ENV_NAME, + 'related_object_type': + messages.WRONG_RELATED_OBJECT_TYPE + }, + expected_code=base.BAD_REQUEST_CODE) + + @patch(base.RESPONDER_BASE_READ) + def test_get_messages_list_with_correct_related_object_type(self, read): + self.validate_get_request(messages.URL, + params={ + 'env_name': base.ENV_NAME, + 'related_object_type': + messages.CORRECT_RELATED_OBJECT_TYPE + }, + mocks={ + read: messages. + MESSAGES_WITH_SPECIFIC_RELATED_OBJECT_TYPE + }, + expected_code=base.SUCCESSFUL_CODE, + expected_response=messages. + MESSAGES_WITH_SPECIFIC_RELATED_OBJECT_TYPE_RESPONSE + ) + + def test_get_messages_list_with_non_int_page(self): + self.validate_get_request(messages.URL, + params={ + 'env_name': base.ENV_NAME, + 'page': base.NON_INT_PAGE + }, + expected_code=base.BAD_REQUEST_CODE) + + @patch(base.RESPONDER_BASE_READ) + def test_get_messages_list_with_int_page(self, read): + self.validate_get_request(messages.URL, + params={ + 'env_name': base.ENV_NAME, + 'page': base.INT_PAGE + }, + mocks={ + read: messages.MESSAGES + }, + expected_code=base.SUCCESSFUL_CODE, + expected_response=messages.MESSAGES_RESPONSE) + + def test_get_messages_list_with_non_int_page_size(self): + self.validate_get_request(messages.URL, + params={ + 'env_name': base.ENV_NAME, + 'page_size': base.NON_INT_PAGESIZE + }, + expected_code=base.BAD_REQUEST_CODE) + + @patch(base.RESPONDER_BASE_READ) + def test_get_messages_list_with_int_pagesize(self, read): + self.validate_get_request(messages.URL, + params={ + 'env_name': base.ENV_NAME, + 'page_size': base.INT_PAGESIZE + }, + mocks={ + read: messages.MESSAGES + }, + expected_code=base.SUCCESSFUL_CODE, + expected_response=messages.MESSAGES_RESPONSE) + + @patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME) + @patch(base.RESPONDER_BASE_READ) + def test_get_messages_list_with_env_name_and_nonexistent_related_object(self, read, check_env_name): + self.validate_get_request(messages.URL, + params={ + 'env_name': base.ENV_NAME, + 'related_object': messages.NONEXISTENT_RELATED_OBJECT + }, + mocks={ + read: [], + check_env_name: True + }, + expected_code=base.NOT_FOUND_CODE) + + @patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME) + @patch(base.RESPONDER_BASE_READ) + def test_get_messages_list_with_unknown_env_name(self, read, check_env_name): + self.validate_get_request(messages.URL, + params={ + 'env_name': base.UNKNOWN_ENV, + 'related_object': messages.RELATED_OBJECT + }, + mocks={ + read: [], + check_env_name: False + }, + expected_code=base.BAD_REQUEST_CODE) + + @patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME) + @patch(base.RESPONDER_BASE_READ) + def test_get_message_with_env_name_and_nonexistent_id(self, read, check_env_name): + self.validate_get_request(messages.URL, + params={ + 'env_name': base.ENV_NAME, + 'id': messages.NONEXISTENT_MESSAGE_ID + }, + mocks={ + read: [], + check_env_name: True + }, + expected_code=base.NOT_FOUND_CODE) + + @patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME) + @patch(base.RESPONDER_BASE_READ) + def test_get_message_with_unknown_env_name_and_id(self, read, check_env_name): + self.validate_get_request(messages.URL, + params={ + 'env_name': base.UNKNOWN_ENV, + 'id': messages.MESSAGE_ID + }, + mocks={ + read: [], + check_env_name: False + }, + expected_code=base.BAD_REQUEST_CODE) + + @patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME) + @patch(base.RESPONDER_BASE_READ) + def test_get_message_with_env_name_and_id(self, read, check_env_name): + self.validate_get_request(messages.URL, + params={ + 'env_name': base.ENV_NAME, + 'id': messages.MESSAGE_ID + }, + mocks={ + read: messages.MESSAGES_WITH_SPECIFIC_ID, + check_env_name: False + }, + expected_code=base.SUCCESSFUL_CODE, + expected_response=messages.MESSAGES_WITH_SPECIFIC_ID[0]) |