Example #1
0
 def assign_owner_to_objs(self,
                          objs,
                          owner=ObjectPersonsFactory().default()):
     """Assign of an owner to objects."""
     return [
         self.client.create_object(type=objects.get_singular(self.endpoint),
                                   ownable=obj.__dict__,
                                   person=owner.__dict__)
         for obj in help_utils.convert_to_list(objs)
     ]
Example #2
0
 def create_objs(self, count, factory_params=None, **attrs_for_template):
     """Create new Assessments and make default relationships of Persons:
 'Creator', 'Assessor' to them via REST API and return list of created
 objects with filtered attributes.
 """
     objs = BaseRestService(url.ASSESSMENTS).create_objs(
         count, factory_params=None, **attrs_for_template)
     # add Default Person as 'Assessor', 'Creator' to Assessments
     RelationshipsService().map_objs(
         src_obj=ObjectPersonsFactory().default(),
         dest_objs=objs,
         attrs={"AssigneeType": "Creator,Assessor"})
     return objs
Example #3
0
 def create_objs(self, count, factory_params=None, **attrs_for_template):
   """Create new Assessments and make default relationships of Persons:
   'Creator', 'Assessor' to them via REST API and return list of created
   objects with filtered attributes.
   """
   objs = BaseRestService(self.endpoint).create_objs(
       count, factory_params, **attrs_for_template)
   assignees = [assignee for obj in objs for assignee in obj.assignees]
   if assignees:
     RelationshipsService().map_objs(
         src_obj=ObjectPersonsFactory().default(), dest_objs=objs,
         attrs={"AssigneeType": ",".join(assignees)})
   return objs
Example #4
0
 def update_obj_attrs_values(obj, is_replace_attrs_values,
                             is_allow_none_values, **arguments):
     """Update object's attributes values."""
     for obj_attr_name in arguments:
         if (obj_attr_name
                 in Entity.get_attrs_names_for_entities(obj.__class__)):
             _obj_attr_value = arguments.get(obj_attr_name)
             condition = (True
                          if is_allow_none_values else _obj_attr_value)
             if condition and not is_replace_values_of_dicts:
                 # convert repr from objects to dicts exclude datetime objects
                 obj_attr_value = (
                     cls.convert_objs_repr_to_dict(_obj_attr_value)
                     if not isinstance(_obj_attr_value, datetime) else
                     _obj_attr_value)
                 if not is_replace_attrs_values:
                     origin_obj_attr_value = getattr(obj, obj_attr_name)
                     obj_attr_value = (
                         dict(origin_obj_attr_value.items() +
                              obj_attr_value.items()) if obj_attr_name
                         == "custom_attributes" else help_utils.
                         convert_to_list(origin_obj_attr_value) +
                         help_utils.convert_to_list(obj_attr_value))
                 setattr(obj, obj_attr_name, obj_attr_value)
                 if obj_attr_name in [
                         "creator", "assignee", "verifier"
                 ]:
                     from lib.entities.entities_factory import ObjectPersonsFactory
                     if not isinstance(obj.assignees, dict):
                         obj.assignees = dict()
                     obj.assignees[obj_attr_name.capitalize()] = ([
                         ObjectPersonsFactory().default().__dict__
                     ])
             if is_replace_values_of_dicts and isinstance(
                     _obj_attr_value, dict):
                 obj_attr_value = StringMethods.exchange_dicts_items(
                     transform_dict=_obj_attr_value,
                     dicts=help_utils.convert_to_list(
                         getattr(obj, obj_attr_name)),
                     is_keys_not_values=False)
                 obj_attr_value = (obj_attr_value if isinstance(
                     getattr(obj, obj_attr_name), list) else
                                   obj_attr_value[0])
                 setattr(obj, obj_attr_name, obj_attr_value)
     return obj