def test_get_check_awsaccounts_handler_success(self): # patch mock patch_get_uuid4 = patch("premembers.common.common_utils.get_uuid4") # start mock object mock_get_uuid4 = patch_get_uuid4.start() # mock data mock_get_uuid4.side_effect = side_effect_get_uuid4 # addCleanup stop mock object self.addCleanup(patch_get_uuid4.stop) # create data table list_data_aws_accounts = [] mock_pm_checkHistory.create(data_pm_check_history) mock_pm_projects.create(data_pm_project) mock_pm_organizations.create(data_pm_organizations) for index, data_aws_account_coops in enumerate( list_data_aws_account_coops): mock_pm_awsAccountCoops.create(data_aws_account_coops) data_aws_accounts = { 'AWSAccount': data_aws_account_coops['AWSAccount'], 'CoopID': data_aws_account_coops['CoopID'], 'AWSAccountName': data_aws_account_coops['AWSAccountName'], 'RoleName': data_aws_account_coops['RoleName'], 'ExternalID': data_aws_account_coops['ExternalID'], 'OrganizationID': data_aws_account_coops['OrganizationID'], 'OrganizationName': data_pm_organizations['OrganizationName'], 'ProjectID': data_aws_account_coops['ProjectID'], 'ProjectName': data_pm_project['ProjectName'], 'CheckHistoryId': check_history_id, 'CheckResultID': str(index + 1) } list_data_aws_accounts.append(data_aws_accounts) # prepare data expected_response = { 'CheckHistoryId': check_history_id, 'AWSAccounts': list_data_aws_accounts } # create event mock event_mock = {"CheckHistoryId": check_history_id} # Call function test actual_response = awssecuritychecks.get_check_awsaccounts_handler( event_mock, {}) # check response self.assertEquals(expected_response, actual_response) # check CheckStatus check_history = mock_pm_checkHistory.query_key(check_history_id) self.assertEquals(1, check_history['CheckStatus']) # check create resord table PM_CheckResults check_results = mock_pm_checkResults.query_all() self.assertEquals(len(list_data_aws_account_coops), len(check_results['Items']))
def setUp(self): super().setUp() # truncate old data in the table if db_utils.check_table_exist(Tables.PM_SECURITY_CHECK_WEBHOOK): db_utils.delete_table(Tables.PM_SECURITY_CHECK_WEBHOOK) if db_utils.check_table_exist( Tables.PM_SECURITY_CHECK_WEBHOOK_CALL_HISTORY): db_utils.delete_table( Tables.PM_SECURITY_CHECK_WEBHOOK_CALL_HISTORY) if db_utils.check_table_exist(Tables.PM_PROJECTS): db_utils.delete_table(Tables.PM_PROJECTS) if db_utils.check_table_exist(Tables.PM_CHECK_HISTORY): db_utils.delete_table(Tables.PM_CHECK_HISTORY) # create table mock_pm_projects.create_table() mock_pm_checkHistory.create_table() mock_pm_securityCheckWebhook.create_table() mock_pm_securityCheckWebhookCallHistory.create_table() # create data table pm_project mock_pm_projects.create(data_pm_project) # create data pm_security_check_webhooks for data_pm_security_check_webhooks in list_data_pm_security_check_webhooks: mock_pm_securityCheckWebhook.create( data_pm_security_check_webhooks) # create data pm_securityCheckWebhookCallHistory for data_pm_security_check_webhook_call_history in list_data_pm_security_check_webhook_call_historys: mock_pm_securityCheckWebhookCallHistory.create( data_pm_security_check_webhook_call_history)
def test_list_item_settings_handler_success_case_not_exists_data_exclusion_resource( self): # perpare data test mock_pm_affiliation.create(data_pm_affiliation) mock_pm_projects.create(data_pm_projects) mock_pm_awsAccountCoops.create(data_pm_aws_account_coops) # Call function test actual_response = checkitemsettings.list_item_settings_handler( event_mock, {}) # Get data response actual_status_code = actual_response['statusCode'] actual_response_bodys = json.loads(actual_response['body']) # Check data self.assertEqual(HTTPStatus.OK, actual_status_code) for actual_response_body in actual_response_bodys: if actual_response_body[ "checkItemCode"] in LIST_CHECK_ITEM_CODE_EXCLUDED_RESOURCE: self.assertEqual(ExcludedResourceFlag.Disable, actual_response_body["excludedResourceFlag"]) else: self.assertEqual(ExcludedResourceFlag.Other, actual_response_body["excludedResourceFlag"])
def setUp(self): super().setUp() # truncate old data in the table if db_utils.check_table_exist(Tables.PM_PROJECTS): db_utils.delete_table(Tables.PM_PROJECTS) if db_utils.check_table_exist(Tables.PM_ORGANIZATIONS): db_utils.delete_table(Tables.PM_ORGANIZATIONS) # create table mock_pm_projects.create_table() mock_pm_organizations.create_table() # create data table mock_pm_projects.create(data_pm_project) mock_pm_organizations.create(data_pm_organization)
def setUp(self): super().setUp() # truncate old data in the table if db_utils.check_table_exist(Tables.PM_AFFILIATION): db_utils.delete_table(Tables.PM_AFFILIATION) if db_utils.check_table_exist(Tables.PM_PROJECTS): db_utils.delete_table(Tables.PM_PROJECTS) if db_utils.check_table_exist(Tables.PM_CHECK_HISTORY): db_utils.delete_table(Tables.PM_CHECK_HISTORY) # create table mock_pm_affiliation.create_table() mock_pm_projects.create_table() mock_pm_checkHistory.create_table() # create data table mock_pm_projects.create(data_pm_project) mock_pm_affiliation.create(data_pm_affiliation)
def test_list_item_settings_handler_success_case_exists_data_exclusion_resource( self): # perpare data test aws_account = copy.deepcopy(DataCommon.AWS_ACCOUNT) mock_pm_affiliation.create(data_pm_affiliation) mock_pm_projects.create(data_pm_projects) mock_pm_awsAccountCoops.create(data_pm_aws_account_coops) for check_item_code in LIST_CHECK_ITEM_CODE_EXCLUDED_RESOURCE: data_pm_exclusion_resources[ 'ExclusionResourceID'] = common_utils.get_uuid4() data_pm_exclusion_resources['CheckItemCode'] = check_item_code data_pm_exclusion_resources['CheckItemRefineCode'] = copy.deepcopy( DataPmExclusionResources.CHECK_ITEM_REFINE_CODE_TEMPLATE. format(organization_id, project_id, aws_account, check_item_code)) data_pm_exclusion_resources['AccountRefineCode'] = copy.deepcopy( DataPmExclusionResources.ACCOUNT_REFINE_CODE_TEMPLATE.format( organization_id, project_id, aws_account)) mock_pm_exclusionResources.create(data_pm_exclusion_resources) # Call function test actual_response = checkitemsettings.list_item_settings_handler( event_mock, {}) # Get data response actual_status_code = actual_response['statusCode'] actual_response_bodys = json.loads(actual_response['body']) # Check data self.assertEqual(HTTPStatus.OK, actual_status_code) for actual_response_body in actual_response_bodys: if actual_response_body[ "checkItemCode"] in LIST_CHECK_ITEM_CODE_EXCLUDED_RESOURCE: self.assertEqual(ExcludedResourceFlag.Enable, actual_response_body["excludedResourceFlag"]) else: self.assertEqual(ExcludedResourceFlag.Other, actual_response_body["excludedResourceFlag"])