aboutsummaryrefslogtreecommitdiffstats
path: root/app/test/api/responders_test/resource
diff options
context:
space:
mode:
authorYaron Yogev <yaronyogev@gmail.com>2017-07-27 09:02:54 +0300
committerYaron Yogev <yaronyogev@gmail.com>2017-07-27 14:56:25 +0300
commit7e83d0876ddb84a45e130eeba28bc40ef53c074b (patch)
tree47d76239ae7658d87c66abd142df92709427e7dd /app/test/api/responders_test/resource
parent378ecbd8947589b9cbb39013a0c2e2aa201e03bd (diff)
Calipso initial release for OPNFV
Change-Id: I7210c244b0c10fa80bfa8c77cb86c9d6ddf8bc88 Signed-off-by: Yaron Yogev <yaronyogev@gmail.com>
Diffstat (limited to 'app/test/api/responders_test/resource')
-rw-r--r--app/test/api/responders_test/resource/__init__.py10
-rw-r--r--app/test/api/responders_test/resource/test_aggregates.py103
-rw-r--r--app/test/api/responders_test/resource/test_clique_constraints.py138
-rw-r--r--app/test/api/responders_test/resource/test_clique_types.py267
-rw-r--r--app/test/api/responders_test/resource/test_cliques.py240
-rw-r--r--app/test/api/responders_test/resource/test_constants.py53
-rw-r--r--app/test/api/responders_test/resource/test_environment_configs.py420
-rw-r--r--app/test/api/responders_test/resource/test_inventory.py162
-rw-r--r--app/test/api/responders_test/resource/test_links.py193
-rw-r--r--app/test/api/responders_test/resource/test_messages.py236
-rw-r--r--app/test/api/responders_test/resource/test_monitoring_config_templates.py156
-rw-r--r--app/test/api/responders_test/resource/test_scans.py239
-rw-r--r--app/test/api/responders_test/resource/test_scheduled_scans.py247
13 files changed, 2464 insertions, 0 deletions
diff --git a/app/test/api/responders_test/resource/__init__.py b/app/test/api/responders_test/resource/__init__.py
new file mode 100644
index 0000000..1e85a2a
--- /dev/null
+++ b/app/test/api/responders_test/resource/__init__.py
@@ -0,0 +1,10 @@
+###############################################################################
+# 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 #
+###############################################################################
+
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)
diff --git a/app/test/api/responders_test/resource/test_clique_constraints.py b/app/test/api/responders_test/resource/test_clique_constraints.py
new file mode 100644
index 0000000..f990b5c
--- /dev/null
+++ b/app/test/api/responders_test/resource/test_clique_constraints.py
@@ -0,0 +1,138 @@
+###############################################################################
+# 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 clique_constraints
+from unittest.mock import patch
+
+
+class TestCliqueConstraints(TestBase):
+
+ def test_get_clique_constraints_list_with_invalid_filter(self):
+ self.validate_get_request(clique_constraints.URL,
+ params={
+ "invalid": "invalid"
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_get_clique_constraints_list_with_non_int_page(self):
+ self.validate_get_request(clique_constraints.URL,
+ params={
+ "page": base.NON_INT_PAGE
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_clique_constraints_list_with_int_page(self, read):
+ self.validate_get_request(clique_constraints.URL,
+ params={
+ "page": base.INT_PAGE
+ },
+ mocks={
+ read: clique_constraints.CLIQUE_CONSTRAINTS
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=clique_constraints.
+ CLIQUE_CONSTRAINTS_RESPONSE
+ )
+
+ def test_get_clique_constraints_list_with_non_int_pagesize(self):
+ self.validate_get_request(clique_constraints.URL,
+ params={
+ "page_size": base.NON_INT_PAGESIZE
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_clique_constraints_list_with_int_pagesize(self, read):
+ self.validate_get_request(clique_constraints.URL,
+ params={
+ "page_size": base.INT_PAGESIZE
+ },
+ mocks={
+ read: clique_constraints.CLIQUE_CONSTRAINTS
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=clique_constraints.
+ CLIQUE_CONSTRAINTS_RESPONSE
+ )
+
+ def test_get_clique_constraints_with_wrong_id(self):
+ self.validate_get_request(clique_constraints.URL,
+ params={
+ 'id': clique_constraints.WRONG_ID
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_clique_constraints_with_nonexistent_id(self, read):
+ self.validate_get_request(clique_constraints.URL,
+ params={
+ "id": clique_constraints.NONEXISTENT_ID
+ },
+ mocks={
+ read: []
+ },
+ expected_code=base.NOT_FOUND_CODE
+ )
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_clique_constraints_with_id(self, read):
+ self.validate_get_request(clique_constraints.URL,
+ params={
+ "id": clique_constraints.CORRECT_ID
+ },
+ mocks={
+ read: clique_constraints.
+ CLIQUE_CONSTRAINTS_WITH_SPECIFIC_ID
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=clique_constraints.
+ CLIQUE_CONSTRAINTS_WITH_SPECIFIC_ID[0]
+ )
+
+ def test_get_clique_constraints_list_with_wrong_focal_point_type(self):
+ self.validate_get_request(clique_constraints.URL,
+ params={
+ "focal_point_type":
+ clique_constraints.WRONG_FOCAL_POINT_TYPE
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_clique_constraints_list_with_focal_point_type(self, read):
+ self.validate_get_request(clique_constraints.URL,
+ params={
+ "focal_point_type":
+ clique_constraints.CORRECT_FOCAL_POINT_TYPE
+ },
+ mocks={
+ read: clique_constraints.
+ CLIQUE_CONSTRAINTS_WITH_SPECIFIC_FOCAL_POINT_TYPE
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=clique_constraints.
+ CLIQUE_CONSTRAINTS_WITH_SPECIFIC_FOCAL_POINT_TYPE_RESPONSE
+ )
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_clique_constraints_list_with_constraints(self, read):
+ self.validate_get_request(clique_constraints.URL,
+ params={
+ "constraint": clique_constraints.CONSTRAINT
+ },
+ mocks={
+ read: clique_constraints.
+ CLIQUE_CONSTRAINTS_WITH_SPECIFIC_CONSTRAINT
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=clique_constraints.
+ CLIQUE_CONSTRAINTS_WITH_SPECIFIC_CONSTRAINT_RESPONSE
+ )
diff --git a/app/test/api/responders_test/resource/test_clique_types.py b/app/test/api/responders_test/resource/test_clique_types.py
new file mode 100644
index 0000000..f5e331e
--- /dev/null
+++ b/app/test/api/responders_test/resource/test_clique_types.py
@@ -0,0 +1,267 @@
+###############################################################################
+# 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 #
+###############################################################################
+import json
+
+from test.api.responders_test.test_data import base
+from test.api.test_base import TestBase
+from test.api.responders_test.test_data import clique_types
+from unittest.mock import patch
+
+
+class TestCliqueTypes(TestBase):
+
+ def test_get_clique_types_list_without_env_name(self):
+ self.validate_get_request(clique_types.URL,
+ params={},
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_get_clique_types_with_invalid_filter(self):
+ self.validate_get_request(clique_types.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "invalid": "invalid"
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_get_clique_type_with_wrong_id(self):
+ self.validate_get_request(clique_types.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "id": clique_types.WRONG_ID
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_clique_type_with_id(self, read):
+ self.validate_get_request(clique_types.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "id": clique_types.CORRECT_ID
+ },
+ mocks={
+ read: clique_types.CLIQUE_TYPES_WITH_SPECIFIC_ID
+ },
+ expected_response=clique_types.
+ CLIQUE_TYPES_WITH_SPECIFIC_ID[0],
+ expected_code=base.SUCCESSFUL_CODE
+ )
+
+ def test_get_clique_types_list_with_wrong_focal_point_type(self):
+ self.validate_get_request(clique_types.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "focal_point_type": clique_types.WRONG_FOCAL_POINT_TYPE
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_clique_types_list_with_correct_focal_point_type(self, read):
+ self.validate_get_request(clique_types.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "focal_point_type":
+ clique_types.CORRECT_FOCAL_POINT_POINT_TYPE
+ },
+ mocks={
+ read: clique_types.
+ CLIQUE_TYPES_WITH_SPECIFIC_FOCAL_POINT_TYPE
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=clique_types.
+ CLIQUE_TYPES_WITH_SPECIFIC_FOCAL_POINT_TYPE_RESPONSE
+ )
+
+ def test_get_clique_types_list_with_wrong_link_type(self):
+ self.validate_get_request(clique_types.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "link_type": clique_types.WRONG_LINK_TYPE
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_clique_types_list_with_correct_link_type(self, read):
+ self.validate_get_request(clique_types.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "link_type": base.CORRECT_LINK_TYPE
+ },
+ mocks={
+ read: clique_types.
+ CLIQUE_TYPES_WITH_SPECIFIC_LINK_TYPE
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=clique_types.
+ CLIQUE_TYPES_WITH_SPECIFIC_LINK_TYPE_RESPONSE
+ )
+
+ def test_get_clique_types_list_with_non_int_page(self):
+ self.validate_get_request(clique_types.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_clique_types_list_with_int_page(self, read):
+ self.validate_get_request(clique_types.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "page": base.INT_PAGE
+ },
+ mocks={
+ read: clique_types.CLIQUE_TYPES
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=clique_types.CLIQUE_TYPES_RESPONSE)
+
+ def test_get_clique_types_list_with_non_int_page_size(self):
+ self.validate_get_request(clique_types.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_clique_types_list_with_int_page_size(self, read):
+ self.validate_get_request(clique_types.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "page_size": base.INT_PAGESIZE
+ },
+ mocks={
+ read: clique_types.CLIQUE_TYPES
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=clique_types.CLIQUE_TYPES_RESPONSE)
+
+ @patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME)
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_clique_types_list_with_unknown_env_name(self, read, check_env_name):
+ self.validate_get_request(clique_types.URL,
+ params={
+ "env_name": base.UNKNOWN_ENV
+ },
+ 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_clique_types_list_with_env_name_and_nonexistent_link_type(self, read, check_env_name):
+ self.validate_get_request(clique_types.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "link_type": clique_types.NONEXISTENT_LINK_TYPE
+ },
+ 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_clique_type_with_unknown_env_name_and_id(self, read, check_env_name):
+ self.validate_get_request(clique_types.URL,
+ params={
+ "env_name": base.UNKNOWN_ENV,
+ "id": clique_types.NONEXISTENT_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_clique_type_with_env_name_and_nonexistent_id(self, read, check_env_name):
+ self.validate_get_request(clique_types.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "id": clique_types.NONEXISTENT_ID
+ },
+ mocks={
+ read: [],
+ check_env_name: True
+ },
+ expected_code=base.NOT_FOUND_CODE)
+
+ def test_post_clique_type_with_non_dict_clique_type(self):
+ self.validate_post_request(clique_types.URL,
+ body=json.dumps(clique_types.NON_DICT_CLIQUE_TYPE),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_clique_type_without_env_name(self):
+ self.validate_post_request(clique_types.URL,
+ body=json.dumps(clique_types.CLIQUE_TYPE_WITHOUT_ENVIRONMENT),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME)
+ def test_post_clique_type_with_unknown_env_name(self, check_environment_name):
+ self.validate_post_request(clique_types.URL,
+ mocks={
+ check_environment_name: False
+ },
+ body=json.dumps(clique_types.
+ CLIQUE_TYPE_WITH_UNKNOWN_ENVIRONMENT),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_clique_type_without_focal_point_type(self):
+ self.validate_post_request(clique_types.URL,
+ body=json.dumps(clique_types.
+ CLIQUE_TYPE_WITHOUT_FOCAL_POINT_TYPE),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_clique_type_with_wrong_focal_point_type(self):
+ self.validate_post_request(clique_types.URL,
+ body=json.dumps(clique_types.
+ CLIQUE_TYPE_WITH_WRONG_FOCAL_POINT_TYPE),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_clique_type_without_link_types(self):
+ self.validate_post_request(clique_types.URL,
+ body=json.dumps(
+ clique_types.CLIQUE_TYPE_WITHOUT_LINK_TYPES
+ ),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_clique_type_with_non_list_link_types(self):
+ self.validate_post_request(clique_types.URL,
+ body=json.dumps(clique_types.
+ CLIQUE_TYPE_WITH_NON_LIST_LINK_TYPES),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_clique_type_with_wrong_link_type(self):
+ self.validate_post_request(clique_types.URL,
+ body=json.dumps(clique_types.
+ CLIQUE_TYPE_WITH_WRONG_LINK_TYPE),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_clique_type_without_name(self):
+ self.validate_post_request(clique_types.URL,
+ body=json.dumps(clique_types.CLIQUE_TYPE_WITHOUT_NAME),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME)
+ @patch(base.RESPONDER_BASE_WRITE)
+ def test_post_clique_type(self, write, check_environment_name):
+ self.validate_post_request(clique_types.URL,
+ body=json.dumps(clique_types.CLIQUE_TYPE),
+ mocks={
+ write: None,
+ check_environment_name: True
+ },
+ expected_code=base.CREATED_CODE)
diff --git a/app/test/api/responders_test/resource/test_cliques.py b/app/test/api/responders_test/resource/test_cliques.py
new file mode 100644
index 0000000..de3576b
--- /dev/null
+++ b/app/test/api/responders_test/resource/test_cliques.py
@@ -0,0 +1,240 @@
+###############################################################################
+# 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 cliques
+from unittest.mock import patch
+
+
+class TestCliques(TestBase):
+
+ def test_get_cliques_list_without_env_name(self):
+ self.validate_get_request(cliques.URL,
+ params={},
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_get_cliques_list_with_invalid_filter(self):
+ self.validate_get_request(cliques.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "invalid": "invalid"
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_get_cliques_list_with_non_int_page(self):
+ self.validate_get_request(cliques.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_cliques_list_with_int_page(self, read):
+ self.validate_get_request(cliques.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "page": base.INT_PAGE
+ },
+ mocks={
+ read: cliques.CLIQUES
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=cliques.CLIQUES_RESPONSE)
+
+ def test_get_cliques_list_with_non_int_pagesize(self):
+ self.validate_get_request(cliques.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_cliques_list_with_int_pagesize(self, read):
+ self.validate_get_request(cliques.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "page_size": base.INT_PAGESIZE
+ },
+ mocks={
+ read: cliques.CLIQUES
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=cliques.CLIQUES_RESPONSE)
+
+ def test_get_clique_with_wrong_clique_id(self):
+ self.validate_get_request(cliques.URL,
+ params={
+ 'env_name': base.ENV_NAME,
+ 'id': cliques.WRONG_CLIQUE_ID
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_clique_with_clique_id(self, read):
+ self.validate_get_request(cliques.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "id": cliques.CORRECT_CLIQUE_ID
+ },
+ mocks={
+ read: cliques.CLIQUES_WITH_SPECIFIC_ID
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=cliques.CLIQUES_WITH_SPECIFIC_ID[0]
+ )
+
+ def test_get_cliques_list_with_wrong_focal_point(self):
+ self.validate_get_request(cliques.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "focal_point": cliques.WRONG_FOCAL_POINT
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_cliques_list_with_focal_point(self, read):
+ self.validate_get_request(cliques.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "focal_point": cliques.CORRECT_FOCAL_POINT
+ },
+ mocks={
+ read: cliques.CLIQUES_WITH_SPECIFIC_FOCAL_POINT
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=cliques.
+ CLIQUES_WITH_SPECIFIC_FOCAL_POINT_RESPONSE
+ )
+
+ def test_get_cliques_list_with_wrong_focal_point_type(self):
+ self.validate_get_request(cliques.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "focal_point_type": cliques.WRONG_FOCAL_POINT_TYPE
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_cliques_list_with_focal_point_type(self, read):
+ self.validate_get_request(cliques.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "focal_point_type": cliques.CORRECT_FOCAL_POINT_TYPE
+ },
+ mocks={
+ read: cliques.CLIQUES_WITH_SPECIFIC_FOCAL_POINT_TYPE
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=cliques.
+ CLIQUES_WITH_SPECIFIC_FOCAL_POINT_TYPE_RESPONSE
+ )
+
+ def test_get_cliques_list_with_wrong_link_type(self):
+ self.validate_get_request(cliques.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "link_type": base.WRONG_LINK_TYPE
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_cliques_list_with_link_type(self, read):
+ self.validate_get_request(cliques.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "link_type": cliques.CORRECT_LINK_TYPE
+ },
+ mocks={
+ read: cliques.CLIQUES_WITH_SPECIFIC_LINK_TYPE
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=cliques.
+ CLIQUES_WITH_SPECIFIC_LINK_TYPE_RESPONSE
+ )
+
+ def test_get_cliques_list_with_wrong_link_id(self):
+ self.validate_get_request(cliques.URL,
+ {
+ "env_name": base.ENV_NAME,
+ "link_id": cliques.WRONG_LINK_ID
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_clique_ids_with_correct_link_id(self, read):
+ self.validate_get_request(cliques.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "link_id": cliques.CORRECT_LINK_ID
+ },
+ mocks={
+ read: cliques.CLIQUES_WITH_SPECIFIC_LINK_ID
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=cliques.
+ CLIQUES_WITH_SPECIFIC_LINK_ID_RESPONSE
+ )
+
+ @patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME)
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_cliques_list_with_env_name_and_nonexistent_link_id(self, read, check_env_name):
+ self.validate_get_request(cliques.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "link_id": cliques.NONEXISTENT_LINK_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_cliques_list_with_unknown_env_name(self, read, check_env_name):
+ self.validate_get_request(cliques.URL,
+ params={
+ "env_name": base.UNKNOWN_ENV
+ },
+ 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_clique_with_env_name_and_nonexistent_clique_id(self, read, check_env_name):
+ self.validate_get_request(cliques.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "id": cliques.NONEXISTENT_CLIQUE_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_clique_with_unknown_env_name_and_clique_id(self, read, check_env_name):
+ self.validate_get_request(cliques.URL,
+ params={
+ "env_name": base.UNKNOWN_ENV,
+ "id": cliques.NONEXISTENT_CLIQUE_ID
+ },
+ mocks={
+ read: [],
+ check_env_name: False
+ },
+ expected_code=base.BAD_REQUEST_CODE)
diff --git a/app/test/api/responders_test/resource/test_constants.py b/app/test/api/responders_test/resource/test_constants.py
new file mode 100644
index 0000000..0d92ebe
--- /dev/null
+++ b/app/test/api/responders_test/resource/test_constants.py
@@ -0,0 +1,53 @@
+###############################################################################
+# 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 constants
+from unittest.mock import patch
+
+
+class TestConstants(TestBase):
+
+ def test_get_constant_without_name(self):
+ self.validate_get_request(constants.URL,
+ params={},
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_get_constant_with_unknown_filter(self):
+ self.validate_get_request(constants.URL,
+ params={
+ "unknown": "unknown"
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_constant_with_unknown_name(self, read):
+ self.validate_get_request(constants.URL,
+ params={
+ "name": constants.UNKNOWN_NAME
+ },
+ mocks={
+ read: []
+ },
+ expected_code=base.NOT_FOUND_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_constant(self, read):
+ self.validate_get_request(constants.URL,
+ params={
+ "name": constants.NAME
+ },
+ mocks={
+ read: constants.CONSTANTS_WITH_SPECIFIC_NAME
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=constants.
+ CONSTANTS_WITH_SPECIFIC_NAME[0]
+ )
diff --git a/app/test/api/responders_test/resource/test_environment_configs.py b/app/test/api/responders_test/resource/test_environment_configs.py
new file mode 100644
index 0000000..7002ed7
--- /dev/null
+++ b/app/test/api/responders_test/resource/test_environment_configs.py
@@ -0,0 +1,420 @@
+###############################################################################
+# 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 #
+###############################################################################
+import json
+
+from test.api.responders_test.test_data import base
+from test.api.test_base import TestBase
+from test.api.responders_test.test_data import environment_configs
+from utils.constants import EnvironmentFeatures
+from utils.inventory_mgr import InventoryMgr
+from unittest.mock import patch
+
+
+class TestEnvironmentConfigs(TestBase):
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_environment_configs_list(self, read):
+ self.validate_get_request(environment_configs.URL,
+ params={},
+ mocks={
+ read: environment_configs.ENV_CONFIGS
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=environment_configs.
+ ENV_CONFIGS_RESPONSE
+ )
+
+ def test_get_environment_configs_list_with_invalid_filters(self):
+ self.validate_get_request(environment_configs.URL,
+ params={
+ "unknown": "unknown"
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_environment_configs_list_with_name(self, read):
+ self.validate_get_request(environment_configs.URL,
+ params={
+ "name": environment_configs.NAME
+ },
+ mocks={
+ read: environment_configs.
+ ENV_CONFIGS_WITH_SPECIFIC_NAME
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=environment_configs.
+ ENV_CONFIGS_WITH_SPECIFIC_NAME[0]
+ )
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_environment_configs_list_with_unknown_name(self, read):
+ self.validate_get_request(environment_configs.URL,
+ params={
+ "name": environment_configs.UNKNOWN_NAME
+ },
+ mocks={
+ read: []
+ },
+ expected_code=base.NOT_FOUND_CODE)
+
+ def test_get_environment_configs_list_with_wrong_distribution(self):
+ self.validate_get_request(environment_configs.URL,
+ params={
+ "distribution":
+ environment_configs.WRONG_DISTRIBUTION
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_environment_configs_list_with_distribution(self, read):
+ self.validate_get_request(environment_configs.URL,
+ params={
+ "distribution":
+ environment_configs.CORRECT_DISTRIBUTION
+ },
+ mocks={
+ read: environment_configs.
+ ENV_CONFIGS_WITH_SPECIFIC_DISTRIBUTION
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=environment_configs.
+ ENV_CONFIGS_WITH_SPECIFIC_DISTRIBUTION_RESPONSE)
+
+ def test_get_environment_configs_list_with_wrong_mechanism_driver(self):
+ self.validate_get_request(environment_configs.URL,
+ params={
+ "mechanism_drivers":
+ environment_configs.WRONG_MECHANISM_DRIVER
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_environment_configs_list_with_mechanism_driver(self, read):
+ self.validate_get_request(environment_configs.URL,
+ params={
+ "mechanism_drivers":
+ environment_configs.CORRECT_MECHANISM_DRIVER
+ },
+ mocks={
+ read: environment_configs.
+ ENV_CONFIGS_WITH_SPECIFIC_MECHANISM_DRIVER
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=environment_configs.
+ ENV_CONFIGS_WITH_SPECIFIC_MECHANISM_DRIVER_RESPONSE
+ )
+
+ def test_get_environment_configs_list_with_wrong_type_driver(self):
+ self.validate_get_request(environment_configs.URL,
+ params={
+ "type_drivers":
+ environment_configs.WRONG_TYPE_DRIVER
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_environment_configs_list_with_type_driver(self, read):
+ self.validate_get_request(environment_configs.URL,
+ params={
+ "type_drivers":
+ environment_configs.CORRECT_TYPE_DRIVER
+ },
+ mocks={
+ read: environment_configs.
+ ENV_CONFIGS_WITH_SPECIFIC_TYPE_DRIVER
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=environment_configs.
+ ENV_CONFIGS_WITH_SPECIFIC_TYPE_DRIVER_RESPONSE
+ )
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_environment_configs_list_with_user(self, read):
+ self.validate_get_request(environment_configs.URL,
+ params={
+ "user": environment_configs.USER
+ },
+ mocks={
+ read: environment_configs.
+ ENV_CONFIGS_WITH_SPECIFIC_USER
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=environment_configs.
+ ENV_CONFIGS_WITH_SPECIFIC_USER_RESPONSE
+ )
+
+ def test_get_environment_configs_list_with_non_bool_listen(self):
+ self.validate_get_request(environment_configs.URL,
+ params={
+ "listen": environment_configs.NON_BOOL_LISTEN
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_environment_configs_list_with_bool_listen(self, read):
+ self.validate_get_request(environment_configs.URL,
+ params={
+ "listen": environment_configs.BOOL_LISTEN
+ },
+ mocks={
+ read: environment_configs.
+ ENV_CONFIGS_WITH_SPECIFIC_LISTEN
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=environment_configs.
+ ENV_CONFIGS_WITH_SPECIFIC_LISTEN_RESPONSE
+ )
+
+ def test_get_environment_configs_list_with_non_bool_scanned(self):
+ self.validate_get_request(environment_configs.URL,
+ params={
+ "scanned": environment_configs.
+ NON_BOOL_SCANNED
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_environment_configs_list_with_bool_scanned(self, read):
+ self.validate_get_request(environment_configs.URL,
+ params={
+ "scanned": environment_configs.BOOL_SCANNED
+ },
+ mocks={
+ read: environment_configs.
+ ENV_CONFIGS_WITH_SPECIFIC_SCANNED
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=environment_configs.
+ ENV_CONFIGS_WITH_SPECIFIC_SCANNED_RESPONSE
+ )
+
+ def test_get_environment_configs_list_with_non_bool_monitoring_setup_done(self):
+ self.validate_get_request(environment_configs.URL,
+ params={
+ "listen": environment_configs.
+ NON_BOOL_MONITORING_SETUP_DONE
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_environment_configs_list_with_bool_monitoring_setup_done(self, read):
+ self.validate_get_request(environment_configs.URL,
+ params={
+ "scanned": environment_configs.
+ BOOL_MONITORING_SETUP_DONE
+ },
+ mocks={
+ read: environment_configs.
+ ENV_CONFIGS_WITH_SPECIFIC_MONITORING_SETUP_DONE
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=environment_configs.
+ ENV_CONFIGS_WITH_SPECIFIC_MONITORING_SETUP_DONE_RESPONSE
+ )
+
+ def test_get_environment_configs_list_with_non_int_page(self):
+ self.validate_get_request(environment_configs.URL,
+ params={
+ "page": base.NON_INT_PAGE
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_environment_configs_list_with_int_page(self, read):
+ self.validate_get_request(environment_configs.URL,
+ params={
+ "page": base.INT_PAGE
+ },
+ mocks={
+ read: environment_configs.ENV_CONFIGS
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=environment_configs.
+ ENV_CONFIGS_RESPONSE
+ )
+
+ def test_get_environment_configs_list_with_non_int_page_size(self):
+ self.validate_get_request(environment_configs.URL,
+ params={
+ "page_size": base.NON_INT_PAGESIZE
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_environment_configs_list_with_int_page_size(self, read):
+ self.validate_get_request(environment_configs.URL,
+ params={
+ "page_size": base.INT_PAGESIZE
+ },
+ mocks={
+ read: environment_configs.ENV_CONFIGS
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=environment_configs.
+ ENV_CONFIGS_RESPONSE
+ )
+
+ def test_post_environment_config_without_app_path(self):
+ test_data = self.get_updated_data(environment_configs.ENV_CONFIG,
+ deleted_keys=["app_path"])
+ self.validate_post_request(environment_configs.URL,
+ body=json.dumps(test_data),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_environment_config_without_configuration(self):
+ test_data = self.get_updated_data(environment_configs.ENV_CONFIG,
+ deleted_keys=["configuration"])
+ self.validate_post_request(environment_configs.URL,
+ body=json.dumps(test_data),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_environment_config_without_distribution(self):
+ test_data = self.get_updated_data(environment_configs.ENV_CONFIG,
+ deleted_keys=["distribution"])
+ self.validate_post_request(environment_configs.URL,
+ body=json.dumps(test_data),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_environment_config_with_wrong_distribution(self):
+ test_data = self.get_updated_data(environment_configs.ENV_CONFIG,
+ updates={"distribution": environment_configs.WRONG_DISTRIBUTION})
+ self.validate_post_request(environment_configs.URL,
+ body=json.dumps(test_data),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_environment_config_without_listen(self):
+ test_data = self.get_updated_data(environment_configs.ENV_CONFIG,
+ deleted_keys=["listen"])
+ self.validate_post_request(environment_configs.URL,
+ body=json.dumps(test_data),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_environment_config_with_wrong_listen(self):
+ test_data = self.get_updated_data(environment_configs.ENV_CONFIG,
+ updates={"listen": environment_configs.NON_BOOL_LISTEN})
+ self.validate_post_request(environment_configs.URL,
+ body=json.dumps(test_data),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_environment_config_without_mechanism_driver(self):
+ test_data = self.get_updated_data(environment_configs.ENV_CONFIG,
+ deleted_keys=["mechanism_drivers"])
+ self.validate_post_request(environment_configs.URL,
+ body=json.dumps(test_data),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_environment_config_with_wrong_mechanism_driver(self):
+ test_data = self.get_updated_data(environment_configs.ENV_CONFIG,
+ updates={
+ "mechanism_drivers":
+ [environment_configs.WRONG_MECHANISM_DRIVER]
+ })
+ self.validate_post_request(environment_configs.URL,
+ body=json.dumps(test_data),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_environment_config_without_name(self):
+ test_data = self.get_updated_data(environment_configs.ENV_CONFIG,
+ deleted_keys=["name"])
+ self.validate_post_request(environment_configs.URL,
+ body=json.dumps(test_data),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_environment_config_without_operational(self):
+ test_data = self.get_updated_data(environment_configs.ENV_CONFIG,
+ deleted_keys=["operational"])
+ self.validate_post_request(environment_configs.URL,
+ body=json.dumps(test_data),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_environment_config_with_wrong_scanned(self):
+ test_data = self.get_updated_data(environment_configs.ENV_CONFIG,
+ updates={
+ "scanned": environment_configs.NON_BOOL_SCANNED
+ })
+ self.validate_post_request(environment_configs.URL,
+ body=json.dumps(test_data),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_environment_config_with_wrong_last_scanned(self):
+ test_data = self.get_updated_data(environment_configs.ENV_CONFIG,
+ updates={
+ "last_scanned": base.WRONG_FORMAT_TIME
+ })
+ self.validate_post_request(environment_configs.URL,
+ body=json.dumps(test_data),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_environment_config_without_type(self):
+ test_data = self.get_updated_data(environment_configs.ENV_CONFIG,
+ deleted_keys=["type"])
+ self.validate_post_request(environment_configs.URL,
+ body=json.dumps(test_data),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_environment_config_without_type_drivers(self):
+ test_data = self.get_updated_data(environment_configs.ENV_CONFIG,
+ deleted_keys=["type_drivers"])
+ self.validate_post_request(environment_configs.URL,
+ body=json.dumps(test_data),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_environment_config_with_wrong_type_drivers(self):
+ test_data = self.get_updated_data(environment_configs.ENV_CONFIG,
+ updates={
+ "type_drivers": [environment_configs.WRONG_TYPE_DRIVER]
+ })
+ self.validate_post_request(environment_configs.URL,
+ body=json.dumps(test_data),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def mock_validate_env_config_with_supported_envs(self, scanning,
+ monitoring, listening):
+ InventoryMgr.is_feature_supported_in_env = lambda self, matches, feature: {
+ EnvironmentFeatures.SCANNING: scanning,
+ EnvironmentFeatures.MONITORING: monitoring,
+ EnvironmentFeatures.LISTENING: listening
+ }[feature]
+
+ @patch(base.RESPONDER_BASE_WRITE)
+ def test_post_environment_config(self, write):
+ self.mock_validate_env_config_with_supported_envs(True, True, True)
+ self.validate_post_request(environment_configs.URL,
+ mocks={
+ write: None
+ },
+ body=json.dumps(environment_configs.ENV_CONFIG),
+ expected_code=base.CREATED_CODE)
+
+ def test_post_unsupported_environment_config(self):
+ test_cases = [
+ {
+ "scanning": False,
+ "monitoring": True,
+ "listening": True
+ },
+ {
+ "scanning": True,
+ "monitoring": False,
+ "listening": True
+ },
+ {
+ "scanning": True,
+ "monitoring": True,
+ "listening": False
+ }
+ ]
+ for test_case in test_cases:
+ self.mock_validate_env_config_with_supported_envs(test_case["scanning"],
+ test_case["monitoring"],
+ test_case["listening"])
+ self.validate_post_request(environment_configs.URL,
+ body=json.dumps(environment_configs.ENV_CONFIG),
+ expected_code=base.BAD_REQUEST_CODE)
diff --git a/app/test/api/responders_test/resource/test_inventory.py b/app/test/api/responders_test/resource/test_inventory.py
new file mode 100644
index 0000000..0ef9089
--- /dev/null
+++ b/app/test/api/responders_test/resource/test_inventory.py
@@ -0,0 +1,162 @@
+###############################################################################
+# 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.responders_test.test_data import base
+from test.api.responders_test.test_data import inventory
+from test.api.test_base import TestBase
+from unittest.mock import patch
+
+
+class TestInventory(TestBase):
+
+ def test_get_objects_list_without_env_name(self):
+ self.validate_get_request(inventory.URL,
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_get_objects_list_with_invalid_filter(self):
+ self.validate_get_request(inventory.URL,
+ params={
+ "invalid": "invalid"
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_get_objects_list_with_non_boolean_subtree(self):
+ self.validate_get_request(inventory.URL,
+ params={
+ 'env_name': base.ENV_NAME,
+ 'sub_tree': base.NON_BOOL
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_objects_list_with_boolean_subtree(self, read):
+ self.validate_get_request(inventory.URL,
+ params={
+ 'env_name': base.ENV_NAME,
+ 'sub_tree': base.BOOL
+ },
+ mocks={
+ read: inventory.OBJECTS_LIST
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=inventory.OBJECT_IDS_RESPONSE
+ )
+
+ def test_get_objects_list_with_non_int_page(self):
+ self.validate_get_request(inventory.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_objects_list_with_int_page(self, read):
+ self.validate_get_request(inventory.URL,
+ params={
+ 'env_name': base.ENV_NAME,
+ 'page': base.INT_PAGE
+ },
+ mocks={
+ read: inventory.OBJECTS_LIST
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=inventory.OBJECT_IDS_RESPONSE
+ )
+
+ def test_get_objects_list_with_non_int_pagesize(self):
+ self.validate_get_request(inventory.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_objects_list_with_int_pagesize(self, read):
+ self.validate_get_request(inventory.URL,
+ params={
+ 'env_name': base.ENV_NAME,
+ 'page_size': base.INT_PAGESIZE
+ },
+ mocks={
+ read: inventory.OBJECTS_LIST
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=inventory.OBJECT_IDS_RESPONSE
+ )
+
+ @patch(base.RESPONDER_BASE_READ)
+ @patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME)
+ def test_get_nonexistent_objects_list_with_env_name(self, check_env_name, read):
+ self.validate_get_request(inventory.URL,
+ params={
+ 'env_name': base.ENV_NAME,
+ },
+ mocks={
+ read: [],
+ check_env_name: True
+ },
+ expected_code=base.NOT_FOUND_CODE,
+ )
+
+ @patch(base.RESPONDER_BASE_READ)
+ @patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME)
+ def test_get_objects_list_with_unkown_env_name(self, check_env_name, read):
+ self.validate_get_request(inventory.URL,
+ params={
+ 'env_name': base.ENV_NAME,
+ },
+ mocks={
+ read: [],
+ check_env_name: False
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_object_with_env_name_and_id(self, read):
+ self.validate_get_request(inventory.URL,
+ params={
+ 'env_name': base.ENV_NAME,
+ 'id': inventory.ID
+ },
+ mocks={
+ read: inventory.OBJECTS
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=inventory.OBJECTS[0]
+ )
+
+ @patch(base.RESPONDER_BASE_READ)
+ @patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME)
+ def test_get_nonexistent_object_with_env_name_and_id(self, check_env_name, read):
+ self.validate_get_request(inventory.URL,
+ params={
+ 'env_name': base.ENV_NAME,
+ 'id': inventory.NONEXISTENT_ID
+ },
+ mocks={
+ read: [],
+ check_env_name: True
+ },
+ expected_code=base.NOT_FOUND_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ @patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME)
+ def test_get_object_with_unkown_env_name_and_id(self, check_env_name, read):
+ self.validate_get_request(inventory.URL,
+ params={
+ 'env_name': base.UNKNOWN_ENV,
+ 'id': inventory.ID
+ },
+ mocks={
+ read: [],
+ check_env_name: False
+ },
+ expected_code=base.BAD_REQUEST_CODE)
diff --git a/app/test/api/responders_test/resource/test_links.py b/app/test/api/responders_test/resource/test_links.py
new file mode 100644
index 0000000..b312aa1
--- /dev/null
+++ b/app/test/api/responders_test/resource/test_links.py
@@ -0,0 +1,193 @@
+###############################################################################
+# 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.responders_test.test_data import base
+from test.api.responders_test.test_data import links
+from test.api.test_base import TestBase
+from unittest.mock import patch
+
+
+class TestLinks(TestBase):
+
+ def test_get_links_list_without_env_name(self):
+ self.validate_get_request(links.URL,
+ params={},
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_get_links_list_with_invalid_filters(self):
+ self.validate_get_request(links.URL,
+ params={
+ 'invalid': 'invalid'
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_get_links_list_with_wrong_link_type(self):
+ self.validate_get_request(links.URL,
+ params={
+ 'env_name': base.ENV_NAME,
+ 'link_type': links.WRONG_TYPE
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_links_list_with_correct_link_type(self, read):
+ self.validate_get_request(links.URL,
+ params={
+ 'env_name': base.ENV_NAME,
+ 'link_type': links.CORRECT_TYPE
+ },
+ mocks={
+ read: links.LINKS_WITH_SPECIFIC_TYPE
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=links.
+ LINKS_WITH_SPECIFIC_TYPE_RESPONSE
+ )
+
+ def test_get_links_list_with_wrong_state(self):
+ self.validate_get_request(links.URL,
+ params={
+ 'env_name': base.ENV_NAME,
+ 'state': links.WRONG_STATE
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_links_list_with_correct_state(self, read):
+ self.validate_get_request(links.URL,
+ params={
+ 'env_name': base.ENV_NAME,
+ 'state': links.CORRECT_STATE
+ },
+ mocks={
+ read: links.LINKS_WITH_SPECIFIC_STATE,
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=links.
+ LINKS_WITH_SPECIFIC_STATE_RESPONSE
+ )
+
+ def test_get_link_with_env_name_and_wrong_link_id(self):
+ self.validate_get_request(links.URL,
+ params={
+ 'env_name': base.ENV_NAME,
+ 'id': links.WRONG_LINK_ID
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_link_with_env_name_and_link_id(self, read):
+ self.validate_get_request(links.URL,
+ params={
+ 'env_name': base.ENV_NAME,
+ 'id': links.LINK_ID
+ },
+ mocks={
+ read: links.LINKS_WITH_SPECIFIC_ID
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=links.
+ LINKS_WITH_SPECIFIC_ID[0]
+ )
+
+ def test_get_links_list_with_non_int_page(self):
+ self.validate_get_request(links.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_links_list_with_int_page(self, read):
+ self.validate_get_request(links.URL,
+ params={
+ 'env_name': base.ENV_NAME,
+ 'page': base.INT_PAGE
+ },
+ mocks={
+ read: links.LINKS
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=links.LINKS_LIST_RESPONSE)
+
+ def test_get_link_ids_with_non_int_page_size(self):
+ self.validate_get_request(links.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_links_list_with_int_page_size(self, read):
+ self.validate_get_request(links.URL,
+ params={
+ 'env_name': base.ENV_NAME,
+ 'page_size': base.INT_PAGESIZE
+ },
+ mocks={
+ read: links.LINKS
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=links.LINKS_LIST_RESPONSE)
+
+ @patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME)
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_links_list_with_env_name_and_unknown_host(self, read, check_env_name):
+ self.validate_get_request(links.URL,
+ params={
+ 'env_name': base.ENV_NAME,
+ 'host': links.UNKNOWN_HOST
+ },
+ 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_links_list_with_unknown_env_name(self, read, check_env_name):
+ self.validate_get_request(links.URL,
+ params={
+ 'env_name': base.UNKNOWN_ENV
+ },
+ 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_link_with_env_name_and_nonexistent_link_id(self, read, check_env_name):
+ self.validate_get_request(links.URL,
+ params={
+ 'env_name': base.ENV_NAME,
+ 'id': links.NONEXISTENT_LINK_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_link_with_unknown_env_name(self, read, check_env_name):
+ self.validate_get_request(links.URL,
+ params={
+ 'env_name': base.UNKNOWN_ENV
+ },
+ mocks={
+ read: [],
+ check_env_name: False
+ },
+ expected_code=base.BAD_REQUEST_CODE)
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])
diff --git a/app/test/api/responders_test/resource/test_monitoring_config_templates.py b/app/test/api/responders_test/resource/test_monitoring_config_templates.py
new file mode 100644
index 0000000..04f413e
--- /dev/null
+++ b/app/test/api/responders_test/resource/test_monitoring_config_templates.py
@@ -0,0 +1,156 @@
+###############################################################################
+# 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 monitoring_config_templates
+from unittest.mock import patch
+
+
+class TestMonitoringConfigTemplates(TestBase):
+
+ def test_get_templates_list_with_unknown_filter(self):
+ self.validate_get_request(monitoring_config_templates.URL,
+ params={
+ "unknown": "unknown"
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_get_templates_list_with_non_int_order(self):
+ self.validate_get_request(monitoring_config_templates.URL,
+ params={
+ "order": monitoring_config_templates.NON_INT_ORDER
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_templates_list_with_order(self, read):
+ self.validate_get_request(monitoring_config_templates.URL,
+ params={
+ "order": monitoring_config_templates.INT_ORDER
+ },
+ mocks={
+ read: monitoring_config_templates.
+ TEMPLATES_WITH_SPECIFIC_ORDER
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=monitoring_config_templates.
+ TEMPLATES_WITH_SPECIFIC_ORDER_RESPONSE
+ )
+
+ def test_get_templates_list_with_wrong_side(self):
+ self.validate_get_request(monitoring_config_templates.URL,
+ params={
+ "side": monitoring_config_templates.WRONG_SIDE
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_templates_list_with_side(self, read):
+ self.validate_get_request(monitoring_config_templates.URL,
+ params={
+ "side": monitoring_config_templates.CORRECT_SIDE
+ },
+ mocks={
+ read: monitoring_config_templates.
+ TEMPLATES_WITH_SPECIFIC_SIDE
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=monitoring_config_templates.
+ TEMPLATES_WITH_SPECIFIC_SIDE_RESPONSE
+ )
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_templates_list_with_type(self, read):
+ self.validate_get_request(monitoring_config_templates.URL,
+ params={
+ "type": monitoring_config_templates.TYPE
+ },
+ mocks={
+ read: monitoring_config_templates.
+ TEMPLATES_WITH_SPECIFIC_TYPE
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=monitoring_config_templates.
+ TEMPLATES_WITH_SPECIFIC_TYPE_RESPONSE
+ )
+
+ def test_get_templates_list_with_non_int_page(self):
+ self.validate_get_request(monitoring_config_templates.URL,
+ params={
+ "page": base.NON_INT_PAGE
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_templates_list_with_int_page(self, read):
+ self.validate_get_request(monitoring_config_templates.URL,
+ params={
+ "page": base.INT_PAGE
+ },
+ mocks={
+ read: monitoring_config_templates.TEMPLATES
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=monitoring_config_templates.
+ TEMPLATES_RESPONSE
+ )
+
+ def test_get_templates_list_with_non_int_pagesize(self):
+ self.validate_get_request(monitoring_config_templates.URL,
+ params={
+ "page_size": base.NON_INT_PAGESIZE
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_templates_list_with_int_pagesize(self, read):
+ self.validate_get_request(monitoring_config_templates.URL,
+ params={
+ "page_size": base.INT_PAGESIZE
+ },
+ mocks={
+ read: monitoring_config_templates.TEMPLATES
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=monitoring_config_templates.
+ TEMPLATES_RESPONSE
+ )
+
+ def test_get_template_with_wrong_id(self):
+ self.validate_get_request(monitoring_config_templates.URL,
+ params={
+ "id": monitoring_config_templates.WRONG_ID
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_template_with_unknown_id(self, read):
+ self.validate_get_request(monitoring_config_templates.URL,
+ params={
+ "id": monitoring_config_templates.UNKNOWN_ID
+ },
+ mocks={
+ read: []
+ },
+ expected_code=base.NOT_FOUND_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_template_with_id(self, read):
+ self.validate_get_request(monitoring_config_templates.URL,
+ params={
+ "id": monitoring_config_templates.CORRECT_ID
+ },
+ mocks={
+ read: monitoring_config_templates.TEMPLATES_WITH_SPECIFIC_ID
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=monitoring_config_templates.
+ TEMPLATES_WITH_SPECIFIC_ID[0]
+ )
diff --git a/app/test/api/responders_test/resource/test_scans.py b/app/test/api/responders_test/resource/test_scans.py
new file mode 100644
index 0000000..708cd54
--- /dev/null
+++ b/app/test/api/responders_test/resource/test_scans.py
@@ -0,0 +1,239 @@
+###############################################################################
+# 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 #
+###############################################################################
+import json
+
+from test.api.responders_test.test_data import base
+from test.api.test_base import TestBase
+from test.api.responders_test.test_data import scans
+from unittest.mock import patch
+
+
+class TestScans(TestBase):
+
+ def test_get_scans_list_without_env_name(self):
+ self.validate_get_request(scans.URL,
+ params={},
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_get_scans_list_with_invalid_filter(self):
+ self.validate_get_request(scans.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "invalid": "invalid"
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_get_scans_list_with_non_int_page(self):
+ self.validate_get_request(scans.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_scans_list_with_int_page(self, read):
+ self.validate_get_request(scans.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "page": base.INT_PAGE
+ },
+ mocks={
+ read: scans.SCANS
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=scans.SCANS_RESPONSE)
+
+ def test_get_scans_list_with_non_int_pagesize(self):
+ self.validate_get_request(scans.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_scans_list_with_int_pagesize(self, read):
+ self.validate_get_request(scans.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "page_size": base.INT_PAGESIZE
+ },
+ mocks={
+ read: scans.SCANS
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=scans.SCANS_RESPONSE)
+
+ @patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME)
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_scans_list_with_unknown_env(self, read, check_env_name):
+ self.validate_get_request(scans.URL,
+ params={
+ "env_name": base.UNKNOWN_ENV
+ },
+ mocks={
+ read: [],
+ check_env_name: False
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_scans_list_with_base_object(self, read):
+ self.validate_get_request(scans.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "base_object": scans.BASE_OBJECT
+ },
+ mocks={
+ read: scans.SCANS_WITH_SPECIFIC_BASE_OBJ
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=scans.
+ SCANS_WITH_SPECIFIC_BASE_OBJ_RESPONSE
+ )
+
+ def test_get_scans_list_with_wrong_status(self):
+ self.validate_get_request(scans.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "status": scans.WRONG_STATUS
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_scans_list_with_status(self, read):
+ self.validate_get_request(scans.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "status": scans.CORRECT_STATUS
+ },
+ mocks={
+ read: scans.SCANS_WITH_SPECIFIC_STATUS,
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=scans.
+ SCANS_WITH_SPECIFIC_STATUS_RESPONSE
+ )
+
+ def test_get_scan_with_wrong_id(self):
+ self.validate_get_request(scans.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "id": scans.WRONG_ID
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME)
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_scan_with_nonexistent_id(self, read, check_env_name):
+ self.validate_get_request(scans.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "id": scans.NONEXISTENT_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_scan_with_unknown_env_and_nonexistent_id(self, read, check_env_name):
+ self.validate_get_request(scans.URL,
+ params={
+ "env_name": base.UNKNOWN_ENV,
+ "id": scans.NONEXISTENT_ID
+ },
+ mocks={
+ read: [],
+ check_env_name: False
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_scan_with_id(self, read):
+ self.validate_get_request(scans.URL,
+ params={
+ "env_name": base.ENV_NAME,
+ "id": scans.CORRECT_ID
+ },
+ mocks={
+ read: scans.SCANS_WITH_SPECIFIC_ID
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=scans.SCANS_WITH_SPECIFIC_ID[0]
+ )
+
+ def test_post_scan_with_non_dict_scan(self):
+ self.validate_post_request(scans.URL,
+ body=json.dumps(scans.NON_DICT_SCAN),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_scan_without_env_name(self):
+ self.validate_post_request(scans.URL,
+ body=json.dumps(scans.SCAN_WITHOUT_ENV),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME)
+ def test_post_scan_with_unknown_env_name(self, check_environment_name):
+ self.validate_post_request(scans.URL,
+ mocks={
+ check_environment_name: False
+ },
+ body=json.dumps(scans.SCAN_WITH_UNKNOWN_ENV),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_scan_without_status(self):
+ self.validate_post_request(scans.URL,
+ body=json.dumps(scans.SCAN_WITHOUT_STATUS),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_scan_with_wrong_status(self):
+ self.validate_post_request(scans.URL,
+ body=json.dumps(scans.SCAN_WITH_WRONG_STATUS),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_scan_with_wrong_log_level(self):
+ self.validate_post_request(scans.URL,
+ body=json.dumps(scans.SCAN_WITH_WRONG_LOG_LEVEL),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_scan_with_non_bool_clear(self):
+ self.validate_post_request(scans.URL,
+ body=json.dumps(scans.SCAN_WITH_NON_BOOL_CLEAR),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_scan_with_non_bool_scan_only_inventory(self):
+ self.validate_post_request(scans.URL,
+ body=json.dumps(scans.SCAN_WITH_NON_BOOL_SCAN_ONLY_INVENTORY),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_scan_with_non_bool_scan_only_links(self):
+ self.validate_post_request(scans.URL,
+ body=json.dumps(scans.SCAN_WITH_NON_BOOL_SCAN_ONLY_LINKS),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_scan_with_non_bool_scan_only_cliques(self):
+ self.validate_post_request(scans.URL,
+ body=json.dumps(scans.SCAN_WITH_NON_BOOL_SCAN_ONLY_CLIQUES),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME)
+ @patch(base.RESPONDER_BASE_WRITE)
+ def test_post_scan(self, write, check_env_name):
+ self.validate_post_request(scans.URL,
+ mocks={
+ check_env_name: True,
+ write: None
+ },
+ body=json.dumps(scans.SCAN),
+ expected_code=base.CREATED_CODE)
diff --git a/app/test/api/responders_test/resource/test_scheduled_scans.py b/app/test/api/responders_test/resource/test_scheduled_scans.py
new file mode 100644
index 0000000..23c38de
--- /dev/null
+++ b/app/test/api/responders_test/resource/test_scheduled_scans.py
@@ -0,0 +1,247 @@
+###############################################################################
+# 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 #
+###############################################################################
+import json
+
+from test.api.responders_test.test_data import base
+from test.api.test_base import TestBase
+from test.api.responders_test.test_data import scheduled_scans
+from unittest.mock import patch
+
+
+class TestScheduledScans(TestBase):
+ def test_get_scheduled_scans_list_without_env_name(self):
+ self.validate_get_request(scheduled_scans.URL,
+ params={},
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_get_scheduled_scans_list_with_invalid_filter(self):
+ self.validate_get_request(scheduled_scans.URL,
+ params={
+ "environment": base.ENV_NAME,
+ "invalid": "invalid"
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_get_scheduled_scans_list_with_non_int_page(self):
+ self.validate_get_request(scheduled_scans.URL,
+ params={
+ "environment": base.ENV_NAME,
+ "page": base.NON_INT_PAGE
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_scheduled_scans_list_with_int_page(self, read):
+ self.validate_get_request(scheduled_scans.URL,
+ params={
+ "environment": base.ENV_NAME,
+ "page": base.INT_PAGE
+ },
+ mocks={
+ read: scheduled_scans.SCHEDULED_SCANS
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=scheduled_scans.
+ SCHEDULED_SCANS_RESPONSE
+ )
+
+ def test_get_scheduled_scans_list_with_non_int_pagesize(self):
+ self.validate_get_request(scheduled_scans.URL,
+ params={
+ "environment": base.ENV_NAME,
+ "page_size": base.NON_INT_PAGESIZE
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_scheduled_scans_list_with_int_pagesize(self, read):
+ self.validate_get_request(scheduled_scans.URL,
+ params={
+ "environment": base.ENV_NAME,
+ "page_size": base.INT_PAGESIZE
+ },
+ mocks={
+ read: scheduled_scans.SCHEDULED_SCANS
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=scheduled_scans.
+ SCHEDULED_SCANS_RESPONSE
+ )
+
+ @patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME)
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_scheduled_scans_list_with_unknown_env(self, read, check_env_name):
+ self.validate_get_request(scheduled_scans.URL,
+ params={
+ "environment": base.UNKNOWN_ENV
+ },
+ mocks={
+ read: [],
+ check_env_name: False
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_get_scheduled_scans_list_with_wrong_freq(self):
+ self.validate_get_request(scheduled_scans.URL,
+ params={
+ "environment": base.ENV_NAME,
+ "freq": scheduled_scans.WRONG_FREQ
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_scheduled_scans_list_with_freq(self, read):
+ self.validate_get_request(scheduled_scans.URL,
+ params={
+ "environment": base.ENV_NAME,
+ "freq": scheduled_scans.CORRECT_FREQ
+ },
+ mocks={
+ read: scheduled_scans.
+ SCHEDULED_SCAN_WITH_SPECIFIC_FREQ,
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=scheduled_scans.
+ SCHEDULED_SCAN_WITH_SPECIFIC_FREQ_RESPONSE
+ )
+
+ def test_get_scheduled_scan_with_wrong_id(self):
+ self.validate_get_request(scheduled_scans.URL,
+ params={
+ "environment": base.ENV_NAME,
+ "id": scheduled_scans.WRONG_ID
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME)
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_scan_with_nonexistent_id(self, read, check_env_name):
+ self.validate_get_request(scheduled_scans.URL,
+ params={
+ "environment": base.ENV_NAME,
+ "id": scheduled_scans.NONEXISTENT_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_scheduled_scan_with_unknown_env_and_nonexistent_id(self, read,
+ check_env_name):
+ self.validate_get_request(scheduled_scans.URL,
+ params={
+ "environment": base.UNKNOWN_ENV,
+ "id": scheduled_scans.NONEXISTENT_ID
+ },
+ mocks={
+ read: [],
+ check_env_name: False
+ },
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_READ)
+ def test_get_scheduled_scan_with_id(self, read):
+ self.validate_get_request(scheduled_scans.URL,
+ params={
+ "environment": base.ENV_NAME,
+ "id": scheduled_scans.CORRECT_ID
+ },
+ mocks={
+ read: scheduled_scans.
+ SCHEDULED_SCAN_WITH_SPECIFIC_ID
+ },
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=scheduled_scans.
+ SCHEDULED_SCAN_WITH_SPECIFIC_ID[0]
+ )
+
+ def test_post_scheduled_scan_with_non_dict_scheduled_scan(self):
+ self.validate_post_request(scheduled_scans.URL,
+ body=json.dumps(scheduled_scans.
+ NON_DICT_SCHEDULED_SCAN),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_post_bad_scheduled_scans(self):
+ test_cases = [
+ {
+ "body": scheduled_scans.
+ SCHEDULED_SCAN_WITHOUT_ENV
+ },
+ {
+ "body": scheduled_scans.
+ SCHEDULED_SCAN_WITHOUT_FREQ
+ },
+ {
+ "body": scheduled_scans.
+ SCHEDULED_SCAN_WITH_WRONG_FREQ
+ },
+ {
+ "body": scheduled_scans.
+ SCHEDULED_SCAN_WITH_WRONG_LOG_LEVEL
+ },
+ {
+ "body": scheduled_scans.
+ SCHEDULED_SCAN_WITHOUT_SUBMIT_TIMESTAMP
+ },
+ {
+ "body": scheduled_scans.
+ SCHEDULED_SCAN_WITH_WRONG_SUBMIT_TIMESTAMP
+ },
+ {
+ "body": scheduled_scans.
+ SCHEDULED_SCAN_WITH_NON_BOOL_CLEAR
+ },
+ {
+ "body": scheduled_scans.
+ SCHEDULED_SCAN_WITH_NON_BOOL_SCAN_ONLY_LINKS
+ },
+ {
+ "body": scheduled_scans.
+ SCHEDULED_SCAN_WITH_NON_BOOL_SCAN_ONLY_CLIQUES
+ },
+ {
+ "body": scheduled_scans.
+ SCHEDULED_SCAN_WITH_NON_BOOL_SCAN_ONLY_INVENTORY
+ },
+ {
+ "body": scheduled_scans.
+ SCHEDULED_SCAN_WITH_EXTRA_SCAN_ONLY_FLAGS
+ }
+ ]
+ for test_case in test_cases:
+ self.validate_post_request(scheduled_scans.URL,
+ body=json.dumps(test_case["body"]),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME)
+ def test_post_scheduled_scan_with_unknown_env_name(self,
+ check_environment_name):
+ self.validate_post_request(scheduled_scans.URL,
+ mocks={
+ check_environment_name: False
+ },
+ body=json.dumps(scheduled_scans.
+ SCHEDULED_SCAN_WITH_UNKNOWN_ENV),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ @patch(base.RESPONDER_BASE_CHECK_ENVIRONMENT_NAME)
+ @patch(base.RESPONDER_BASE_WRITE)
+ def test_post_scheduled_scan(self, write, check_env_name):
+ self.validate_post_request(scheduled_scans.URL,
+ mocks={
+ check_env_name: True,
+ write: None
+ },
+ body=json.dumps(scheduled_scans.
+ SCHEDULED_SCAN),
+ expected_code=base.CREATED_CODE)