def _check_assessments_filtration(assessment, cavs, operator, audit, selenium): """Check that filtration of assessments works.""" # pylint: disable=too-many-locals cads = [Representation.repr_dict_to_obj(cad) for cad in assessment.custom_attribute_definitions] filter_exprs = FilterUtils().get_filter_exprs_by_cavs( cads, cavs, operator) assessment = Representation.extract_objs_wo_excluded_attrs( [assessment.repr_ui()], *(Representation.tree_view_attrs_to_exclude + ( "audit", "assessment_type", "modified_by")) )[0] expected_results = [{"filter": filter_expr, "objs": [assessment]} for filter_expr in filter_exprs] actual_results = [] for filter_expr in filter_exprs: result = { "filter": filter_expr, "objs": webui_service.AssessmentsService( selenium).filter_and_get_list_objs_from_tree_view(audit, filter_expr) } actual_results.append(result) error_message = messages.AssertionMessages.format_err_msg_equal( [{exp_res["filter"]: [exp_obj.title for exp_obj in exp_res["objs"]]} for exp_res in expected_results], [{act_res["filter"]: [act_obj.title for act_obj in act_res["objs"]]} for act_res in actual_results] ) + messages.AssertionMessages.format_err_msg_equal( StringMethods.convert_list_elements_to_list( [exp_res["objs"] for exp_res in expected_results]), StringMethods.convert_list_elements_to_list( [act_res["objs"] for act_res in actual_results])) assert expected_results == actual_results, error_message
def test_asmts_gcas_filtering( self, new_program_rest, new_audit_rest, new_cas_for_assessments_rest, new_assessments_rest, selenium, operator ): """Test for checking filtering of Assessment by Custom Attributes in audit scope. Preconditions: - Program created via REST API. - Audit created via REST API. - Assessment created via REST API. - Global Custom Attributes for Assessment created via REST API. """ custom_attr_values = ( CustomAttributeDefinitionsFactory().generate_ca_values( list_ca_def_objs=new_cas_for_assessments_rest)) expected_asmt = new_assessments_rest[0] (rest_service.AssessmentsService().update_obj( obj=expected_asmt, custom_attributes=custom_attr_values)) filter_exprs = FilterUtils().get_filter_exprs_by_cas( expected_asmt.custom_attribute_definitions, custom_attr_values, operator) # due to 'actual_asmt.custom_attributes = {None: None}' expected_asmt = expected_asmt.repr_ui().update_attrs( custom_attributes={None: None}, status=AssessmentStates.IN_PROGRESS) expected_results = [{"filter": filter_expr, "objs": [expected_asmt]} for filter_expr in filter_exprs] actual_results = [ {"filter": filter_expr, "objs": webui_service.AssessmentsService(selenium). filter_and_get_list_objs_from_tree_view(new_audit_rest, filter_expr)} for filter_expr in filter_exprs] assert expected_results == actual_results, ( messages.AssertionMessages.format_err_msg_equal(expected_results, actual_results))
def test_asmts_gcas_filtering( self, new_program_rest, new_audit_rest, new_cas_for_assessments_rest, new_assessments_rest, operator, selenium ): """Test for checking filtering of Assessment by Custom Attributes in audit scope. Preconditions: - Program created via REST API. - Audit created via REST API. - Assessments created via REST API. - Global Custom Attributes for Assessment created via REST API. - Set revers value of GCA with Checkbox type for second Assessment. """ # pylint: disable=too-many-locals custom_attr_values = ( CustomAttributeDefinitionsFactory().generate_ca_values( list_ca_def_objs=new_cas_for_assessments_rest)) checkbox_id = entity.Entity.filter_objs_by_attrs( objs=new_cas_for_assessments_rest, attribute_type=element.AdminWidgetCustomAttributes.CHECKBOX).id expected_asmt = new_assessments_rest[0] asmts_rest_service = rest_service.AssessmentsService() asmts_rest_service.update_obj( obj=expected_asmt, custom_attributes=custom_attr_values) asmts_rest_service.update_obj( obj=new_assessments_rest[1], custom_attributes={checkbox_id: not custom_attr_values[checkbox_id]}) filter_exprs = FilterUtils().get_filter_exprs_by_cas( expected_asmt.custom_attribute_definitions, custom_attr_values, operator) # 'expected_asmt': updated_at (outdated) # 'actual_asmts': created_at, updated_at, custom_attributes (None) expected_asmt = entity.Entity.extract_objs_wo_excluded_attrs( [expected_asmt.update_attrs( status=AssessmentStates.IN_PROGRESS).repr_ui()], *Representation.tree_view_attrs_to_exclude)[0] expected_results = [{"filter": filter_expr, "objs": [expected_asmt]} for filter_expr in filter_exprs] actual_results = [ {"filter": filter_expr, "objs": entity.Entity.extract_objs_wo_excluded_attrs( webui_service.AssessmentsService( selenium).filter_and_get_list_objs_from_tree_view( new_audit_rest, filter_expr), *("updated_at", "custom_attributes")) } for filter_expr in filter_exprs] assert expected_results == actual_results, ( messages.AssertionMessages.format_err_msg_equal( [{exp_res["filter"]: [exp_obj.title for exp_obj in exp_res["objs"]] } for exp_res in expected_results], [{act_res["filter"]: [act_obj.title for act_obj in act_res["objs"]] } for act_res in actual_results]) + messages.AssertionMessages.format_err_msg_equal( string_utils.convert_list_elements_to_list( [exp_res["objs"] for exp_res in expected_results]), string_utils.convert_list_elements_to_list( [act_res["objs"] for act_res in actual_results])))
def test_filter_of_snapshotable_control( self, create_audit_with_control_and_update_control, selenium, version_of_ctrl, is_found ): """Check via UI that filtering work for snapshoted version of Control only, filtering by actual values returns no items in scope of Audit page. """ audit_with_one_control = create_audit_with_control_and_update_control audit = audit_with_one_control["new_audit_rest"][0] expected_control = audit_with_one_control[version_of_ctrl][0] filter_exp = FilterUtils.get_filter_exp_by_title(expected_control.title) actual_controls = (webui_service.ControlsService(selenium). filter_list_objs_from_tree_view( src_obj=audit, filter_exp=filter_exp)) assert (expected_control in [ctrls for ctrls in actual_controls if len(actual_controls) != 0] ) == is_found, messages.ERR_MSG_FORMAT.format( [expected_control], actual_controls)
def test_filter_of_snapshotable_control( self, create_audit_with_control_and_update_control, selenium, version_of_ctrl, is_found ): """Check via UI that filtering work for snapshoted version of Control only, filtering by actual values returns no items in scope of Audit page. """ audit_with_one_control = create_audit_with_control_and_update_control audit = audit_with_one_control["new_audit_rest"][0] # due to 'actual_control.custom_attributes = {None: None}' expected_control = (audit_with_one_control[version_of_ctrl][0].repr_ui(). update_attrs(custom_attributes={None: None})) filter_exp = FilterUtils.get_filter_exp_by_title(expected_control.title) actual_controls = ( webui_service.ControlsService(selenium). filter_list_objs_from_tree_view(src_obj=audit, filter_exp=filter_exp)) assert (expected_control in [ctrls for ctrls in actual_controls] ) == is_found, messages.ERR_MSG_FORMAT.format( [expected_control], actual_controls)
def test_filter_of_snapshotable_control( self, create_audit_with_control_and_update_control, selenium, version_of_ctrl, is_found): """Check via UI that filtering work for snapshoted version of Control only, filtering by actual values returns no items in scope of Audit page. """ audit_with_one_control = create_audit_with_control_and_update_control audit = audit_with_one_control["new_audit_rest"][0] # due to 'actual_control.custom_attributes = {None: None}' expected_control = ( audit_with_one_control[version_of_ctrl][0].repr_ui().update_attrs( custom_attributes={None: None})) filter_exp = FilterUtils.get_filter_exp_by_title( expected_control.title) actual_controls = (webui_service.ControlsService( selenium).filter_list_objs_from_tree_view(src_obj=audit, filter_exp=filter_exp)) assert (expected_control in [ ctrls for ctrls in actual_controls ]) == is_found, (messages.AssertionMessages.format_err_msg_contains( expected_control, [ctrls for ctrls in actual_controls]))
def test_filter_of_snapshotable_control( self, create_audit_with_control_and_update_control, version_of_ctrl, is_found, selenium): """Check via UI that filtering work for snapshoted version of Control only, filtering by actual values returns no items in scope of Audit page. """ audit_with_one_control = create_audit_with_control_and_update_control audit = audit_with_one_control["new_audit_rest"][0] expected_control = audit_with_one_control[version_of_ctrl][0].repr_ui() filter_exp = FilterUtils.get_filter_exp_by_title( expected_control.title) actual_controls = (webui_service.ControlsService( selenium).filter_and_get_list_objs_from_tree_view( src_obj=audit, filter_exp=filter_exp)) # 'actual_controls': created_at, updated_at, custom_attributes (None) expected_controls, actual_controls = entity.Entity.extract_objs( [expected_control], actual_controls, *Representation.tree_view_attrs_to_exclude) expected_control = expected_controls[0] assert is_found is (expected_control in actual_controls), ( messages.AssertionMessages.format_err_msg_contains( expected_control, actual_controls))
def test_filter_of_snapshotable_control( self, create_audit_with_control_and_update_control, version_of_ctrl, is_found, selenium ): """Check via UI that filtering work for snapshoted version of Control only, filtering by actual values returns no items in scope of Audit page. """ audit_with_one_control = create_audit_with_control_and_update_control audit = audit_with_one_control["new_audit_rest"][0] expected_control = audit_with_one_control[version_of_ctrl][0].repr_ui() filter_exp = FilterUtils.get_filter_exp_by_title(expected_control.title) actual_controls = (webui_service.ControlsService(selenium). filter_and_get_list_objs_from_tree_view( src_obj=audit, filter_exp=filter_exp)) # 'actual_controls': created_at, updated_at, custom_attributes (None) expected_controls, actual_controls = Representation.extract_objs( [expected_control], actual_controls, *Representation.tree_view_attrs_to_exclude) expected_control = expected_controls[0] assert is_found is (expected_control in actual_controls), ( messages.AssertionMessages.format_err_msg_contains( expected_control, actual_controls))