def test_delete_excluded_resources_case_get_record_pm_aws_account_coops_is_zero( self): # mock object patch_query_awscoop_coop_key = patch( "premembers.repository.pm_awsAccountCoops.query_awscoop_coop_key") # start mock object mock_query_awscoop_coop_key = patch_query_awscoop_coop_key.start() mock_error_common = mock_common_utils.mock_error_common(self) # mock data mock_query_awscoop_coop_key.return_value = [] # addCleanup stop mock object self.addCleanup(patch_query_awscoop_coop_key.stop) # call Function test actual_response = checkitemsettings_logic.delete_excluded_resources( trace_id, organization_id, project_id, check_item_code, coop_id, region_name, resource_type, resource_name) # assert output function # check call function common write log error mock_error_common.assert_called_once() # assert output function actual_response_body = json.loads(actual_response["body"]) err_aws_401 = MsgConst.ERR_AWS_401 self.assertEqual(err_aws_401["code"], actual_response_body["code"]) self.assertEqual(err_aws_401["message"], actual_response_body["message"]) self.assertEqual(err_aws_401["description"], actual_response_body["description"]) self.assertEqual(HTTPStatus.UNPROCESSABLE_ENTITY.value, actual_response["statusCode"])
def test_execute_security_check_with_executed_type_case_error_get_pm_projects_is_zero(self): # patch mock patch_get_projects_by_organization_id = patch( "premembers.repository.pm_projects.get_projects_by_organization_id" ) # start mock object mock_get_projects_by_organization_id = patch_get_projects_by_organization_id.start() mock_error_common = mock_common_utils.mock_error_common(self) # mock object mock_get_projects_by_organization_id.return_value = [] # addCleanup stop mock object self.addCleanup(patch_get_projects_by_organization_id.stop) # call function test actual_response = awschecks_logic.execute_security_check_with_executed_type( trace_id, organization_id, project_id, execute_user_id, email, "MANUAL") # assert output function # check call function common write log error mock_error_common.assert_called_once() # assert output function actual_response_body = json.loads(actual_response["body"]) err_aws_401 = MsgConst.ERR_AWS_401 self.assertEqual(err_aws_401["code"], actual_response_body["code"]) self.assertEqual(err_aws_401["message"], actual_response_body["message"]) self.assertEqual(err_aws_401["description"], actual_response_body["description"]) self.assertEqual(HTTPStatus.UNPROCESSABLE_ENTITY.value, actual_response["statusCode"])
def test_execute_security_check_from_external_case_over_limit_check(self): # patch mock patch_query_webhook_index = patch( "premembers.repository.pm_securityCheckWebhook.query_webhook_index" ) patch_query_key = patch( "premembers.repository.pm_securityCheckWebhook.query_key") patch_query_pm_security_check_webhook_call_history = patch( "premembers.repository.pm_securityCheckWebhookCallHistory.query") # start mock object mock_query_webhook_index = patch_query_webhook_index.start() mock_query_key = patch_query_key.start() mock_query_pm_security_check_webhook_call_history = patch_query_pm_security_check_webhook_call_history.start() mock_error_common = mock_common_utils.mock_error_common(self) # mock object mock_query_webhook_index.return_value = list_data_pm_security_check_webhooks_convert_response mock_query_key.return_value = list_data_pm_security_check_webhooks[0] mock_query_pm_security_check_webhook_call_history.return_value = copy.deepcopy( DataPmSecurityCheckWebhookCallHistory. LIST_DATA_SECURITY_CHECK_WEBHOOK_CALL_HISTORY_OVER_LIMIT_CHECK) # addCleanup stop mock object self.addCleanup(patch_query_webhook_index.stop) self.addCleanup(patch_query_key.stop) self.addCleanup( patch_query_pm_security_check_webhook_call_history.stop) # call function test actual_response = awschecks_logic.execute_security_check_from_external( trace_id, webhook_path) # assert output function # check call function common write log error mock_error_common.assert_called_once() # assert output function actual_response_body = json.loads(actual_response["body"]) message_203 = MsgConst.ERR_REQUEST_203 self.assertEqual(message_203["code"], actual_response_body["code"]) self.assertEqual(message_203["message"], actual_response_body["message"]) self.assertEqual(message_203["description"], actual_response_body["description"]) self.assertEqual(HTTPStatus.TOO_MANY_REQUESTS, actual_response["statusCode"])
def test_delete_excluded_resources_case_record_not_matching_region_name_and_not_matching_resource_name_and_not_matching_resource_type( self): # mock object patch_query_awscoop_coop_key = patch( "premembers.repository.pm_awsAccountCoops.query_awscoop_coop_key") patch_query_check_item_refine_code = patch( "premembers.repository.pm_exclusionResources.query_check_item_refine_code" ) # start mock object mock_query_awscoop_coop_key = patch_query_awscoop_coop_key.start() mock_query_check_item_refine_code = patch_query_check_item_refine_code.start( ) mock_error_common = mock_common_utils.mock_error_common(self) # mock data mock_query_awscoop_coop_key.return_value = data_pm_aws_account_coops mock_query_check_item_refine_code.return_value = [ data_pm_exclusion_resources ] # addCleanup stop mock object self.addCleanup(patch_query_awscoop_coop_key.stop) self.addCleanup(patch_query_check_item_refine_code.stop) region_name = "region_name_not_matching" resource_name = "resource_name_not_matching" resource_type = "resource_type_not_matching" # call Function test actual_response = checkitemsettings_logic.delete_excluded_resources( trace_id, organization_id, project_id, check_item_code, coop_id, region_name, resource_type, resource_name) # assert output function # check call function common write log error mock_error_common.assert_called_once() # assert output function actual_response_body = json.loads(actual_response["body"]) err_301 = MsgConst.ERR_301 self.assertEqual(err_301["code"], actual_response_body["code"]) self.assertEqual(err_301["message"], actual_response_body["message"]) self.assertEqual(err_301["description"], actual_response_body["description"]) self.assertEqual(HTTPStatus.NOT_FOUND.value, actual_response["statusCode"])
def test_execute_security_check_from_external_case_error_record_webhook_query_key_is_zero(self): # patch mock patch_query_webhook_index = patch( "premembers.repository.pm_securityCheckWebhook.query_webhook_index" ) patch_query_key = patch( "premembers.repository.pm_securityCheckWebhook.query_key") # start mock object mock_query_webhook_index = patch_query_webhook_index.start() mock_query_key = patch_query_key.start() mock_error_common = mock_common_utils.mock_error_common(self) # mock object mock_query_webhook_index.return_value = list_data_pm_security_check_webhooks_convert_response mock_query_key.return_value = [] # addCleanup stop mock object self.addCleanup(patch_query_webhook_index.stop) self.addCleanup(patch_query_key.stop) # call function test actual_response = awschecks_logic.execute_security_check_from_external( trace_id, webhook_path) # assert output function # check call function common write log error mock_error_common.assert_called_once() # assert output function actual_response_body = json.loads(actual_response["body"]) message_301 = MsgConst.ERR_301 self.assertEqual(message_301["code"], actual_response_body["code"]) self.assertEqual(message_301["message"], actual_response_body["message"]) self.assertEqual(message_301["description"], actual_response_body["description"]) self.assertEqual(HTTPStatus.NOT_FOUND, actual_response["statusCode"])