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_cads_for_asmt_tmpls( cads=extra_attrs[:len(_list_cas_types)]), audit=extra_attrs[len(_list_cas_types):][0].__dict__) else: cavs = [cav.__dict__ for cav in CustomAttributeDefinitionsFactory.generate_cavs( 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_audit_with_control_with_cas_and_update_control_cav( program, gcads_for_control, control_mapped_to_program, audit ): """Create Program, GCAs for Control and Control, map Control to Program, create Audit under Program, update Control via REST API and return dictionary of executed fixtures. """ from lib.entities.entities_factory import CustomAttributeDefinitionsFactory cavs = [cav.__dict__ for cav in CustomAttributeDefinitionsFactory.generate_cavs( cads=gcads_for_control)] return {"program": program, "control": copy.deepcopy(control_mapped_to_program), "audit": audit, "updated_control": rest_facade.update_control( control_mapped_to_program, custom_attribute_values=cavs)}
def _set_values_for_assessment(assessment, cads, only_checkbox, checkbox_value): """Set CA values for assessment""" checkbox_cad = Representation.filter_objs_by_attrs( objs=cads, attribute_type=element.AdminWidgetCustomAttributes.CHECKBOX) if only_checkbox: cavs = [CustomAttributeDefinitionsFactory.generate_cav( checkbox_cad, checkbox_value)] else: cavs = CustomAttributeDefinitionsFactory.generate_cavs(cads) for cav in cavs: if cav.custom_attribute_id == checkbox_cad.id: cav.attribute_value = checkbox_value rest_service.AssessmentsService().update_obj( obj=assessment, custom_attribute_values=[cav.__dict__ for cav in cavs]) return cavs
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: cavs = [ cav.__dict__ for cav in CustomAttributeDefinitionsFactory.generate_cavs( cads=parent_objs) ] updated_objs = (factory.get_cls_rest_service( object_name=obj_name)().update_objs( objs=objs_to_update, factory_params=factory_params, custom_attribute_definitions=[ cad.__dict__ for cad in parent_objs ], custom_attribute_values=cavs)) 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: cavs = [cav.__dict__ for cav in CustomAttributeDefinitionsFactory.generate_cavs( cads=parent_objs)] updated_objs = ( factory.get_cls_rest_service(object_name=obj_name)().update_objs( objs=objs_to_update, factory_params=factory_params, custom_attribute_definitions=[cad.__dict__ for cad in parent_objs], custom_attribute_values=cavs)) 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