From 7e83d0876ddb84a45e130eeba28bc40ef53c074b Mon Sep 17 00:00:00 2001 From: Yaron Yogev Date: Thu, 27 Jul 2017 09:02:54 +0300 Subject: Calipso initial release for OPNFV Change-Id: I7210c244b0c10fa80bfa8c77cb86c9d6ddf8bc88 Signed-off-by: Yaron Yogev --- .../responders_test/resource/test_aggregates.py | 103 +++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 app/test/api/responders_test/resource/test_aggregates.py (limited to 'app/test/api/responders_test/resource/test_aggregates.py') diff --git a/app/test/api/responders_test/resource/test_aggregates.py b/app/test/api/responders_test/resource/test_aggregates.py new file mode 100644 index 0000000..1b642e0 --- /dev/null +++ b/app/test/api/responders_test/resource/test_aggregates.py @@ -0,0 +1,103 @@ +############################################################################### +# 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 aggregates +from unittest.mock import patch + + +class TestAggregates(TestBase): + + def test_get_aggregate_without_type(self): + self.validate_get_request(aggregates.URL, + params={}, + expected_code=base.BAD_REQUEST_CODE) + + def test_get_aggregate_with_wrong_filter(self): + self.validate_get_request(aggregates.URL, + params={ + "unknown": "unknown" + }, + expected_code=base.BAD_REQUEST_CODE) + + def test_get_environment_aggregates_without_env_name(self): + self.validate_get_request(aggregates.URL, + params={ + "type": aggregates.ENV_TYPE + }, + expected_code=base.BAD_REQUEST_CODE) + + @patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME) + def test_get_environment_aggregates_with_unknown_env_name(self, + check_env_name): + self.validate_get_request(aggregates.URL, + params={ + "type": aggregates.ENV_TYPE, + "env_name": base.UNKNOWN_ENV + }, + mocks={ + check_env_name: False + }, + expected_code=base.BAD_REQUEST_CODE) + + @patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME) + @patch(base.RESPONDER_BASE_AGGREGATE) + def test_get_environment_aggregates_with_env_name(self, aggregates_method, + check_env_name): + self.validate_get_request(aggregates.URL, + params={ + "type": aggregates.ENV_TYPE, + "env_name": base.ENV_NAME + }, + mocks={ + check_env_name: True, + aggregates_method: + aggregates.ENVIRONMENT_AGGREGATES + }, + expected_code=base.SUCCESSFUL_CODE, + expected_response= + aggregates.ENVIRONMENT_AGGREGATES_RESPONSE + ) + + @patch(base.RESPONDER_BASE_AGGREGATE) + def test_get_message_aggregates(self, aggregate): + self.validate_get_request(aggregates.URL, + params={ + "type": aggregates.MESSAGE_TYPE + }, + side_effects={aggregate: [ + aggregates.MESSAGE_ENV_AGGREGATES, + aggregates.MESSAGE_LEVEL_AGGREGATES] + }, + expected_code=base.SUCCESSFUL_CODE, + expected_response= + aggregates.MESSAGE_AGGREGATES_RESPONSE + ) + + @patch(base.RESPONDER_BASE_AGGREGATE) + def test_get_constant_aggregates(self, aggregate): + self.validate_get_request(aggregates.URL, + params={ + "type": aggregates.CONSTANT_TYPE + }, + mocks={ + aggregate: aggregates.CONSTANT_AGGREGATES + }, + expected_code=base.SUCCESSFUL_CODE, + expected_response= + aggregates.CONSTANT_AGGREGATES_RESPONSE + ) + + def test_get_unknown_aggregates(self): + self.validate_get_request(aggregates.URL, + params={ + "type": aggregates.UNKNOWN_TYPE + }, + expected_code=base.BAD_REQUEST_CODE) -- cgit 1.2.3-korg