def create_objs_rest_used_exta_arrts(name, extra_attrs, factory_params): """Create new objects via REST API according to object name (plural form) and list extra attributes. Return: [lib.entities.entity.*Entity, ...] """ if extra_attrs[0].type == objects.get_singular(objects.CUSTOM_ATTRIBUTES): if name == objects.ASSESSMENT_TEMPLATES: return factory.get_cls_rest_service(object_name=name)().create_objs( count=1, factory_params=factory_params, custom_attribute_definitions=CustomAttributeDefinitionsFactory. generate_ca_defenitions_for_asmt_tmpls( list_ca_definitions=extra_attrs[:len(_list_cas_types)]), audit=extra_attrs[len(_list_cas_types):][0].__dict__) else: cavs = [cav.__dict__ for cav in CustomAttributeDefinitionsFactory.generate_ca_values( cads=extra_attrs)] return factory.get_cls_rest_service(object_name=name)().create_objs( count=1, factory_params=factory_params, custom_attribute_definitions=[cad.__dict__ for cad in extra_attrs], custom_attribute_values=cavs) else: return ([factory.get_cls_rest_service(object_name=name)(). create_objs(count=1, factory_params=factory_params, **{parent_obj.type.lower(): parent_obj.__dict__})[0] for parent_obj in extra_attrs])
def create_objs_rest_used_exta_arrts(name, extra_attrs, factory_params): """Create new objects via REST API according to object name (plural form) and list extra attributes. Return: [lib.entities.entity.*Entity, ...] """ if extra_attrs[0].type == objects.get_singular( objects.CUSTOM_ATTRIBUTES): if name == objects.ASSESSMENT_TEMPLATES: return factory.get_cls_rest_service(object_name=name)( ).create_objs( count=1, factory_params=factory_params, custom_attribute_definitions= CustomAttributeDefinitionsFactory. generate_ca_defenitions_for_asmt_tmpls( list_ca_definitions=extra_attrs[:len(_list_cas_types )]), audit=extra_attrs[len(_list_cas_types):][0].__dict__) else: return factory.get_cls_rest_service( object_name=name)().create_objs( count=1, factory_params=factory_params, custom_attributes=CustomAttributeDefinitionsFactory( ).generate_ca_values(list_ca_def_objs=extra_attrs)) else: return ([ factory.get_cls_rest_service(object_name=name)().create_objs( count=1, factory_params=factory_params, **{parent_obj.type.lower(): parent_obj.__dict__})[0] for parent_obj in extra_attrs ])
def update_rest_fixture(fixture, factory_params=None): """Extract arguments of 'update_rest_fixture' fixture from fixture name, update existing objects via REST API and return updated. """ parent_objs = None has_cas = False obj_name = fixture.replace("update_", "").replace("_rest", "") _objs_to_update = "new_{}_rest".format(obj_name) # e.g. need if: 'new_controls_rest' and 'update_control_rest' try: objs_to_update = get_fixture_from_dict_fixtures(fixture=_objs_to_update) except KeyError: _objs_to_update = "new_{}_rest".format(objects.get_plural(obj_name)) objs_to_update = get_fixture_from_dict_fixtures( fixture=_objs_to_update)[0] if objects.get_plural(obj_name) in objects.ALL_OBJS: obj_name = objects.get_plural(obj_name) if "_with_cas" in obj_name: has_cas = True obj_name = objects.get_plural(obj_name.replace("_with_cas", "")) parent_objs = get_fixture_from_dict_fixtures( fixture="new_{}_rest".format("cas_for_" + obj_name)) if objs_to_update: if has_cas and parent_objs: updated_objs = ( factory.get_cls_rest_service(object_name=obj_name)().update_objs( objs=objs_to_update, factory_params=factory_params, custom_attributes=CustomAttributeDefinitionsFactory(). generate_ca_values(list_ca_def_objs=parent_objs))) else: updated_objs = factory.get_cls_rest_service( object_name=obj_name)().update_objs(objs=objs_to_update, factory_params=factory_params) return updated_objs
def update_rest_fixture(fixture, factory_params=None): """Extract arguments of 'update_rest_fixture' fixture from fixture name, update existing objects via REST API and return updated. """ parent_objs = None has_cas = False obj_name = fixture.replace("update_", "").replace("_rest", "") _objs_to_update = "new_{}_rest".format(obj_name) # e.g. need if: 'new_controls_rest' and 'update_control_rest' try: objs_to_update = _get_fixture_from_dict_fixtures(fixture=_objs_to_update) except KeyError: _objs_to_update = "new_{}_rest".format(objects.get_plural(obj_name)) objs_to_update = _get_fixture_from_dict_fixtures( fixture=_objs_to_update)[0] if objects.get_plural(obj_name) in objects.ALL_OBJS: obj_name = objects.get_plural(obj_name) if "_with_cas" in obj_name: has_cas = True obj_name = objects.get_plural(obj_name.replace("_with_cas", "")) parent_objs = _get_fixture_from_dict_fixtures( fixture="new_{}_rest".format("cas_for_" + obj_name)) if objs_to_update: if has_cas and parent_objs: updated_objs = ( factory.get_cls_rest_service(object_name=obj_name)().update_objs( objs=objs_to_update, factory_params=factory_params, custom_attributes=CustomAttributeDefinitionsFactory(). generate_ca_values(list_ca_def_objs=parent_objs))) else: updated_objs = factory.get_cls_rest_service( object_name=obj_name)().update_objs(objs=objs_to_update, factory_params=factory_params) return updated_objs
def update_control(control, **attrs): """Update control.""" # pylint: disable=no-else-return if not attrs: attrs["title"] = "EDITED_" + control.title return (factory.get_cls_rest_service(objects.get_plural( control.type))().update_obj(obj=control, title=attrs["title"])) else: return (factory.get_cls_rest_service(objects.get_plural( control.type))().update_obj(obj=control, **attrs))
def update_control(control, **attrs): """Update control.""" # pylint: disable=no-else-return if not attrs: attrs["title"] = "EDITED_" + control.title return (factory.get_cls_rest_service( objects.get_plural(control.type))().update_obj( obj=control, title=attrs["title"])) else: return (factory.get_cls_rest_service( objects.get_plural(control.type))().update_obj( obj=control, **attrs))
def delete_rest_fixture(fixture): """Extract arguments of 'delete_rest_fixture' fixture from fixture name, delete existing objects via REST API. """ obj_name = fixture.replace("delete_", "").replace("_rest", "") _objs_to_delete = "new_{}_rest".format(obj_name) # e.g. need if: 'new_controls_rest' and 'delete_control_rest' try: objs_to_delete = get_fixture_from_dict_fixtures( fixture=_objs_to_delete) except KeyError: _objs_to_delete = "new_{}_rest".format( objects.get_plural(obj_name)) objs_to_delete = get_fixture_from_dict_fixtures( fixture=_objs_to_delete)[0] if objects.get_plural(obj_name) in objects.ALL_OBJS: obj_name = objects.get_plural(obj_name) if "_with_cas" in obj_name: obj_name = objects.get_plural(obj_name.replace("_with_cas", "")) if "cas_for_" in obj_name: obj_name = objects.CUSTOM_ATTRIBUTES if objs_to_delete: deleted_objs = factory.get_cls_rest_service( object_name=obj_name)().delete_objs(objs=objs_to_delete) return deleted_objs
def create_objs_rest(name, count, factory_params): """Create new objects via REST API according to object name (plural form) and objects count. Return: [lib.entities.entity.*Entity, ...] """ return factory.get_cls_rest_service(object_name=name)().create_objs( count=count, factory_params=factory_params)
def test_snapshot_can_be_unmapped_from_assessment_or_issue( self, create_audit_with_control_and_update_control, dynamic_objects, selenium, dynamic_object_state): """Check Snapshot can be unmapped from assessment using "Unmap" button on info panel. Test parameters: "Checking assessment" "Checking issue" Steps: - Create assessment - Map snapshoted control with assessment - Unmap snapshot from assessment - Make sure that assessment has no any mapped snapshots """ # pylint: disable=misplaced-comparison-constant audit_with_one_control = create_audit_with_control_and_update_control control = audit_with_one_control["new_control_rest"][0].repr_ui() audit = audit_with_one_control["new_audit_rest"][0] existing_obj = dynamic_objects existing_obj_name = objects.get_plural(existing_obj.type) (get_cls_webui_service(existing_obj_name)( selenium).map_objs_via_tree_view_item(src_obj=audit, dest_objs=[control])) controls_ui_service = (get_cls_webui_service( objects.get_plural(control.type))(selenium)) (get_cls_rest_service(existing_obj_name)().update_obj( obj=existing_obj, status=dynamic_object_state)) controls_ui_service.unmap_via_info_panel(existing_obj, control) actual_controls_count = controls_ui_service.get_count_objs_from_tab( src_obj=existing_obj) actual_controls = (controls_ui_service.get_list_objs_from_tree_view( src_obj=existing_obj)) assert 0 == actual_controls_count assert [] == actual_controls
def test_destructive_snapshot_can_be_unmapped_from_assessment_or_issue( self, create_audit_with_control_and_update_control, dynamic_objects, selenium, dynamic_object_state ): """Check Snapshot can be unmapped from assessment using "Unmap" button on info panel. Test parameters: "Checking assessment" "Checking issue" Steps: - Create assessment - Map snapshoted control with assessment - Unmap snapshot from assessment - Make sure that assessment has no any mapped snapshots """ # pylint: disable=misplaced-comparison-constant audit_with_one_control = create_audit_with_control_and_update_control control = audit_with_one_control["new_control_rest"][0].repr_ui() audit = audit_with_one_control["new_audit_rest"][0] existing_obj = dynamic_objects existing_obj_name = objects.get_plural(existing_obj.type) (get_cls_webui_service(existing_obj_name)(selenium). map_objs_via_tree_view_item(src_obj=audit, dest_objs=[control])) controls_ui_service = webui_service.ControlsService(selenium) (get_cls_rest_service(existing_obj_name)(). update_obj(obj=existing_obj, status=dynamic_object_state)) controls_ui_service.unmap_via_info_panel(existing_obj, control) actual_controls_count = controls_ui_service.get_count_objs_from_tab( src_obj=existing_obj) actual_controls = (controls_ui_service.get_list_objs_from_tree_view( src_obj=existing_obj)) assert 0 == actual_controls_count assert [] == actual_controls
def create_objs_rest(name, count, factory_params): """Create new objects via REST API according to object name (plural form) and objects count. Return: [lib.entities.entity.*Entity, ...] """ return factory.get_cls_rest_service( object_name=name)().create_objs(count=count, factory_params=factory_params)
def cas_dashboards(obj, *urls): """Creates 'Dashboard' CAs for obj and fill them with provided urls. Returns: dict with dashboard tab items names as a keys and urls as a values. """ cads_rest_service = rest_service.CustomAttributeDefinitionsService() gca_defs = cads_rest_service.create_dashboard_gcas(obj.type, count=len(urls)) factory.get_cls_rest_service(objects.get_plural(obj.type))().update_obj( obj=obj, custom_attributes=dict(zip([gca_def.id for gca_def in gca_defs], urls))) valid_dashboard_url_pattern = re.compile(r"^https?://[^\s]+$") valid_urls = [i for i in urls if re.match(valid_dashboard_url_pattern, i)] return dict( zip([ gca_def.title.replace(value_aliases.DASHBOARD + "_", "") for gca_def in gca_defs ], valid_urls))
def _create_obj_in_program_scope(obj_name, program, **attrs): """Create an object with `attrs`. Optionally map this object to program. """ factory_params, attrs_remainder = _split_attrs(attrs, ["program"]) obj = factory.get_cls_rest_service(object_name=obj_name)().create_obj( factory_params=factory_params, **attrs_remainder) if program: map_objs(program, obj) return obj
def _create_obj_in_program_scope(obj_name, program, **attrs): """Create an object with `attrs`. Optionally map this object to program. """ factory_params, attrs_remainder = _split_attrs(attrs, ["program"]) obj = factory.get_cls_rest_service(object_name=obj_name)().create_obj( factory_params=factory_params, **attrs_remainder) if program: map_objs(program, obj) return obj
def create_and_clone_audit_w_params_to_update( self, request, new_program_rest, new_control_rest, map_new_program_rest_to_new_control_rest, new_audit_rest, new_assessment_rest, new_assessment_template_rest, new_issue_rest, selenium): """Create Audit with clonable and non clonable objects via REST API and clone it with them via UI. Preconditions: - Program, Control created via REST API. - Control mapped to Program via REST API. - Audit created under Program via REST API. - Assessment, Assessment Template, Issue created under Audit via REST API. - Issue mapped to Audit via REST API. """ # pylint: disable=too-many-locals if hasattr(request, "param") and request.param: if isinstance(request.param, tuple): fixture, params_to_update = request.param # fixtures which are objects if fixture in request.fixturenames and fixture.startswith( "new_"): fixture = locals().get(fixture) (get_cls_rest_service(objects.get_plural( fixture.type))().update_obj(obj=fixture, **params_to_update)) expected_audit = entities_factory.AuditsFactory().clone( audit=new_audit_rest)[0] expected_asmt_tmpl = entities_factory.AssessmentTemplatesFactory( ).clone(asmt_tmpl=new_assessment_template_rest)[0] actual_audit = (webui_service.AuditsService( selenium).clone_via_info_page_and_get_obj( audit_obj=new_audit_rest)) return { "audit": new_audit_rest, "expected_audit": expected_audit, "actual_audit": actual_audit, "assessment": new_assessment_rest, "issue": new_issue_rest, "assessment_template": new_assessment_template_rest, "expected_assessment_template": expected_asmt_tmpl, "control": new_control_rest, "program": new_program_rest }
def update_acl(objs, people, rewrite_acl=False, **kwargs): """Updates or rewrites access control list of objects. Args: objs: A list of objects to update. people: Person or list of persons who will be assigned with role rewrite_acl: Boolean indicating whether the object ACL will be updated or rewritten. **kwargs: role_name: Name of access control role. role_id: Id of access control role. Returns: list of updated objects.""" return [ factory.get_cls_rest_service(objects.get_plural( obj.type))().update_acl(obj=obj, people=people, rewrite_acl=rewrite_acl, role_name=kwargs["role_name"], role_id=kwargs["role_id"]) for obj in objs ]
def create_and_clone_audit_w_params_to_update( self, request, program, control_mapped_to_program, audit, assessment, assessment_template_rest, issue_mapped_to_audit, selenium ): """Create Audit with clonable and non clonable objects via REST API and clone it with them via UI. Preconditions: - Program, Control created via REST API. - Control mapped to Program via REST API. - Audit created under Program via REST API. - Assessment, Assessment Template, Issue created under Audit via REST API. - Issue mapped to Audit via REST API. """ # pylint: disable=too-many-locals if hasattr(request, "param") and request.param: if isinstance(request.param, tuple): fixture, params_to_update = request.param # fixtures which are objects if fixture in request.fixturenames and ( fixture == "audit" or "assessment_template" ): fixture = locals().get(fixture) (get_cls_rest_service(objects.get_plural(fixture.type))(). update_obj(obj=fixture, **params_to_update)) expected_audit = entities_factory.AuditsFactory.clone( audit=audit)[0] expected_asmt_tmpl = entities_factory.AssessmentTemplatesFactory.clone( asmt_tmpl=assessment_template_rest)[0] actual_audit = (webui_service.AuditsService(selenium). clone_via_info_page_and_get_obj(audit_obj=audit)) return { "audit": audit, "expected_audit": expected_audit, "actual_audit": actual_audit, "assessment": assessment, "issue": issue_mapped_to_audit, "assessment_template": assessment_template_rest, "expected_assessment_template": expected_asmt_tmpl, "control": control_mapped_to_program, "program": program }
def delete_rest_fixture(fixture): """Extract arguments of 'delete_rest_fixture' fixture from fixture name, delete existing objects via REST API. """ obj_name = fixture.replace("delete_", "").replace("_rest", "") _objs_to_delete = "new_{}_rest".format(obj_name) # e.g. need if: 'new_controls_rest' and 'delete_control_rest' try: objs_to_delete = get_fixture_from_dict_fixtures(fixture=_objs_to_delete) except KeyError: _objs_to_delete = "new_{}_rest".format(objects.get_plural(obj_name)) objs_to_delete = get_fixture_from_dict_fixtures( fixture=_objs_to_delete)[0] if objects.get_plural(obj_name) in objects.ALL_OBJS: obj_name = objects.get_plural(obj_name) if "_with_cas" in obj_name: obj_name = objects.get_plural(obj_name.replace("_with_cas", "")) if "cas_for_" in obj_name: obj_name = objects.CUSTOM_ATTRIBUTES if objs_to_delete: deleted_objs = factory.get_cls_rest_service( object_name=obj_name)().delete_objs(objs=objs_to_delete) return deleted_objs
def delete_control(control): """Delete control.""" return (factory.get_cls_rest_service( objects.get_plural(control.type))().delete_objs(control))
def delete_control(control): """Delete control.""" return (factory.get_cls_rest_service( objects.get_plural(control.type))().delete_objs(control))
def update_object(obj, **attrs): """Update object attrs or update object title if no attrs passed.""" if not attrs: attrs.update({"title": element.Common.TITLE_EDITED_PART + obj.title}) return (factory.get_cls_rest_service(objects.get_plural( obj.type))().update_obj(obj=obj, **attrs))