aboutsummaryrefslogtreecommitdiffstats
path: root/app/test/api
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
parent378ecbd8947589b9cbb39013a0c2e2aa201e03bd (diff)
Calipso initial release for OPNFV
Change-Id: I7210c244b0c10fa80bfa8c77cb86c9d6ddf8bc88 Signed-off-by: Yaron Yogev <yaronyogev@gmail.com>
Diffstat (limited to 'app/test/api')
-rw-r--r--app/test/api/__init__.py10
-rw-r--r--app/test/api/responders_test/__init__.py10
-rw-r--r--app/test/api/responders_test/auth/__init__.py10
-rw-r--r--app/test/api/responders_test/auth/test_tokens.py105
-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
-rw-r--r--app/test/api/responders_test/test_data/__init__.py10
-rw-r--r--app/test/api/responders_test/test_data/aggregates.py67
-rw-r--r--app/test/api/responders_test/test_data/base.py179
-rw-r--r--app/test/api/responders_test/test_data/clique_constraints.py74
-rw-r--r--app/test/api/responders_test/test_data/clique_types.py170
-rw-r--r--app/test/api/responders_test/test_data/cliques.py171
-rw-r--r--app/test/api/responders_test/test_data/constants.py23
-rw-r--r--app/test/api/responders_test/test_data/environment_configs.py221
-rw-r--r--app/test/api/responders_test/test_data/inventory.py37
-rw-r--r--app/test/api/responders_test/test_data/links.py90
-rw-r--r--app/test/api/responders_test/test_data/messages.py108
-rw-r--r--app/test/api/responders_test/test_data/monitoring_config_templates.py98
-rw-r--r--app/test/api/responders_test/test_data/scans.py187
-rw-r--r--app/test/api/responders_test/test_data/scheduled_scans.py138
-rw-r--r--app/test/api/responders_test/test_data/tokens.py83
-rw-r--r--app/test/api/test_base.py101
33 files changed, 4356 insertions, 0 deletions
diff --git a/app/test/api/__init__.py b/app/test/api/__init__.py
new file mode 100644
index 0000000..1e85a2a
--- /dev/null
+++ b/app/test/api/__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/__init__.py b/app/test/api/responders_test/__init__.py
new file mode 100644
index 0000000..1e85a2a
--- /dev/null
+++ b/app/test/api/responders_test/__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/auth/__init__.py b/app/test/api/responders_test/auth/__init__.py
new file mode 100644
index 0000000..1e85a2a
--- /dev/null
+++ b/app/test/api/responders_test/auth/__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/auth/test_tokens.py b/app/test/api/responders_test/auth/test_tokens.py
new file mode 100644
index 0000000..d7b9675
--- /dev/null
+++ b/app/test/api/responders_test/auth/test_tokens.py
@@ -0,0 +1,105 @@
+###############################################################################
+# 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 unittest.mock import patch
+
+from test.api.responders_test.test_data import base
+
+from test.api.responders_test.test_data import tokens
+from test.api.test_base import TestBase
+
+
+class TestTokens(TestBase):
+
+ def test_create_token_without_auth_obj(self):
+ self.validate_post_request(tokens.URL,
+ body=json.dumps(tokens.AUTH_OBJ_WITHOUT_AUTH),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_create_token_without_methods(self):
+ self.validate_post_request(tokens.URL,
+ body=json.dumps(tokens.AUTH_OBJ_WITHOUT_METHODS),
+ expected_code=base.BAD_REQUEST_CODE)
+
+ def test_create_token_without_credentials_in_credentials_method(self):
+ self.validate_post_request(tokens.URL,
+ body=json.dumps(tokens.AUTH_OBJ_WITHOUT_CREDENTIALS),
+ expected_code=base.UNAUTHORIZED_CODE)
+
+ def test_create_token_without_token_in_token_method(self):
+ self.validate_post_request(tokens.URL,
+ body=json.dumps(tokens.AUTH_OBJ_WITHOUT_TOKEN),
+ expected_code=base.UNAUTHORIZED_CODE)
+
+ @patch(tokens.AUTH_VALIDATE_CREDENTIALS)
+ def test_create_token_with_wrong_credentials(self, validate_credentials):
+ self.validate_post_request(tokens.URL,
+ body=json.dumps(tokens.AUTH_OBJ_WITH_WRONG_CREDENTIALS),
+ mocks={
+ validate_credentials: False
+ },
+ expected_code=base.UNAUTHORIZED_CODE)
+
+ @patch(tokens.AUTH_VALIDATE_TOKEN)
+ def test_create_token_with_wrong_token(self, validate_token):
+ self.validate_post_request(tokens.URL,
+ body=json.dumps(tokens.AUTH_OBJ_WITH_WRONG_TOKEN),
+ mocks={
+ validate_token: 'token error'
+ },
+ expected_code=base.UNAUTHORIZED_CODE)
+
+ @patch(tokens.AUTH_WRITE_TOKEN)
+ @patch(tokens.AUTH_VALIDATE_CREDENTIALS)
+ def test_create_token_with_correct_credentials(self, validate_credentials, write_token):
+ self.validate_post_request(tokens.URL,
+ body=json.dumps(tokens.AUTH_OBJ_WITH_CORRECT_CREDENTIALS),
+ mocks={
+ validate_credentials: True,
+ write_token: None
+ },
+ expected_code=base.CREATED_CODE)
+
+ @patch(tokens.AUTH_WRITE_TOKEN)
+ @patch(tokens.AUTH_VALIDATE_TOKEN)
+ def test_create_token_with_correct_token(self, validate_token, write_token):
+ self.validate_post_request(tokens.URL,
+ body=json.dumps(tokens.AUTH_OBJ_WITH_CORRECT_TOKEN),
+ mocks={
+ validate_token: None,
+ write_token: None
+ },
+ expected_code=base.CREATED_CODE)
+
+ def test_delete_token_without_token(self):
+ self.validate_delete_request(tokens.URL,
+ headers=tokens.HEADER_WITHOUT_TOKEN,
+ expected_code=base.UNAUTHORIZED_CODE
+ )
+
+ @patch(tokens.AUTH_VALIDATE_TOKEN)
+ def test_delete_token_with_wrong_token(self, validate_token):
+ self.validate_delete_request(tokens.URL,
+ headers=tokens.HEADER_WITH_WRONG_TOKEN,
+ mocks={
+ validate_token: 'token error'
+ },
+ expected_code=base.UNAUTHORIZED_CODE)
+
+ @patch(tokens.AUTH_VALIDATE_TOKEN)
+ @patch(tokens.AUTH_DELETE_TOKEN)
+ def test_delete_token_with_correct_token(self, delete_token, validate_token):
+ self.validate_delete_request(tokens.URL,
+ headers=tokens.HEADER_WITH_CORRECT_TOKEN,
+ mocks={
+ validate_token: None,
+ delete_token: None
+ },
+ expected_code=base.SUCCESSFUL_CODE)
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)
diff --git a/app/test/api/responders_test/test_data/__init__.py b/app/test/api/responders_test/test_data/__init__.py
new file mode 100644
index 0000000..1e85a2a
--- /dev/null
+++ b/app/test/api/responders_test/test_data/__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/test_data/aggregates.py b/app/test/api/responders_test/test_data/aggregates.py
new file mode 100644
index 0000000..52ce985
--- /dev/null
+++ b/app/test/api/responders_test/test_data/aggregates.py
@@ -0,0 +1,67 @@
+###############################################################################
+# 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 #
+###############################################################################
+URL = "/aggregates"
+
+CONSTANT_TYPE = "constant"
+ENV_TYPE = "environment"
+MESSAGE_TYPE = "message"
+UNKNOWN_TYPE = "unknown"
+
+CONSTANT_AGGREGATES = [
+ {"name": "type_drivers", "total": 5},
+ {"name": "environment_monitoring_types", "total": 1},
+ {"name": "link_states", "total": 2}
+]
+ENVIRONMENT_AGGREGATES = [
+ {'_id': 'otep', 'total': 3},
+ {'_id': 'instance', 'total': 2},
+ {'_id': 'network_agent', 'total': 6}
+]
+MESSAGE_ENV_AGGREGATES = [
+ {'_id': 'Mirantis-Liberty-API', 'total': 15}
+]
+MESSAGE_LEVEL_AGGREGATES = [
+ {'_id': 'info', 'total': 15}
+]
+
+CONSTANT_AGGREGATES_RESPONSE = {
+ "type": "constant",
+ "aggregates": {
+ "names": {
+ "type_drivers": 5,
+ "environment_monitoring_types": 1,
+ "link_states": 2
+ }
+ }
+ }
+
+ENVIRONMENT_AGGREGATES_RESPONSE = {
+ "aggregates": {
+ "object_types": {
+ "otep": 3,
+ "instance": 2,
+ "network_agent": 6
+ }
+ },
+ "env_name": "Mirantis-Liberty-API",
+ "type": "environment"
+}
+
+MESSAGE_AGGREGATES_RESPONSE = {
+ "aggregates": {
+ "environments": {
+ "Mirantis-Liberty-API": 15
+ },
+ "levels": {
+ "info": 15
+ }
+ },
+ "type": "message"
+ }
diff --git a/app/test/api/responders_test/test_data/base.py b/app/test/api/responders_test/test_data/base.py
new file mode 100644
index 0000000..1e85800
--- /dev/null
+++ b/app/test/api/responders_test/test_data/base.py
@@ -0,0 +1,179 @@
+###############################################################################
+# 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 #
+###############################################################################
+# HTTP status code
+SUCCESSFUL_CODE = "200"
+NOT_FOUND_CODE = "404"
+CONFLICT_CODE = "409"
+BAD_REQUEST_CODE = "400"
+UNAUTHORIZED_CODE = "401"
+CREATED_CODE = "201"
+
+ENV_NAME = "Mirantis-Liberty-API"
+UNKNOWN_ENV = "Unkown-Environment"
+NON_INT_PAGE = 1.4
+INT_PAGE = 1
+NON_INT_PAGESIZE = 2.4
+INT_PAGESIZE = 2
+
+WRONG_LINK_TYPE = "instance-host"
+CORRECT_LINK_TYPE= "instance-vnic"
+
+WRONG_LINK_STATE = "wrong"
+CORRECT_LINK_STATE = "up"
+
+WRONG_SCAN_STATUS = "error"
+CORRECT_SCAN_STATUS = "completed"
+
+WRONG_MONITORING_SIDE = "wrong-side"
+CORRECT_MONITORING_SIDE = "client"
+
+WRONG_MESSAGE_SEVERITY = "wrong-severity"
+CORRECT_MESSAGE_SEVERITY = "warn"
+
+WRONG_TYPE_DRIVER = "wrong_type"
+CORRECT_TYPE_DRIVER = "local"
+
+WRONG_MECHANISM_DRIVER = "wrong-mechanism-dirver"
+CORRECT_MECHANISM_DRIVER = "ovs"
+
+WRONG_LOG_LEVEL = "wrong-log-level"
+CORRECT_LOG_LEVEL = "critical"
+
+WRONG_OBJECT_TYPE = "wrong-object-type"
+CORRECT_OBJECT_TYPE = "vnic"
+
+WRONG_ENV_TYPE = ""
+CORRECT_ENV_TYPE = "development"
+
+WRONG_DISTRIBUTION = "wrong-environment"
+CORRECT_DISTRIBUTION = "Mirantis-6.0"
+
+WRONG_OBJECT_ID = "58a2406e6a283a8bee15d43"
+CORRECT_OBJECT_ID = "58a2406e6a283a8bee15d43f"
+
+WRONG_FORMAT_TIME = "2017-01-25T23:34:333+TX0012"
+CORRECT_FORMAT_TIME = "2017-01-25T14:28:32.400Z"
+
+NON_BOOL = "falses"
+BOOL = False
+NON_DICT_OBJ = ""
+
+# fake constants
+CONSTANTS_BY_NAMES = {
+ "link_types": [
+ "instance-vnic",
+ "otep-vconnector",
+ "otep-pnic",
+ "pnic-network",
+ "vedge-otep",
+ "vnic-vconnector",
+ "vconnector-pnic",
+ "vconnector-vedge",
+ "vnic-vedge",
+ "vedge-pnic",
+ "vservice-vnic"
+ ],
+ "link_states": [
+ "up",
+ "down"
+ ],
+ "scan_statuses": [
+ "draft",
+ "pending",
+ "running",
+ "completed",
+ "failed",
+ "aborted"
+ ],
+ "monitoring_sides": [
+ "client",
+ "server"
+ ],
+ "messages_severity": [
+ "panic",
+ "alert",
+ "crit",
+ "error",
+ "warn",
+ "notice",
+ "info",
+ "debug"
+ ],
+ "type_drivers": [
+ "local",
+ "vlan",
+ "vxlan",
+ "gre",
+ "flat"
+ ],
+ "mechanism_drivers": [
+ "ovs",
+ "vpp",
+ "LinuxBridge",
+ "Arista",
+ "Nexus"
+ ],
+ "log_levels": [
+ "critical",
+ "error",
+ "warning",
+ "info",
+ "debug",
+ "notset"
+ ],
+ "object_types": [
+ "vnic",
+ "vconnector",
+ "vedge",
+ "instance",
+ "vservice",
+ "pnic",
+ "network",
+ "port",
+ "otep",
+ "agent"
+ ],
+ "env_types": [
+ "development",
+ "testing",
+ "staging",
+ "production"
+ ],
+ "distributions": [
+ "Mirantis-6.0",
+ "Mirantis-7.0",
+ "Mirantis-8.0",
+ "Mirantis-9.0",
+ "RDO-Juno"
+ ],
+ "environment_operational_status": [
+ "stopped",
+ "running",
+ "error"
+ ],
+ "environment_provision_types": [
+ "None",
+ "Deploy",
+ "Files",
+ "DB"
+ ],
+ "environment_monitoring_types": [
+ "Sensu"
+ ]
+}
+
+# path info
+RESPONDER_BASE_PATH = "api.responders.responder_base.ResponderBase"
+RESPONDER_BASE_GET_OBJECTS_LIST = RESPONDER_BASE_PATH + ".get_objects_list"
+RESPONDER_BASE_GET_OBJECT_BY_ID = RESPONDER_BASE_PATH + ".get_object_by_id"
+RESPONDER_BASE_CHECK_ENVIRONMENT_NAME = RESPONDER_BASE_PATH + ".check_environment_name"
+RESPONDER_BASE_READ = RESPONDER_BASE_PATH + ".read"
+RESPONDER_BASE_WRITE = RESPONDER_BASE_PATH + ".write"
+RESPONDER_BASE_AGGREGATE = RESPONDER_BASE_PATH + ".aggregate"
diff --git a/app/test/api/responders_test/test_data/clique_constraints.py b/app/test/api/responders_test/test_data/clique_constraints.py
new file mode 100644
index 0000000..6f867ae
--- /dev/null
+++ b/app/test/api/responders_test/test_data/clique_constraints.py
@@ -0,0 +1,74 @@
+###############################################################################
+# 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
+
+URL = "/clique_constraints"
+
+WRONG_ID = base.WRONG_OBJECT_ID
+NONEXISTENT_ID = "576a4176a83d5313f21971f0"
+CORRECT_ID = base.CORRECT_OBJECT_ID
+
+WRONG_FOCAL_POINT_TYPE = base.WRONG_OBJECT_TYPE
+CORRECT_FOCAL_POINT_TYPE = base.CORRECT_OBJECT_TYPE
+
+CONSTRAINT = "network"
+
+CLIQUE_CONSTRAINTS_WITH_SPECIFIC_ID = [
+ {
+ "id": CORRECT_ID
+ }
+]
+
+CLIQUE_CONSTRAINTS_WITH_SPECIFIC_FOCAL_POINT_TYPE = [
+ {
+ "id": "576a4176a83d5313f21971f5",
+ "focal_point_type": CORRECT_FOCAL_POINT_TYPE
+ },
+ {
+ "id": "576ac7069f6ba3074882b2eb",
+ "focal_point_type": CORRECT_FOCAL_POINT_TYPE
+ }
+]
+
+CLIQUE_CONSTRAINTS_WITH_SPECIFIC_FOCAL_POINT_TYPE_RESPONSE = {
+ "clique_constraints": CLIQUE_CONSTRAINTS_WITH_SPECIFIC_FOCAL_POINT_TYPE
+}
+
+CLIQUE_CONSTRAINTS_WITH_SPECIFIC_CONSTRAINT = [
+ {
+ "id": "576a4176a83d5313f21971f5",
+ "constraints": [
+ CONSTRAINT
+ ]
+ },
+ {
+ "id": "576ac7069f6ba3074882b2eb",
+ "constraints": [
+ CONSTRAINT
+ ]
+ }
+]
+
+CLIQUE_CONSTRAINTS_WITH_SPECIFIC_CONSTRAINT_RESPONSE = {
+ "clique_constraints": CLIQUE_CONSTRAINTS_WITH_SPECIFIC_CONSTRAINT
+}
+
+CLIQUE_CONSTRAINTS = [
+ {
+ "id": "576a4176a83d5313f21971f5"
+ },
+ {
+ "id": "576ac7069f6ba3074882b2eb"
+ }
+]
+
+CLIQUE_CONSTRAINTS_RESPONSE = {
+ "clique_constraints": CLIQUE_CONSTRAINTS
+}
diff --git a/app/test/api/responders_test/test_data/clique_types.py b/app/test/api/responders_test/test_data/clique_types.py
new file mode 100644
index 0000000..0fbe839
--- /dev/null
+++ b/app/test/api/responders_test/test_data/clique_types.py
@@ -0,0 +1,170 @@
+###############################################################################
+# 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
+
+
+URL = "/clique_types"
+
+WRONG_ID = base.WRONG_OBJECT_ID
+NONEXISTENT_ID = "58ca73ae3a8a836d10ff3b44"
+CORRECT_ID = base.CORRECT_OBJECT_ID
+
+WRONG_FOCAL_POINT_TYPE = base.WRONG_OBJECT_TYPE
+CORRECT_FOCAL_POINT_POINT_TYPE = base.CORRECT_OBJECT_TYPE
+
+WRONG_LINK_TYPE = base.WRONG_LINK_TYPE
+NONEXISTENT_LINK_TYPE = "otep-pnic"
+CORRECT_LINK_TYPE = base.CORRECT_LINK_TYPE
+
+CLIQUE_TYPES_WITH_SPECIFIC_ID = [
+ {
+ "environment": "Mirantis-Liberty-API",
+ "focal_point_type": "pnic",
+ "id": CORRECT_ID
+ }
+]
+
+CLIQUE_TYPES_WITH_SPECIFIC_FOCAL_POINT_TYPE = [
+ {
+ "environment": "Mirantis-Liberty-API",
+ "focal_point_type": CORRECT_FOCAL_POINT_POINT_TYPE,
+ "id": "58ca73ae3a8a836d10ff3b80"
+ },
+ {
+ "environment": "Mirantis-Liberty-API",
+ "focal_point_type": CORRECT_FOCAL_POINT_POINT_TYPE,
+ "id": "58ca73ae3a8a836d10ff3b81"
+ }
+]
+
+CLIQUE_TYPES_WITH_SPECIFIC_FOCAL_POINT_TYPE_RESPONSE = {
+ "clique_types": CLIQUE_TYPES_WITH_SPECIFIC_FOCAL_POINT_TYPE
+}
+
+CLIQUE_TYPES_WITH_SPECIFIC_LINK_TYPE = [
+ {
+ "environment": "Mirantis-Liberty-API",
+ "link_types": [
+ CORRECT_LINK_TYPE
+ ],
+ "id": "58ca73ae3a8a836d10ff3b80"
+ },
+ {
+ "environment": "Mirantis-Liberty-API",
+ "link_types": [
+ CORRECT_LINK_TYPE
+ ],
+ "id": "58ca73ae3a8a836d10ff3b81"
+ }
+]
+
+CLIQUE_TYPES_WITH_SPECIFIC_LINK_TYPE_RESPONSE = {
+ "clique_types": CLIQUE_TYPES_WITH_SPECIFIC_LINK_TYPE
+}
+
+CLIQUE_TYPES = [
+ {
+ "environment": "Mirantis-Liberty-API",
+ "focal_point_type": "vnic",
+ "id": "58ca73ae3a8a836d10ff3b80"
+ },
+ {
+ "environment": "Mirantis-Liberty-API",
+ "focal_point_type": "vnic",
+ "id": "58ca73ae3a8a836d10ff3b81"
+ }
+]
+
+CLIQUE_TYPES_RESPONSE = {
+ "clique_types": CLIQUE_TYPES
+}
+
+NON_DICT_CLIQUE_TYPE = base.NON_DICT_OBJ
+
+CLIQUE_TYPE_WITHOUT_ENVIRONMENT = {
+ "name": "instance_vconnector_clique",
+ "link_types": [
+ "instance-vnic",
+ "vnic-vconnector"
+ ],
+ "focal_point_type": "instance"
+}
+
+CLIQUE_TYPE_WITH_UNKNOWN_ENVIRONMENT = {
+ "environment": base.UNKNOWN_ENV,
+ "id": "589a3969761b0555a3ef6093",
+ "name": "instance_vconnector_clique",
+ "link_types": [
+ "instance-vnic",
+ "vnic-vconnector"
+ ],
+ "focal_point_type": "instance"
+}
+
+CLIQUE_TYPE_WITHOUT_FOCAL_POINT_TYPE = {
+ "environment": "Mirantis-Liberty-API",
+ "name": "instance_vconnector_clique",
+ "link_types": [
+ "instance-vnic",
+ "vnic-vconnector"
+ ]
+}
+
+CLIQUE_TYPE_WITH_WRONG_FOCAL_POINT_TYPE = {
+ "environment": "Mirantis-Liberty-API",
+ "name": "instance_vconnector_clique",
+ "link_types": [
+ "instance-vnic",
+ "vnic-vconnector"
+ ],
+ "focal_point_type": WRONG_FOCAL_POINT_TYPE
+}
+
+CLIQUE_TYPE_WITHOUT_LINK_TYPES = {
+ "environment": "Mirantis-Liberty-API",
+ "name": "instance_vconnector_clique",
+ "focal_point_type": "instance"
+}
+
+CLIQUE_TYPE_WITH_NON_LIST_LINK_TYPES = {
+ "environment": "Mirantis-Liberty-API",
+ "name": "instance_vconnector_clique",
+ "link_types": "instance-vnic",
+ "focal_point_type": "instance"
+}
+
+CLIQUE_TYPE_WITH_WRONG_LINK_TYPE = {
+ "environment": "Mirantis-Liberty-API",
+ "name": "instance_vconnector_clique",
+ "link_types": [
+ WRONG_LINK_TYPE,
+ "vnic-vconnector"
+ ],
+ "focal_point_type": "instance"
+}
+
+CLIQUE_TYPE_WITHOUT_NAME = {
+ "environment": "Mirantis-Liberty-API",
+ "link_types": [
+ "instance-vnic",
+ "vnic-vconnector",
+ ],
+ "focal_point_type": "instance"
+}
+
+CLIQUE_TYPE = {
+ "environment": "Mirantis-Liberty-API",
+ "name": "instance_vconnector_clique",
+ "link_types": [
+ "instance-vnic",
+ "vnic-vconnector"
+ ],
+ "focal_point_type": "instance"
+}
diff --git a/app/test/api/responders_test/test_data/cliques.py b/app/test/api/responders_test/test_data/cliques.py
new file mode 100644
index 0000000..e1995cd
--- /dev/null
+++ b/app/test/api/responders_test/test_data/cliques.py
@@ -0,0 +1,171 @@
+###############################################################################
+# 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
+
+URL = "/cliques"
+
+WRONG_CLIQUE_ID = "58a2406e6a283a8bee15d43"
+CORRECT_CLIQUE_ID = "58a2406e6a283a8bee15d43f"
+NONEXISTENT_CLIQUE_ID = "58a2406e6a283a8bee15d43e"
+
+WRONG_FOCAL_POINT = "58a2406e6a283a8bee15d43"
+CORRECT_FOCAL_POINT = "58a2406e6a283a8bee15d43f"
+
+WRONG_LINK_ID = "58a2406e6a283a8bee15d43"
+CORRECT_LINK_ID = "58a2406e6a283a8bee15d43f"
+NONEXISTENT_LINK_ID = "58a2406e6a283a8bee15d43e"
+
+WRONG_FOCAL_POINT_TYPE = base.WRONG_OBJECT_TYPE
+CORRECT_FOCAL_POINT_TYPE = base.CORRECT_OBJECT_TYPE
+
+WRONG_LINK_TYPE = base.WRONG_LINK_TYPE
+CORRECT_LINK_TYPE = base.CORRECT_LINK_TYPE
+
+CLIQUES_WITH_SPECIFIC_ID = [
+ {
+ "environment": "Mirantis-Liberty-API",
+ "focal_point_type": "vnic",
+ "id": CORRECT_CLIQUE_ID
+ }
+]
+
+CLIQUES_WITH_SPECIFIC_FOCAL_POINT_TYPE = [
+ {
+ "environment": "Mirantis-Liberty-API",
+ "focal_point_type": CORRECT_FOCAL_POINT_TYPE,
+ "id": "576c119a3f4173144c7a75c5"
+ },
+ {
+ "environment": "Mirantis-Liberty-API",
+ "focal_point_type": CORRECT_FOCAL_POINT_TYPE,
+ "id": "576c119a3f4173144c7a75cc6"
+ }
+]
+
+CLIQUES_WITH_SPECIFIC_FOCAL_POINT_TYPE_RESPONSE = {
+ "cliques": CLIQUES_WITH_SPECIFIC_FOCAL_POINT_TYPE
+}
+
+CLIQUES_WITH_SPECIFIC_FOCAL_POINT = [
+ {
+ "environment": "Mirantis-Liberty-API",
+ "focal_point": CORRECT_FOCAL_POINT,
+ "id": "576c119a3f4173144c7a75c5"
+ },
+ {
+ "environment": "Mirantis-Liberty-API",
+ "focal_point": CORRECT_FOCAL_POINT,
+ "id": "576c119a3f4173144c7a758e"
+ }
+]
+
+CLIQUES_WITH_SPECIFIC_FOCAL_POINT_RESPONSE = {
+ "cliques": CLIQUES_WITH_SPECIFIC_FOCAL_POINT
+}
+
+CLIQUES_WITH_SPECIFIC_LINK_TYPE = [
+ {
+ "links_detailed": [
+ {
+ "link_type": CORRECT_LINK_TYPE,
+ "_id": "58a2405a6a283a8bee15d42f"
+ },
+ {
+ "link_type": "vnic-vconnector",
+ "_id": "58a240056a283a8bee15d3f2"
+ }
+ ],
+ "environment": "Mirantis-Liberty-API",
+ "focal_point_type": "vnic",
+ "id": "576c119a3f4173144c7a75c5"
+ },
+ {
+ "links_detailed": [
+ {
+ "link_type": CORRECT_LINK_TYPE,
+ "_id": "58a2405a6a283a8bee15d42f"
+ }
+ ],
+ "environment": "Mirantis-Liberty-API",
+ "focal_point_type": "pnic",
+ "id": "576c119a3f4173144c7a75c7"
+ }
+]
+
+CLIQUES_WITH_SPECIFIC_LINK_TYPE_RESPONSE = {
+ "cliques": CLIQUES_WITH_SPECIFIC_LINK_TYPE
+}
+
+CLIQUES_WITH_SPECIFIC_LINK_ID = [
+ {
+ "links_detailed": [
+ {
+ "_id": CORRECT_LINK_ID
+ },
+ {
+ "_id": "58a240056a283a8bee15d3f2"
+ }
+ ],
+ "environment": "Mirantis-Liberty-API",
+ "focal_point_type": "vnic",
+ "id": "576c119a3f4173144c7a75c5"
+ },
+ {
+ "links_detailed": [
+ {
+ "_id": CORRECT_LINK_ID
+ }
+ ],
+ "environment": "Mirantis-Liberty-API",
+ "focal_point_type": "pnic",
+ "id": "576c119a3f4173144c7a75c7"
+ }
+]
+
+CLIQUES_WITH_SPECIFIC_LINK_ID_RESPONSE = {
+ "cliques": CLIQUES_WITH_SPECIFIC_LINK_ID
+}
+
+# response
+CLIQUES = [{
+ "links_detailed": [
+ {
+ "link_type": "instance-vnic",
+ "_id": "58a2405a6a283a8bee15d42f"
+ },
+ {
+ "link_type": "vnic-vconnector",
+ "_id": "58a240056a283a8bee15d3f2"
+ }
+ ],
+ "environment": "Mirantis-Liberty-API",
+ "focal_point_type": "vnic",
+ "id": "576c119a3f4173144c7a75c5"
+ },
+ {
+ "links_detailed": [
+ {
+ "link_type": "instance-vnic",
+ "_id": "58a2405a6a283a8bee15d42f"
+ },
+ {
+ "link_type": "vnic-vconnector",
+ "_id": "58a240056a283a8bee15d3f2"
+ }
+ ],
+ "environment": "Miratis-Liberty-API",
+ "focal_point_type": "pnic",
+ "id": "576c119a3f4173144c7a75c6"
+ }
+]
+
+CLIQUES_RESPONSE = {
+ "cliques": CLIQUES
+}
diff --git a/app/test/api/responders_test/test_data/constants.py b/app/test/api/responders_test/test_data/constants.py
new file mode 100644
index 0000000..9293209
--- /dev/null
+++ b/app/test/api/responders_test/test_data/constants.py
@@ -0,0 +1,23 @@
+###############################################################################
+# 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 #
+###############################################################################
+URL = "/constants"
+UNKNOWN_NAME = "unknown constant"
+NAME = "distributions"
+CONSTANTS_WITH_SPECIFIC_NAME = [{
+ "id": "YmPDAQAchr39KjECQ",
+ "name": NAME,
+ "data": [{
+ "value": "Canonical-icehouse",
+ "label": "Canonical-icehouse"
+ }, {
+ "value": "Canonical-juno",
+ "label": "Canonical-juno"
+ }],
+}]
diff --git a/app/test/api/responders_test/test_data/environment_configs.py b/app/test/api/responders_test/test_data/environment_configs.py
new file mode 100644
index 0000000..2a67fb6
--- /dev/null
+++ b/app/test/api/responders_test/test_data/environment_configs.py
@@ -0,0 +1,221 @@
+###############################################################################
+# 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
+
+
+URL = "/environment_configs"
+
+NAME = "Mirantis-Liberty-API"
+UNKNOWN_NAME = "UNKNOWN NAME"
+WRONG_DISTRIBUTION = base.WRONG_DISTRIBUTION
+CORRECT_DISTRIBUTION = base.CORRECT_DISTRIBUTION
+WRONG_MECHANISM_DRIVER = base.WRONG_MECHANISM_DRIVER
+CORRECT_MECHANISM_DRIVER = base.CORRECT_MECHANISM_DRIVER
+WRONG_TYPE_DRIVER = base.WRONG_TYPE_DRIVER
+CORRECT_TYPE_DRIVER = base.CORRECT_TYPE_DRIVER
+USER = "WS7j8oTbWPf3LbNne"
+NON_BOOL_LISTEN = NON_BOOL_SCANNED = \
+ NON_BOOL_MONITORING_SETUP_DONE = base.NON_BOOL
+
+BOOL_LISTEN = BOOL_SCANNED = \
+ BOOL_MONITORING_SETUP_DONE = base.BOOL
+
+ENV_CONFIGS = [
+ {
+ "distribution": "Mirantis-8.0",
+ "name": "Mirantis-Liberty-API"
+ },
+ {
+ "distribution": "Mirantis-9.0",
+ "name": "Mirantis-Liberty"
+ }
+]
+
+ENV_CONFIGS_RESPONSE = {
+ "environment_configs": ENV_CONFIGS
+}
+
+ENV_CONFIGS_WITH_SPECIFIC_NAME = [
+ {
+ "distribution": "Mirantis-8.0",
+ "name": NAME
+ }
+]
+
+ENV_CONFIGS_WITH_SPECIFIC_DISTRIBUTION = [
+ {
+ "distribution": CORRECT_DISTRIBUTION,
+ "name": "Mirantis-Liberty-API",
+ },
+ {
+ "distribution": CORRECT_DISTRIBUTION,
+ "name": "Mirantis-Liberty"
+ }
+]
+
+ENV_CONFIGS_WITH_SPECIFIC_DISTRIBUTION_RESPONSE = {
+ "environment_configs": ENV_CONFIGS_WITH_SPECIFIC_DISTRIBUTION
+}
+
+ENV_CONFIGS_WITH_SPECIFIC_MECHANISM_DRIVER = [
+ {
+ "name": "Mirantis-Liberty-API",
+ "mechanism_drivers": [
+ CORRECT_MECHANISM_DRIVER
+ ]
+ },
+ {
+ "name": "Mirantis-Liberty",
+ "mechanism_drivers": [
+ CORRECT_MECHANISM_DRIVER
+ ]
+ }
+]
+
+ENV_CONFIGS_WITH_SPECIFIC_MECHANISM_DRIVER_RESPONSE = {
+ "environment_configs": ENV_CONFIGS_WITH_SPECIFIC_MECHANISM_DRIVER
+}
+
+ENV_CONFIGS_WITH_SPECIFIC_TYPE_DRIVER = [
+ {
+ "type_drivers": CORRECT_TYPE_DRIVER,
+ "name": "Mirantis-Liberty-API",
+ },
+ {
+ "type_drivers": CORRECT_TYPE_DRIVER,
+ "name": "Mirantis-Liberty"
+ }
+]
+
+ENV_CONFIGS_WITH_SPECIFIC_TYPE_DRIVER_RESPONSE = {
+ 'environment_configs': ENV_CONFIGS_WITH_SPECIFIC_TYPE_DRIVER
+}
+
+ENV_CONFIGS_WITH_SPECIFIC_USER = [
+ {
+ "user": USER,
+ "name": "Mirantis-Liberty-API",
+ },
+ {
+ "user": USER,
+ "name": "Mirantis-Liberty"
+ }
+]
+
+ENV_CONFIGS_WITH_SPECIFIC_USER_RESPONSE = {
+ "environment_configs": ENV_CONFIGS_WITH_SPECIFIC_USER
+}
+
+ENV_CONFIGS_WITH_SPECIFIC_LISTEN = [
+ {
+ "listen": BOOL_LISTEN,
+ "name": "Mirantis-Liberty-API",
+ },
+ {
+ "listen": BOOL_LISTEN,
+ "name": "Mirantis-Liberty"
+ }
+]
+
+ENV_CONFIGS_WITH_SPECIFIC_LISTEN_RESPONSE = {
+ "environment_configs": ENV_CONFIGS_WITH_SPECIFIC_LISTEN
+}
+
+ENV_CONFIGS_WITH_SPECIFIC_SCANNED = [
+ {
+ "scanned": BOOL_SCANNED,
+ "name": "Mirantis-Liberty-API",
+ },
+ {
+ "scanned": BOOL_SCANNED,
+ "name": "Mirantis-Liberty"
+ }
+]
+
+ENV_CONFIGS_WITH_SPECIFIC_SCANNED_RESPONSE = {
+ "environment_configs": ENV_CONFIGS_WITH_SPECIFIC_SCANNED
+}
+
+ENV_CONFIGS_WITH_SPECIFIC_MONITORING_SETUP_DONE = [
+ {
+ "monitoring_setup_done": BOOL_MONITORING_SETUP_DONE,
+ "name": "Mirantis-Liberty-API",
+ },
+ {
+ "monitoring_setup_done": BOOL_MONITORING_SETUP_DONE,
+ "name": "Mirantis-Liberty"
+ }
+]
+
+ENV_CONFIGS_WITH_SPECIFIC_MONITORING_SETUP_DONE_RESPONSE = {
+ "environment_configs": ENV_CONFIGS_WITH_SPECIFIC_MONITORING_SETUP_DONE
+}
+
+ENV_CONFIG = {
+ "app_path": "/home/korenlev/Calipso/app/",
+ "configuration": [
+ {
+ "host": "10.56.20.239",
+ "name": "mysql",
+ "password": "G1VKEbcqKZXoPthrtNma2D9Y",
+ "port": "3307",
+ "user": "root"
+ },
+ {
+ "name": "OpenStack",
+ "host": "10.56.20.239",
+ "admin_token": "wLWefGuD0uYJ7tqkeEScdnNo",
+ "port": "5000",
+ "user": "admin",
+ "pwd": "admin"
+ },
+ {
+ "host": "10.56.20.239",
+ "key": "/etc/calipso/keys/Mirantis-Liberty-id_rsa",
+ "name": "CLI",
+ "user": "root"
+ },
+ {
+ "host": "10.56.20.239",
+ "name": "AMQP",
+ "password": "YVWMiKMshZhlJCGqFu5PdT9d",
+ "port": "5673",
+ "user": "nova"
+ },
+ {
+ "config_folder": "/tmp/sensu_test",
+ "provision": "None",
+ "env_type": "development",
+ "name": "Monitoring",
+ "api_port": "4567",
+ "rabbitmq_port": "5671",
+ "rabbitmq_pass": "sensuaccess",
+ "rabbitmq_user": "sensu",
+ "ssh_port": "20022",
+ "ssh_user": "root",
+ "ssh_password": "calipso",
+ "server_ip": "korlev-calipso-staging1.cisco.com",
+ "server_name": "calipso-sensu",
+ "type": "Sensu"
+ }
+ ],
+ "distribution": "Mirantis-8.0",
+ "last_scanned": "2017-03-16T11:14:54Z",
+ "listen": True,
+ "mechanism_drivers": [
+ "ovs"
+ ],
+ "name": "Mirantis-Liberty",
+ "operational": "running",
+ "scanned": True,
+ "type": "environment",
+ "type_drivers": "vxlan",
+ "user": "WS7j8oTbWPf3LbNne"
+}
diff --git a/app/test/api/responders_test/test_data/inventory.py b/app/test/api/responders_test/test_data/inventory.py
new file mode 100644
index 0000000..47d611d
--- /dev/null
+++ b/app/test/api/responders_test/test_data/inventory.py
@@ -0,0 +1,37 @@
+###############################################################################
+# 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 #
+###############################################################################
+URL = "/inventory"
+
+ID = "RegionOne-aggregates"
+NONEXISTENT_ID = "Unkown-Id"
+
+
+OBJECTS_LIST = [
+ {
+ "id": "Mirantis-Liberty-regions",
+ "name": "Regions",
+ "name_path": "/Mirantis-Liberty-API/Regions"
+ },
+ {
+ "id": "Mirantis-Liberty-projects",
+ "name": "Projects",
+ "name_path": "/Mirantis-Liberty-API/Projects"
+ }
+]
+
+OBJECT_IDS_RESPONSE = {
+ "objects": OBJECTS_LIST
+}
+
+
+OBJECTS = [{
+ "environment": "Mirantis-Liberty-API",
+ "id": "RegionOne-aggregates"
+}]
diff --git a/app/test/api/responders_test/test_data/links.py b/app/test/api/responders_test/test_data/links.py
new file mode 100644
index 0000000..e71c02d
--- /dev/null
+++ b/app/test/api/responders_test/test_data/links.py
@@ -0,0 +1,90 @@
+###############################################################################
+# 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
+
+
+URL = "/links"
+
+UNKNOWN_HOST = "unknown host"
+
+WRONG_TYPE = base.WRONG_LINK_TYPE
+CORRECT_TYPE = base.CORRECT_LINK_TYPE
+
+WRONG_STATE = base.WRONG_LINK_STATE
+CORRECT_STATE = base.CORRECT_LINK_STATE
+
+LINK_ID = "58ca73ae3a8a836d10ff3b45"
+WRONG_LINK_ID = "58ca73ae3a8a836d10ff3b4"
+NONEXISTENT_LINK_ID = "58ca73ae3a8a836d10ff3b46"
+
+LINKS_WITH_SPECIFIC_TYPE = [
+ {
+ "id": "58ca73ae3a8a836d10ff3bb5",
+ "host": "node-1.cisco.com",
+ "link_type": CORRECT_TYPE,
+ "link_name": "Segment-103",
+ "environment": "Mirantis-Liberty-API"
+ },
+ {
+ "id": "58ca73ae3a8a836d10ff3b4d",
+ "host": "node-1.cisco.com",
+ "link_type": CORRECT_TYPE,
+ "link_name": "Segment-104",
+ "environment": "Mirantis-Liberty-API"
+ }
+]
+
+
+LINKS_WITH_SPECIFIC_STATE = [
+ {
+ "id": "58ca73ae3a8a836d10ff3bb5",
+ "host": "node-1.cisco.com",
+ "state": CORRECT_STATE,
+ "environment": "Mirantis-Liberty-API"
+ },
+ {
+ "id": "58ca73ae3a8a836d10ff3b4d",
+ "host": "node-1.cisco.com",
+ "state": CORRECT_STATE,
+ "environment": "Mirantis-Liberty-API"
+ }
+]
+
+LINKS_WITH_SPECIFIC_STATE_RESPONSE = {
+ "links": LINKS_WITH_SPECIFIC_STATE
+}
+
+LINKS_WITH_SPECIFIC_TYPE_RESPONSE = {
+ "links": LINKS_WITH_SPECIFIC_TYPE
+}
+
+LINKS_WITH_SPECIFIC_ID = [
+ {
+ "id": LINK_ID,
+ "host": "node-1.cisco.com",
+ "link_type": "pnic-network",
+ "link_name": "Segment-103",
+ "environment": "Mirantis-Liberty-API"
+ }
+]
+
+LINKS = [
+ {
+ "id": "58ca73ae3a8a836d10ff3b45",
+ "host": "node-1.cisco.com",
+ "link_type": "pnic-network",
+ "link_name": "Segment-103",
+ "environment": "Mirantis-Liberty-API"
+ }
+]
+
+LINKS_LIST_RESPONSE = {
+ "links": LINKS
+}
diff --git a/app/test/api/responders_test/test_data/messages.py b/app/test/api/responders_test/test_data/messages.py
new file mode 100644
index 0000000..b7b5abd
--- /dev/null
+++ b/app/test/api/responders_test/test_data/messages.py
@@ -0,0 +1,108 @@
+###############################################################################
+# 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
+
+# url
+URL = "/messages"
+
+NONEXISTENT_MESSAGE_ID = "80b5e074-0f1a-4b67-810c-fa9c92d41a9f"
+MESSAGE_ID = "80b5e074-0f1a-4b67-810c-fa9c92d41a98"
+
+WRONG_SEVERITY = base.WRONG_MESSAGE_SEVERITY
+CORRECT_SEVERITY = base.CORRECT_MESSAGE_SEVERITY
+
+WRONG_RELATED_OBJECT_TYPE = base.WRONG_OBJECT_TYPE
+CORRECT_RELATED_OBJECT_TYPE = base.CORRECT_OBJECT_TYPE
+
+RELATED_OBJECT = "instance"
+NONEXISTENT_RELATED_OBJECT = "nonexistent-instance"
+
+WRONG_FORMAT_TIME = base.WRONG_FORMAT_TIME
+CORRECT_FORMAT_TIME = base.CORRECT_FORMAT_TIME
+
+MESSAGES_WITH_SPECIFIC_TIME = [
+ {
+ "level": "info",
+ "environment": "Mirantis-Liberty-API",
+ "id": "3c64fe31-ca3b-49a3-b5d3-c485d7a452e7",
+ "source_system": "OpenStack",
+ "timestamp": CORRECT_FORMAT_TIME
+ }
+]
+
+MESSAGES_WITH_SPECIFIC_TIME_RESPONSE = {
+ "messages": MESSAGES_WITH_SPECIFIC_TIME
+}
+
+MESSAGES_WITH_SPECIFIC_SEVERITY = [
+ {
+ "level": CORRECT_SEVERITY,
+ "environment": "Mirantis-Liberty-API",
+ "id": "3c64fe31-ca3b-49a3-b5d3-c485d7a452e7",
+ "source_system": "OpenStack"
+ },
+ {
+ "level": CORRECT_SEVERITY,
+ "environment": "Mirantis-Liberty-API",
+ "id": "c7071ec0-04db-4820-92ff-3ed2b916738f",
+ "source_system": "OpenStack"
+ },
+]
+
+MESSAGES_WITH_SPECIFIC_SEVERITY_RESPONSE = {
+ "messages": MESSAGES_WITH_SPECIFIC_SEVERITY
+}
+
+MESSAGES_WITH_SPECIFIC_RELATED_OBJECT_TYPE = [
+ {
+ "level": "info",
+ "environment": "Mirantis-Liberty-API",
+ "related_object_type": CORRECT_RELATED_OBJECT_TYPE,
+ "id": "3c64fe31-ca3b-49a3-b5d3-c485d7a452e7"
+ },
+ {
+ "level": "error",
+ "environment": "Mirantis-Liberty-API",
+ "related_object_type": CORRECT_RELATED_OBJECT_TYPE,
+ "id": "c7071ec0-04db-4820-92ff-3ed2b916738f"
+ },
+]
+
+MESSAGES_WITH_SPECIFIC_RELATED_OBJECT_TYPE_RESPONSE = {
+ "messages": MESSAGES_WITH_SPECIFIC_RELATED_OBJECT_TYPE
+}
+
+MESSAGES_WITH_SPECIFIC_ID = [
+ {
+ "level": "info",
+ "environment": "Mirantis-Liberty",
+ "id": MESSAGE_ID,
+ "source_system": "OpenStack"
+ }
+]
+
+MESSAGES = [
+ {
+ "level": "info",
+ "environment": "Mirantis-Liberty",
+ "id": "3c64fe31-ca3b-49a3-b5d3-c485d7a452e7",
+ "source_system": "OpenStack"
+ },
+ {
+ "level": "info",
+ "environment": "Mirantis-Liberty",
+ "id": "c7071ec0-04db-4820-92ff-3ed2b916738f",
+ "source_system": "OpenStack"
+ },
+]
+
+MESSAGES_RESPONSE = {
+ "messages": MESSAGES
+}
diff --git a/app/test/api/responders_test/test_data/monitoring_config_templates.py b/app/test/api/responders_test/test_data/monitoring_config_templates.py
new file mode 100644
index 0000000..0f387a4
--- /dev/null
+++ b/app/test/api/responders_test/test_data/monitoring_config_templates.py
@@ -0,0 +1,98 @@
+###############################################################################
+# 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
+
+
+URL = "/monitoring_config_templates"
+
+WRONG_ID = base.WRONG_OBJECT_ID
+UNKNOWN_ID = "583711893e149c14785d6da5"
+CORRECT_ID = base.CORRECT_OBJECT_ID
+
+NON_INT_ORDER = 1.3
+INT_ORDER = 1
+
+WRONG_SIDE = base.WRONG_MONITORING_SIDE
+CORRECT_SIDE = base.CORRECT_MONITORING_SIDE
+
+TYPE = "client.json"
+
+TEMPLATES_WITH_SPECIFIC_ORDER = [
+ {
+ "order": INT_ORDER,
+ "id": "583711893e149c14785d6daa"
+ },
+ {
+ "order": INT_ORDER,
+ "id": "583711893e149c14785d6da7"
+ }
+]
+
+TEMPLATES_WITH_SPECIFIC_ORDER_RESPONSE = {
+ "monitoring_config_templates":
+ TEMPLATES_WITH_SPECIFIC_ORDER
+}
+
+TEMPLATES_WITH_SPECIFIC_SIDE = [
+ {
+ "side": CORRECT_SIDE,
+ "id": "583711893e149c14785d6daa"
+ },
+ {
+ "side": CORRECT_SIDE,
+ "id": "583711893e149c14785d6da7"
+ }
+]
+
+TEMPLATES_WITH_SPECIFIC_SIDE_RESPONSE = {
+ "monitoring_config_templates":
+ TEMPLATES_WITH_SPECIFIC_SIDE
+}
+
+TEMPLATES_WITH_SPECIFIC_TYPE = [
+ {
+ "type": TYPE,
+ "id": "583711893e149c14785d6daa"
+ },
+ {
+ "type": TYPE,
+ "id": "583711893e149c14785d6da7"
+ }
+]
+
+TEMPLATES_WITH_SPECIFIC_TYPE_RESPONSE = {
+ "monitoring_config_templates":
+ TEMPLATES_WITH_SPECIFIC_TYPE
+}
+
+TEMPLATES_WITH_SPECIFIC_ID = [
+ {
+ "type": "rabbitmq.json",
+ "side": "client",
+ "id": CORRECT_ID
+ }
+]
+
+TEMPLATES = [
+ {
+ "type": "rabbitmq.json",
+ "side": "client",
+ "id": "583711893e149c14785d6daa"
+ },
+ {
+ "type": "rabbitmq.json",
+ "side": "client",
+ "id": "583711893e149c14785d6da7"
+ }
+]
+
+TEMPLATES_RESPONSE = {
+ "monitoring_config_templates": TEMPLATES
+}
diff --git a/app/test/api/responders_test/test_data/scans.py b/app/test/api/responders_test/test_data/scans.py
new file mode 100644
index 0000000..479d371
--- /dev/null
+++ b/app/test/api/responders_test/test_data/scans.py
@@ -0,0 +1,187 @@
+###############################################################################
+# 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
+
+URL = "/scans"
+
+WRONG_ID = base.WRONG_OBJECT_ID
+NONEXISTENT_ID = "58c96a075eb66a121cc4e750"
+CORRECT_ID = base.CORRECT_OBJECT_ID
+
+BASE_OBJECT = "node-2.cisco.com"
+
+WRONG_STATUS = base.WRONG_SCAN_STATUS
+CORRECT_STATUS = base.CORRECT_SCAN_STATUS
+
+SCANS = [
+ {
+ "status": "pending",
+ "environment": "Mirantis-Liberty-API",
+ "id": "58c96a075eb66a121cc4e75f",
+ },
+ {
+ "status": "completed",
+ "environment": "Mirantis-Liberty-API",
+ "id": "58c96a075eb66a121cc4e75e",
+ "scan_completed": True
+ }
+]
+
+SCANS_RESPONSE = {
+ "scans": SCANS
+}
+
+SCANS_WITH_SPECIFIC_ID = [
+ {
+ "status": "pending",
+ "environment": "Mirantis-Liberty-API",
+ "id": CORRECT_ID,
+ }
+]
+
+SCANS_WITH_SPECIFIC_BASE_OBJ = [
+ {
+ "status": "pending",
+ "environment": "Mirantis-Liberty-API",
+ "id": "58c96a075eb66a121cc4e75f",
+ "object_id": BASE_OBJECT
+ },
+ {
+ "status": "completed",
+ "environment": "Mirantis-Liberty-API",
+ "id": "58c96a075eb66a121cc4e75e",
+ "object_id": BASE_OBJECT,
+ "scan_completed": True
+ }
+]
+
+SCANS_WITH_SPECIFIC_BASE_OBJ_RESPONSE = {
+ "scans": SCANS_WITH_SPECIFIC_BASE_OBJ
+}
+
+SCANS_WITH_SPECIFIC_STATUS = [
+ {
+ "status": CORRECT_STATUS,
+ "environment": "Mirantis-Liberty-API",
+ "id": "58c96a075eb66a121cc4e75f",
+ "scan_completed": True
+ },
+ {
+ "status": CORRECT_STATUS,
+ "environment": "Mirantis-Liberty-API",
+ "id": "58c96a075eb66a121cc4e75e",
+ "scan_completed": True
+ }
+]
+
+SCANS_WITH_SPECIFIC_STATUS_RESPONSE = {
+ "scans": SCANS_WITH_SPECIFIC_STATUS
+}
+
+NON_DICT_SCAN = base.NON_DICT_OBJ
+
+SCAN = {
+ "status": "pending",
+ "log_level": "warning",
+ "clear": True,
+ "scan_only_inventory": True,
+ "environment": "Mirantis-Liberty-API",
+ "inventory": "inventory",
+ "object_id": "ff"
+}
+
+SCAN_WITHOUT_ENV = {
+ "status": "pending",
+ "log_level": "warning",
+ "clear": True,
+ "scan_only_inventory": True,
+ "inventory": "inventory",
+ "object_id": "ff"
+}
+
+SCAN_WITH_UNKNOWN_ENV = {
+ "status": "pending",
+ "log_level": "warning",
+ "clear": True,
+ "scan_only_inventory": True,
+ "environment": base.UNKNOWN_ENV,
+ "inventory": "inventory",
+ "object_id": "ff"
+}
+
+SCAN_WITHOUT_STATUS = {
+ "log_level": "warning",
+ "clear": True,
+ "scan_only_inventory": True,
+ "environment": "Mirantis-Liberty-API",
+ "inventory": "inventory",
+ "object_id": "ff"
+}
+
+SCAN_WITH_WRONG_STATUS = {
+ "status": WRONG_STATUS,
+ "log_level": "warning",
+ "clear": True,
+ "scan_only_inventory": True,
+ "environment": "Mirantis-Liberty-API",
+ "inventory": "inventory",
+ "object_id": "ff"
+}
+
+SCAN_WITH_WRONG_LOG_LEVEL = {
+ "status": "pending",
+ "log_level": base.WRONG_LOG_LEVEL,
+ "clear": True,
+ "scan_only_inventory": True,
+ "environment": "Mirantis-Liberty-API",
+ "inventory": "inventory",
+ "object_id": "ff"
+}
+
+SCAN_WITH_NON_BOOL_CLEAR = {
+ "status": "pending",
+ "log_level": "warning",
+ "clear": base.NON_BOOL,
+ "scan_only_inventory": True,
+ "environment": "Mirantis-Liberty-API",
+ "inventory": "inventory",
+ "object_id": "ff"
+}
+
+
+SCAN_WITH_NON_BOOL_SCAN_ONLY_INVENTORY = {
+ "status": "pending",
+ "log_level": "warning",
+ "clear": True,
+ "scan_only_inventory": base.NON_BOOL,
+ "environment": "Mirantis-Liberty-API",
+ "inventory": "inventory",
+ "object_id": "ff"
+}
+
+SCAN_WITH_NON_BOOL_SCAN_ONLY_LINKS = {
+ "status": "pending",
+ "log_level": "warning",
+ "clear": True,
+ "scan_only_links": base.NON_BOOL,
+ "environment": "Mirantis-Liberty-API",
+ "inventory": "inventory",
+ "object_id": "ff"
+}
+
+SCAN_WITH_NON_BOOL_SCAN_ONLY_CLIQUES = {
+ "status": "pending",
+ "log_level": "warning",
+ "clear": True,
+ "scan_only_cliques": base.NON_BOOL,
+ "environment": "Mirantis-Liberty-API",
+ "inventory": "inventory",
+ "object_id": "ff"
+}
diff --git a/app/test/api/responders_test/test_data/scheduled_scans.py b/app/test/api/responders_test/test_data/scheduled_scans.py
new file mode 100644
index 0000000..1019572
--- /dev/null
+++ b/app/test/api/responders_test/test_data/scheduled_scans.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.responders_test.test_data import base
+
+URL = "/scheduled_scans"
+WRONG_FREQ = "wrong_freq"
+CORRECT_FREQ = "WEEKLY"
+WRONG_ID = base.WRONG_OBJECT_ID
+NONEXISTENT_ID = "58c96a075eb66a121cc4e750"
+CORRECT_ID = "ff4d3e80e42e886bef13a084"
+NON_DICT_SCHEDULED_SCAN = ""
+
+
+SCHEDULED_SCANS = [
+ {
+ "id": "ff4d3e80e42e886bef13a084",
+ "environment": base.ENV_NAME,
+ "scheduled_timestamp": "2017-07-24T12:45:03.784+0000",
+ "freq": "WEEKLY"
+ },
+ {
+ "id": "58e4e1aa6df71e971324ea62",
+ "environment": base.ENV_NAME,
+ "scheduled_timestamp": "2017-07-24T12:45:03.784+0000",
+ "freq": "WEEKLY"
+ }
+]
+
+SCHEDULED_SCANS_RESPONSE = {
+ "scheduled_scans": SCHEDULED_SCANS
+}
+
+SCHEDULED_SCAN_WITH_SPECIFIC_FREQ = [{
+ "id": "ff4d3e80e42e886bef13a084",
+ "environment": base.ENV_NAME,
+ "scheduled_timestamp": "2017-07-24T12:45:03.784+0000",
+ "freq": CORRECT_FREQ
+}]
+
+SCHEDULED_SCAN_WITH_SPECIFIC_FREQ_RESPONSE = {
+ "scheduled_scans": SCHEDULED_SCAN_WITH_SPECIFIC_FREQ
+}
+
+SCHEDULED_SCAN_WITH_SPECIFIC_ID = [{
+ "id": CORRECT_ID,
+ "environment": base.ENV_NAME,
+ "scheduled_timestamp": "2017-07-24T12:45:03.784+0000",
+ "freq": CORRECT_FREQ
+}]
+
+SCHEDULED_SCAN = {
+ "environment": base.ENV_NAME,
+ "freq": CORRECT_FREQ,
+ "submit_timestamp": "2017-07-24T12:45:03.784+0000"
+}
+
+SCHEDULED_SCAN_WITHOUT_ENV = {
+ "freq": CORRECT_FREQ,
+ "submit_timestamp": "2017-07-24T12:45:03.784+0000"
+}
+
+SCHEDULED_SCAN_WITH_UNKNOWN_ENV = {
+ "environment": base.UNKNOWN_ENV,
+ "freq": CORRECT_FREQ,
+ "submit_timestamp": "2017-07-24T12:45:03.784+0000"
+}
+
+SCHEDULED_SCAN_WITHOUT_FREQ = {
+ "environment": base.ENV_NAME,
+ "submit_timestamp": "2017-07-24T12:45:03.784+0000"
+}
+
+SCHEDULED_SCAN_WITHOUT_SUBMIT_TIMESTAMP = {
+ "environment": base.ENV_NAME,
+ "freq": CORRECT_FREQ,
+}
+
+SCHEDULED_SCAN_WITH_WRONG_FREQ = {
+ "environment": base.ENV_NAME,
+ "freq": WRONG_FREQ,
+ "submit_timestamp": "2017-07-24T12:45:03.784+0000"
+}
+
+SCHEDULED_SCAN_WITH_WRONG_LOG_LEVEL = {
+ "environment": base.ENV_NAME,
+ "freq": CORRECT_FREQ,
+ "log_level": base.WRONG_LOG_LEVEL,
+ "submit_timestamp": "2017-07-24T12:45:03.784+0000"
+}
+
+SCHEDULED_SCAN_WITH_WRONG_SUBMIT_TIMESTAMP = {
+ "environment": base.ENV_NAME,
+ "freq": CORRECT_FREQ,
+ "submit_timestamp": base.WRONG_FORMAT_TIME
+}
+
+SCHEDULED_SCAN_WITH_NON_BOOL_CLEAR = {
+ "environment": base.ENV_NAME,
+ "freq": CORRECT_FREQ,
+ "submit_timestamp": "2017-07-24T12:45:03.784+0000",
+ "clear": base.NON_BOOL
+}
+
+SCHEDULED_SCAN_WITH_NON_BOOL_SCAN_ONLY_LINKS = {
+ "environment": base.ENV_NAME,
+ "freq": CORRECT_FREQ,
+ "submit_timestamp": "2017-07-24T12:45:03.784+0000",
+ "scan_only_links": base.NON_BOOL
+}
+
+SCHEDULED_SCAN_WITH_NON_BOOL_SCAN_ONLY_CLIQUES = {
+ "environment": base.ENV_NAME,
+ "freq": CORRECT_FREQ,
+ "submit_timestamp": "2017-07-24T12:45:03.784+0000",
+ "scan_only_cliques": base.NON_BOOL
+}
+
+SCHEDULED_SCAN_WITH_NON_BOOL_SCAN_ONLY_INVENTORY = {
+ "environment": base.ENV_NAME,
+ "freq": CORRECT_FREQ,
+ "submit_timestamp": "2017-07-24T12:45:03.784+0000",
+ "scan_only_inventory": base.NON_BOOL
+}
+
+SCHEDULED_SCAN_WITH_EXTRA_SCAN_ONLY_FLAGS = {
+ "environment": base.ENV_NAME,
+ "freq": CORRECT_FREQ,
+ "submit_timestamp": "2017-07-24T12:45:03.784+0000",
+ "scan_only_links": True,
+ "scan_only_inventory": True
+}
diff --git a/app/test/api/responders_test/test_data/tokens.py b/app/test/api/responders_test/test_data/tokens.py
new file mode 100644
index 0000000..8d9960d
--- /dev/null
+++ b/app/test/api/responders_test/test_data/tokens.py
@@ -0,0 +1,83 @@
+###############################################################################
+# 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 #
+###############################################################################
+URL = '/auth/tokens'
+
+AUTH_OBJ_WITHOUT_AUTH = {
+
+}
+
+AUTH_OBJ_WITHOUT_METHODS = {
+ 'auth': {}
+}
+
+AUTH_OBJ_WITHOUT_CREDENTIALS = {
+ 'auth': {
+ 'methods': ['credentials']
+ }
+}
+
+AUTH_OBJ_WITHOUT_TOKEN = {
+ 'auth': {
+ 'methods': ['token']
+ }
+}
+
+AUTH_OBJ_WITH_WRONG_CREDENTIALS = {
+ 'auth': {
+ 'methods': ['credentials'],
+ 'credentials': {
+ 'username': 'wrong_user',
+ 'password': 'password'
+ }
+ }
+}
+
+AUTH_OBJ_WITH_WRONG_TOKEN = {
+ 'auth': {
+ 'methods': ['token'],
+ 'token': 'wrong_token'
+ }
+}
+
+AUTH_OBJ_WITH_CORRECT_CREDENTIALS = {
+ 'auth': {
+ 'methods': ['credentials'],
+ 'credentials': {
+ 'username': 'wrong_user',
+ 'password': 'password'
+ }
+ }
+}
+
+AUTH_OBJ_WITH_CORRECT_TOKEN = {
+ 'auth': {
+ 'methods': ['token'],
+ 'token': '17dfa88789aa47f6bb8501865d905f13'
+ }
+}
+
+HEADER_WITHOUT_TOKEN = {
+
+}
+
+HEADER_WITH_WRONG_TOKEN = {
+ 'X-Auth-Token': 'wrong token'
+}
+
+HEADER_WITH_CORRECT_TOKEN = {
+ 'X-Auth-Token': '17dfa88789aa47f6bb8501865d905f13'
+}
+
+AUTH_BASE_PATH = 'api.auth.auth.Auth'
+AUTH_GET_TOKEN = AUTH_BASE_PATH + '.get_token'
+AUTH_WRITE_TOKEN = AUTH_BASE_PATH + '.write_token'
+AUTH_DELETE_TOKEN = AUTH_BASE_PATH + '.delete_token'
+AUTH_VALIDATE_CREDENTIALS = AUTH_BASE_PATH + '.validate_credentials'
+AUTH_VALIDATE_TOKEN = AUTH_BASE_PATH + '.validate_token'
diff --git a/app/test/api/test_base.py b/app/test/api/test_base.py
new file mode 100644
index 0000000..c126b2b
--- /dev/null
+++ b/app/test/api/test_base.py
@@ -0,0 +1,101 @@
+###############################################################################
+# 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 copy
+
+
+from api.app import App
+from api.middleware.authentication import AuthenticationMiddleware
+from api.responders.responder_base import ResponderBase
+from api.backends.ldap_access import LDAPAccess
+from falcon.testing import TestCase
+from test.api.responders_test.test_data import base
+from unittest.mock import MagicMock
+from utils.mongo_access import MongoAccess
+
+
+def mock_auth_method(*args):
+ return None
+
+
+class TestBase(TestCase):
+
+ def setUp(self, authenticate=False):
+ super().setUp()
+ # mock
+ self.authenticate = authenticate
+ if not authenticate:
+ self.original_auth_method = AuthenticationMiddleware.process_request
+ AuthenticationMiddleware.process_request = mock_auth_method
+
+ ResponderBase.get_constants_by_name = MagicMock(side_effect=
+ lambda name: base.CONSTANTS_BY_NAMES[name])
+ # mock mongo access
+ MongoAccess.mongo_connect = MagicMock()
+ MongoAccess.db = MagicMock()
+ MongoAccess.client = MagicMock()
+ # mock ldap access
+ LDAPAccess.get_ldap_params = MagicMock()
+ LDAPAccess.connect_ldap_server = MagicMock()
+
+ log_level = 'debug'
+ self.app = App(log_level=log_level).get_app()
+
+ def validate_get_request(self, url, params={}, headers=None, mocks={},
+ side_effects={},
+ expected_code=base.SUCCESSFUL_CODE,
+ expected_response=None):
+ self.validate_request("GET", url, params, headers, "",
+ mocks, side_effects,
+ expected_code,
+ expected_response)
+
+ def validate_request(self, action, url, params, headers, body,
+ mocks, side_effects, expected_code,
+ expected_response):
+ for mock_method, mock_data in mocks.items():
+ mock_method.return_value = mock_data
+
+ for mock_method, side_effect in side_effects.items():
+ mock_method.side_effect = side_effect
+
+ result = self.simulate_request(action, url, params=params, headers=headers, body=body)
+ self.assertEqual(result.status, expected_code)
+ if expected_response:
+ self.assertEqual(result.json, expected_response)
+
+ def validate_post_request(self, url, headers={}, body="", mocks={},
+ side_effects={},
+ expected_code=base.CREATED_CODE, expected_response=None):
+ self.validate_request("POST", url, {}, headers, body, mocks, side_effects,
+ expected_code, expected_response)
+
+ def validate_delete_request(self, url, params={}, headers={}, mocks={},
+ side_effects={},
+ expected_code=base.SUCCESSFUL_CODE, expected_response=None):
+ self.validate_request("DELETE", url, params, headers, "",
+ mocks, side_effects,
+ expected_code,
+ expected_response)
+
+ def get_updated_data(self, original_data, deleted_keys=[], updates={}):
+ copy_data = copy.deepcopy(original_data)
+
+ for key in deleted_keys:
+ del copy_data[key]
+
+ for key, value in updates.items():
+ copy_data[key] = value
+
+ return copy_data
+
+ def tearDown(self):
+ # if the authentication method has been mocked, it needs to be reset after test
+ if not self.authenticate:
+ AuthenticationMiddleware.process_request = self.original_auth_method