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 _check_assessments_filtration(assessment, cavs, operator, audit, selenium): """Check that filtration of assessments works.""" 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 get_attrs_names(cls, entity=None): """Get list unique entities attributes' names. If 'entity' then get attributes of one entered entity, else get attributes of all entities. """ all_entities_cls = (help_utils.convert_to_list(entity) if entity else list(Entity.all_entities_classes())) all_entities_attrs_names = StringMethods.convert_list_elements_to_list( [entity_cls().__dict__.keys() for entity_cls in all_entities_cls]) return list(set(all_entities_attrs_names))
def get_attrs_names_for_entities(cls, entity=None): """Get list unique attributes names for entities. If 'entity' then get attributes of one entered entity, else get attributes of all entities. """ all_entities_cls = (help_utils.convert_to_list(entity) if entity else list(Entity.all_entities_classes())) all_entities_attrs_names = StringMethods.convert_list_elements_to_list( [entity_cls().__dict__.keys() for entity_cls in all_entities_cls]) return list(set(all_entities_attrs_names))
def generate_snapshots_fixtures(fixture): """Generate, run and return of results for snapshots dynamic fixtures according to tuple of fixture name. Example: 'create_audit_with_control__risk_and_update_control' 'create_audit_with_controls' 'create_audit_with_controls_and_update_control' 'create_audit_with_control__risk_and_update_control__risk """ global dict_executed_fixtures if isinstance(fixture, str) and fixture.startswith("create_audit_with_"): _creation_params = None _action_params = None updating_params = [] deleting_params = [] fixture_params = fixture.replace("create_audit_with_", "") if "_and_" in fixture_params: _creation_params, _action_params = fixture_params.split("_and_") if "_and_" not in fixture_params: _creation_params = fixture_params creation_params = StringMethods.convert_list_elements_to_list([ "new_{}_rest".format(param) if "_with_cas" not in param else [ "new_cas_for_{}_rest".format( objects.get_plural(param.split("_")[0])), "new_{}_rest".format(param) ] for param in _creation_params.split("__") ]) mapping_params = [ "map_new_program_rest_to_new_{}_rest".format(param) for param in _creation_params.split("__") ] creation_part = (["new_program_rest"] + creation_params + mapping_params + ["new_audit_rest"]) if _action_params: if "update" in _action_params: updating_params = [ "update_{}_rest".format(param) for param in _action_params.replace("update_", "").split("__") ] if "delete" in _action_params: deleting_params = [ "delete_{}_rest".format(param) for param in _action_params.replace("delete_", "").split("__") ] action_part = (updating_params + deleting_params) all_manipulations = creation_part + action_part generate_common_fixtures(*all_manipulations) executed_snapshots_fixtures = copy.deepcopy(dict_executed_fixtures) return executed_snapshots_fixtures
def generate_snapshots_fixtures(fixture): """Generate, run and return of results for snapshots dynamic fixtures according to tuple of fixture name. Example: 'create_audit_with_control__risk_and_update_control' 'create_audit_with_controls' 'create_audit_with_controls_and_update_control' 'create_audit_with_control__risk_and_update_control__risk """ global dict_executed_fixtures if isinstance(fixture, str) and fixture.startswith("create_audit_with_"): _creation_params = None _action_params = None updating_params = [] deleting_params = [] fixture_params = fixture.replace("create_audit_with_", "") if "_and_" in fixture_params: _creation_params, _action_params = fixture_params.split("_and_") if "_and_" not in fixture_params: _creation_params = fixture_params creation_params = StringMethods.convert_list_elements_to_list([ "new_{}_rest".format(param) if "_with_cas" not in param else ["new_cas_for_{}_rest".format(objects.get_plural(param.split("_")[0])), "new_{}_rest".format(param)] for param in _creation_params.split("__")]) mapping_params = [ "map_new_program_rest_to_new_{}_rest".format(param) for param in _creation_params.split("__")] creation_part = (["new_program_rest"] + creation_params + mapping_params + ["new_audit_rest"]) if _action_params: if "update" in _action_params: updating_params = ["update_{}_rest".format(param) for param in _action_params.replace("update_", "").split("__")] if "delete" in _action_params: deleting_params = ["delete_{}_rest".format(param) for param in _action_params.replace("delete_", "").split("__")] action_part = (updating_params + deleting_params) all_manipulations = creation_part + action_part generate_common_fixtures(*all_manipulations) executed_snapshots_fixtures = copy.deepcopy(dict_executed_fixtures) return executed_snapshots_fixtures
def compare_comments(self_comments, other_comments): """Compare entities' 'comments' attributes due to specific dictionaries' format values in list comments. """ # pylint: disable=no-else-return if help_utils.is_multiple_objs( StringMethods.convert_list_elements_to_list( [self_comments, other_comments]), (dict, type(None))): if self_comments and other_comments: is_comments_equal_list = [] for self_comment, other_comment in zip(self_comments, other_comments): is_comments_equal = False if self_comment and other_comment: is_comments_equal = (all( (Representation.compare_datetime( self_comment.get("created_at"), other_comment.get("created_at")) if ( isinstance(_self, datetime) and isinstance(_other, datetime) ) else _self == _other) for _self, _other in zip(self_comment.iteritems( ), other_comment.iteritems()))) # convert datetime to unicode in order to get visible repr if self_comment.get("created_at"): self_comment["created_at"] = unicode( self_comment.get("created_at")) if other_comment.get("created_at"): other_comment["created_at"] = unicode( other_comment.get("created_at")) else: is_comments_equal = self_comment == other_comment is_comments_equal_list.append(is_comments_equal) return all(is_equal for is_equal in is_comments_equal_list) else: return self_comments == other_comments else: Representation.attrs_values_types_error( self_attr=self_comments, other_attr=other_comments, expected_types=(list.__name__, type(None).__name__))
def compare_comments(self_comments, other_comments): """Compare entities' 'comments' attributes due to specific dictionaries' format values in list comments. """ # pylint: disable=no-else-return if help_utils.is_multiple_objs( StringMethods.convert_list_elements_to_list( [self_comments, other_comments]), (dict, type(None))): if self_comments and other_comments: is_comments_equal_list = [] for self_comment, other_comment in zip(self_comments, other_comments): is_comments_equal = False if self_comment and other_comment: is_comments_equal = ( all((Representation.compare_datetime( self_comment.get("created_at"), other_comment.get("created_at") ) if (isinstance(_self, datetime) and isinstance(_other, datetime))else _self == _other) for _self, _other in zip( self_comment.iteritems(), other_comment.iteritems()))) # convert datetime to unicode in order to get visible repr if self_comment.get("created_at"): self_comment["created_at"] = unicode( self_comment.get("created_at")) if other_comment.get("created_at"): other_comment["created_at"] = unicode( other_comment.get("created_at")) else: is_comments_equal = self_comment == other_comment is_comments_equal_list.append(is_comments_equal) return all(is_equal for is_equal in is_comments_equal_list) else: return self_comments == other_comments else: Representation.attrs_values_types_error( self_attr=self_comments, other_attr=other_comments, expected_types=(list.__name__, type(None).__name__))
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.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( 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])))