Beispiel #1
0
def create_asmt_template_w_dropdown(audit, dropdown_types_list):
    """Create assessment template with dropdown custom attribute."""
    multi_choice_mandatory = {
        "file": "2",
        "url": "4",
        "comment": "1",
        "file_url": "6",
        "url_comment": "5",
        "file_comment": "3",
        "file_url_comment": "7",
        "nothing": "0"
    }
    ca_definitions_factory = CustomAttributeDefinitionsFactory()
    custom_attribute_definitions = [
        ca_definitions_factory.create(
            title=(ca_definitions_factory.generate_ca_title(
                AdminWidgetCustomAttributes.DROPDOWN)),
            attribute_type=AdminWidgetCustomAttributes.DROPDOWN,
            definition_type=AdminWidgetCustomAttributes.DROPDOWN,
            multi_choice_mandatory=(",".join(
                multi_choice_mandatory[dropdown_type]
                for dropdown_type in dropdown_types_list)),
            multi_choice_options=(StringMethods.random_list_strings(
                list_len=len(dropdown_types_list))))
    ]
    custom_attribute_definitions = (
        ca_definitions_factory.generate_ca_defenitions_for_asmt_tmpls(
            custom_attribute_definitions))
    return create_asmt_template(
        audit, custom_attribute_definitions=custom_attribute_definitions)
 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
         ])
Beispiel #3
0
    def test_asmt_from_template_w_date(self, control_mapped_to_program, audit,
                                       selenium):
        """
    1. Create a program via REST
    2. Create a control within a program via REST
    3. Create an audit within a program via REST
    4. Create an assessment template with Date local custom attribute
     within audit via REST
    5. Generate an assessment from assessment template and control
     snapshot via REST
    6. Open this assessment in UI
    7. Fill Date local custom attribute
    8. Reload page and check that object built from the page looks as expected
    """
        cad = CustomAttributeDefinitionsFactory().create(
            is_add_rest_attrs=True,
            attribute_type=AdminWidgetCustomAttributes.DATE)
        assessment_template = _create_asmt_template(audit=audit,
                                                    assessment_type="Control",
                                                    custom_attributes=[cad])
        exp_asmt = rest_facade.create_assessment_from_template(
            audit=audit,
            template=assessment_template,
            control_snapshots=[control_mapped_to_program])
        asmts_ui_service = webui_service.AssessmentsService(selenium)
        asmts_ui_service.open_info_page_of_obj_fill_lca(exp_asmt)

        act_asmt = self.info_service().get_obj(obj=exp_asmt)
        exp_asmt.update_attrs(updated_at=act_asmt.updated_at,
                              status=act_asmt.status)
        _assert_asmt(asmts_ui_service, exp_asmt, True)
Beispiel #4
0
 def test_asmt_from_template_w_dropdown_url(self, program,
                                            control_mapped_to_program,
                                            audit, selenium):
     """Check evidence url could be filled in
 via Assessment dropdown.
 Objects structure:
 Program.
 -> Control mapped to program.
 -> Audit.
   -> Asmt template with evidence url dropdown.
     -> Autogenerated asmt.
 """
     asmt_template_w_dropdown = rest_facade.create_asmt_template_w_dropdown(
         audit, ["url"])
     expected_asmt = rest_facade.create_asmt_from_template_rest(
         audit, control_mapped_to_program, asmt_template_w_dropdown)
     dropdown = CustomAttributeDefinitionsFactory().create(
         **expected_asmt.cads_from_template()[0])
     asmt_service = webui_service.AssessmentsService(selenium)
     exp_url = StringMethods.random_string(
         size=StringMethods.RANDOM_STR_LENGTH)
     expected_asmt = asmt_service.choose_and_fill_dropdown_lca(
         expected_asmt, dropdown, url=exp_url)
     expected_asmt_urls = [exp_url]
     expected_asmt.update_attrs(
         updated_at=self.info_service().get_obj(
             obj=expected_asmt).updated_at,
         evidence_urls=expected_asmt_urls,
         mapped_objects=[control_mapped_to_program.title],
         status=object_states.IN_PROGRESS).repr_ui()
     actual_asmt = asmt_service.get_obj_from_info_page(obj=expected_asmt)
     self.general_equal_assert(expected_asmt, actual_asmt, "audit")
 def test_fill_asmt_lcas(self, control_mapped_to_program, audit,
                         attr_type, selenium):
   """
   1. Create a program via REST
   2. Create a control within a program via REST
   3. Create an audit within a program via REST
   4. Create an assessment template with each type of
    local custom attribute within audit via REST
   5. Generate an assessment from assessment template and control
    snapshot via REST
   6. Open this assessment in UI
   7. Fill local custom attribute
   8. Reload page and check that object built from the page looks as expected
   """
   asmt_template = rest_facade.create_asmt_template(
       audit=audit, assessment_type="Control", cad_type=attr_type)
   cas = CustomAttributeDefinitionsFactory().generate_custom_attributes([
       Representation.repr_dict_to_obj(cad)
       for cad in asmt_template.custom_attribute_definitions])
   exp_asmt = rest_facade.create_asmt_from_template(
       audit, asmt_template, control_mapped_to_program)
   asmts_ui_service = webui_service.AssessmentsService(selenium)
   asmts_ui_service.fill_asmt_lcas(exp_asmt, cas)
   selenium.refresh()
   act_asmt = self.info_service().get_obj(obj=exp_asmt)
   exp_asmt.update_attrs(updated_at=act_asmt.updated_at,
                         status=unicode(object_states.IN_PROGRESS),
                         mapped_objects=[control_mapped_to_program],
                         custom_attributes=cas)
   _assert_asmt(asmts_ui_service, exp_asmt)
 def test_fill_asmt_gcas_in_popup(
     self, program, gcads_for_asmt, obj, obj_role, selenium
 ):
   """Test for checking population of GCA from UI Edit popup.
   Preconditions:
   - Program created via REST API.
   - Audit created via REST API.
   - Global Custom Attributes for Assessment created via REST API.
   - Assessment created via REST API.
   """
   user = rest_facade.create_user_with_role(roles.CREATOR)
   obj_args = {obj_role: [user]}
   audit = rest_facade.create_audit(
       program, **obj_args if obj == "audit" else {})
   asmt = rest_facade.create_asmt(
       audit, **obj_args if obj == "assessment" else {})
   users.set_current_user(user)
   custom_attributes = CustomAttributeDefinitionsFactory(
   ).generate_custom_attributes(gcads_for_asmt)
   asmts_ui_service = webui_service.AssessmentsService(selenium)
   asmts_ui_service.fill_obj_gcas_in_popup(asmt, custom_attributes)
   act_asmt = rest_facade.get_obj(asmt)
   asmt.update_attrs(
       updated_at=act_asmt.updated_at, status=act_asmt.status,
       custom_attributes=custom_attributes)
   _assert_asmt(asmts_ui_service, asmt)
Beispiel #7
0
 def new_rest_fixture(fixture, factory_params=None):
   """Extract arguments of 'new_rest_fixture' fixture from fixture name,
   create new objects via REST API and return created.
   """
   if "new_cas_for_" in fixture:
     fixture_params = fixture.replace("new_cas_for_", "").replace("_rest", "")
     obj_name = objects.CUSTOM_ATTRIBUTES
     factory_cas_for_objs = [CustomAttributeDefinitionsFactory().create(
         attribute_type=ca_type,
         definition_type=objects.get_singular(fixture_params))
         for ca_type in _list_cas_types]
     new_objs = [
         _new_objs_rest(obj_name=obj_name, obj_count=1, factory_params=dict(
             attribute_type=ca.attribute_type,
             definition_type=ca.definition_type,
             multi_choice_options=ca.multi_choice_options))[0]
         for ca in factory_cas_for_objs]
   else:
     fixture_params = fixture.replace("new_", "").replace("_rest", "")
     has_cas = False
     if "_with_cas" in fixture_params:
       has_cas = True
       fixture_params = fixture_params.replace("_with_cas", "")
     obj_name = fixture_params
     obj_count = batch.COUNT
     if objects.get_plural(obj_name) in objects.ALL_OBJS:
       obj_name = objects.get_plural(obj_name)
       obj_count = 1
     new_objs = _new_objs_rest(obj_name=obj_name, obj_count=obj_count,
                               has_cas=has_cas, factory_params=factory_params)
   return new_objs
Beispiel #8
0
 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
Beispiel #9
0
 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 Global Custom Attributes
   in audit scope.
   Preconditions:
   - Program created via REST API.
   - Audit created via REST API.
   - Global Custom Attributes for Assessment created via REST API.
   - Assessments created via REST API.
   """
   custom_attr_values = (
       CustomAttributeDefinitionsFactory().generate_ca_values(
           list_ca_def_objs=new_cas_for_assessments_rest))
   checkbox_id = Representation.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]})
   self._check_assessments_filtration(expected_asmt, custom_attr_values,
                                      operator, new_audit_rest, selenium)
Beispiel #11
0
 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 set_values_for_assessment(assessment, only_checkbox, checkbox_value):
   """Set LCA values for assessment"""
   cads = [
       CustomAttributeDefinitionsFactory().create(**definition)
       for definition
       in assessment.cads_from_template()]
   return self._set_values_for_assessment(
       assessment, cads, only_checkbox, checkbox_value)
 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_add_global_ca(self, admin_dashboard, ca_type, def_type):
     """Create different types of Custom Attribute on Admin Dashboard."""
     expected_ca = CustomAttributeDefinitionsFactory().create(
         attribute_type=ca_type, definition_type=def_type)
     ca_widget = admin_dashboard.select_custom_attributes()
     ca_widget.add_custom_attribute(ca_obj=expected_ca)
     list_actual_ca = ca_widget.get_custom_attributes_list(
         ca_group=expected_ca)
     assert expected_ca in list_actual_ca
Beispiel #15
0
 def create_dashboard_gcas(self, obj_type, count=1):
     """Create 'Dashboard' CAs via rest according to passed obj_type and count.
 """
     return [
         self.create_objs(
             1,
             CustomAttributeDefinitionsFactory().create_dashboard_ca(
                 obj_type.lower()).__dict__)[0] for _ in xrange(count)
     ]
 def set_values_for_assessment(assessment, only_checkbox, checkbox_value):
   """Set LCA values for assessment"""
   custom_attr_definitions = [
       CustomAttributeDefinitionsFactory().create(**definition)
       for definition
       in assessment.cads_from_template()]
   checkbox_id = Representation.filter_objs_by_attrs(
       objs=custom_attr_definitions,
       attribute_type=element.AdminWidgetCustomAttributes.CHECKBOX).id
   if only_checkbox:
     attr_values = {}
   else:
     attr_values = CustomAttributeDefinitionsFactory().generate_ca_values(
         list_ca_def_objs=custom_attr_definitions)
     attr_values[checkbox_id] = checkbox_value
   rest_service.AssessmentsService().update_obj(
       obj=assessment, custom_attributes=attr_values)
   return attr_values
 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
Beispiel #18
0
 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_ca_value(
         checkbox_cad, checkbox_value)]
   else:
     cavs = CustomAttributeDefinitionsFactory.generate_ca_values(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 _set_custom_attributes_list(self):
   """Set custom attributes list with Custom Attribute objects from
   current opened content item.
   """
   for row in selenium_utils.get_when_all_visible(self._driver,
                                                  self._locators.ROW_CSS):
     attrs = [i.text for i in row.find_elements(
         *self._locators.CELL_IN_ROW_CSS)]
     # todo: add PO and getting 'multi_choice_options' via 'Edit' btn
     self.custom_attributes_list.append(
         CustomAttributeDefinitionsFactory().create(
             title=attrs[0], attribute_type=attrs[1],
             mandatory=StringMethods.get_bool_value_from_arg(attrs[2]),
             definition_type=self._item_name, multi_choice_options=None))
Beispiel #20
0
def create_asmt_template_w_dropdown(audit, dropdown_types_list):
  """Create assessment template with dropdown custom attribute."""
  multi_choice_mandatory = {"file": "2", "url": "4", "comment": "1",
                            "file_url": "6", "url_comment": "5",
                            "file_comment": "3", "file_url_comment": "7",
                            "nothing": "0"}
  ca_definitions_factory = CustomAttributeDefinitionsFactory()
  custom_attribute_definitions = [ca_definitions_factory.create(
      title=(ca_definitions_factory.generate_ca_title(
          AdminWidgetCustomAttributes.DROPDOWN)),
      attribute_type=AdminWidgetCustomAttributes.DROPDOWN,
      definition_type=AdminWidgetCustomAttributes.DROPDOWN,
      multi_choice_mandatory=(",".join(
          multi_choice_mandatory[dropdown_type]
          for dropdown_type in dropdown_types_list)),
      multi_choice_options=(
          StringMethods.random_list_strings(
              list_len=len(dropdown_types_list))))]
  custom_attribute_definitions = (ca_definitions_factory.
                                  generate_ca_defenitions_for_asmt_tmpls(
                                      custom_attribute_definitions))
  return create_asmt_template(
      audit, custom_attribute_definitions=custom_attribute_definitions)
 def test_asmt_from_template_w_dropdown_comment(self, program,
                                                control_mapped_to_program,
                                                audit, selenium):
     """Check evidence comment could be filled in
 via Assessment dropdown.
 Objects structure:
 Program.
 -> Control mapped to program.
 -> Audit.
   -> Asmt template with evidence comment dropdown.
     -> Autogenerated asmt.
 """
     asmt_template_w_dropdown = rest_facade.create_asmt_template_w_dropdown(
         audit, ["comment"])
     expected_asmt = rest_facade.create_asmt_from_template_rest(
         audit, control_mapped_to_program, asmt_template_w_dropdown)
     dropdown = CustomAttributeDefinitionsFactory().create(
         **expected_asmt.cads_from_template()[0])
     asmt_service = webui_service.AssessmentsService(selenium)
     expected_asmt_comments = [entities_factory.CommentsFactory().create()]
     asmt_service.choose_and_fill_dropdown_lca(
         expected_asmt,
         dropdown.id,
         dropdown.multi_choice_options,
         comment=expected_asmt_comments[0].description)
     expected_asmt_comments = [
         expected_comment.update_attrs(created_at=self.info_service(
         ).get_comment_obj(paren_obj=expected_asmt,
                           comment_description=expected_comment.description
                           ).created_at).repr_ui()
         for expected_comment in expected_asmt_comments
     ]
     expected_asmt.update_attrs(
         updated_at=self.info_service().get_obj(
             obj=expected_asmt).updated_at,
         comments=expected_asmt_comments,
         mapped_objects=[control_mapped_to_program.title],
         status=AssessmentStates.IN_PROGRESS).repr_ui()
     expected_asmt_comments_descriptions = [
         comment.description for comment in expected_asmt_comments
     ]
     actual_asmt = asmt_service.get_obj_from_info_page(obj=expected_asmt)
     actual_asmt_comments_descriptions = [
         comment["description"] for comment in actual_asmt.comments
     ]
     self.general_equal_assert(expected_asmt, actual_asmt, "audit",
                               "comments")
     assert expected_asmt_comments_descriptions \
         == actual_asmt_comments_descriptions
Beispiel #22
0
 def test_set_comment_for_dropdown_lca(self, program,
                                       control_mapped_to_program,
                                       login_role, obj, obj_role, selenium):
     """Check evidence comment could be filled in
 via Assessment dropdown.
 Objects structure:
 Program.
 -> Control mapped to program.
 -> Audit.
   -> Asmt template with evidence comment dropdown.
     -> Autogenerated asmt.
 """
     # pylint: disable=too-many-locals
     user = rest_facade.create_user_with_role(login_role)
     obj_args = {obj_role: [user]}
     audit = rest_facade.create_audit(program,
                                      **obj_args if obj == "audit" else {})
     comment_text = entities_factory.CommentsFactory().create().description
     asmt_template_w_dropdown = rest_facade.create_asmt_template(
         audit,
         cad_type=AdminWidgetCustomAttributes.DROPDOWN,
         dropdown_types_list=["comment"],
         **obj_args if obj == "assessment" else {})
     expected_asmt = rest_facade.create_asmt_from_template(
         audit, asmt_template_w_dropdown, [control_mapped_to_program])
     dropdown = CustomAttributeDefinitionsFactory().create(
         **expected_asmt.cads_from_template()[0])
     users.set_current_user(user)
     asmt_service = webui_service.AssessmentsService(selenium)
     asmt_service.choose_and_fill_dropdown_lca(expected_asmt,
                                               dropdown,
                                               comment=comment_text)
     rest_asmt_obj = self.info_service().get_obj(obj=expected_asmt)
     expected_asmt.update_attrs(
         custom_attributes={
             dropdown.title.upper(): dropdown.multi_choice_options
         },
         updated_at=rest_asmt_obj.updated_at,
         modified_by=rest_asmt_obj.modified_by,
         mapped_objects=[control_mapped_to_program.title],
         status=object_states.IN_PROGRESS).repr_ui()
     actual_asmt = asmt_service.get_obj_from_info_page(obj=expected_asmt)
     actual_comment_texts = [
         comment["description"] for comment in actual_asmt.comments
     ]
     self.general_equal_assert(expected_asmt, actual_asmt, "audit",
                               "comments")
     assert actual_comment_texts == [comment_text]
Beispiel #23
0
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)}
Beispiel #24
0
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)}
Beispiel #25
0
 def test_set_url_for_dropdown_lca(self, program, control_mapped_to_program,
                                   login_role, obj, obj_role, selenium):
     """Check evidence url could be filled in
 via Assessment dropdown.
 Objects structure:
 Program.
 -> Control mapped to program.
 -> Audit.
   -> Asmt template with evidence url dropdown.
     -> Autogenerated asmt.
 """
     user = rest_facade.create_user_with_role(login_role)
     obj_args = {obj_role: [user]}
     audit = rest_facade.create_audit(program,
                                      **obj_args if obj == "audit" else {})
     url = StringMethods.random_string()
     asmt_template_w_dropdown = rest_facade.create_asmt_template(
         audit,
         cad_type=AdminWidgetCustomAttributes.DROPDOWN,
         dropdown_types_list=["url"],
         **obj_args if obj == "assessment" else {})
     expected_asmt = rest_facade.create_asmt_from_template(
         audit, asmt_template_w_dropdown, [control_mapped_to_program])
     dropdown = CustomAttributeDefinitionsFactory().create(
         **expected_asmt.cads_from_template()[0])
     users.set_current_user(user)
     asmt_service = webui_service.AssessmentsService(selenium)
     asmt_service.choose_and_fill_dropdown_lca(expected_asmt,
                                               dropdown,
                                               url=url)
     rest_asmt_obj = self.info_service().get_obj(expected_asmt)
     expected_asmt.update_attrs(
         custom_attributes={
             dropdown.title.upper(): dropdown.multi_choice_options
         },
         updated_at=rest_asmt_obj.updated_at,
         modified_by=rest_asmt_obj.modified_by,
         evidence_urls=[url],
         mapped_objects=[control_mapped_to_program.title],
         status=object_states.IN_PROGRESS)
     _assert_asmt(asmt_service, expected_asmt)
 def test_fill_asmt_gcas_inline(self, program, audit, assessment, attr_type,
                                selenium):
     """Test for checking population of GCA from UI inline fields.
 Preconditions:
 - Program created via REST API.
 - Audit created via REST API.
 - Global Custom Attributes for Assessment created via REST API.
 - Assessment created via REST API.
 """
     gcad = rest_facade.create_gcad(definition_type="assessment",
                                    attribute_type=attr_type)
     custom_attributes = CustomAttributeDefinitionsFactory(
     ).generate_custom_attributes([gcad])
     asmts_ui_service = webui_service.AssessmentsService(selenium)
     asmts_ui_service.fill_obj_gcas_inline(assessment, custom_attributes)
     selenium.refresh()
     actual_asmt = rest_facade.get_obj(assessment)
     assessment.update_attrs(updated_at=actual_asmt.updated_at,
                             status=actual_asmt.status,
                             custom_attributes=custom_attributes)
     _assert_asmt(asmts_ui_service, assessment)
Beispiel #27
0
 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_ca_values(
                   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
Beispiel #28
0
 def convert_repr_rest_to_ui(obj):
   """Convert object's attributes from REST to UI like representation."""
   def convert_attr_val_repr_dict_to_unicode(attr_name, attr_value):
     """Convert attribute value from dictionary to unicode representation
     (get value by key from dictionary 'attr_value' where key determine
     according to 'attr_name').
     """
     if isinstance(attr_value, dict):
       converted_attr_value = attr_value
       if attr_name in Representation.people_attrs_names + [
           "created_by", "modified_by"
       ]:
         converted_attr_value = unicode(attr_value.get("email"))
       if attr_name in ["custom_attribute_definitions", "program", "audit",
                        "mapped_objects"]:
         converted_attr_value = (
             unicode(attr_value.get("title")) if
             attr_name != "custom_attribute_definitions" else
             {attr_value.get("id"): attr_value.get("title").upper()}
         )
       if attr_name in ["custom_attribute_values"]:
         converted_attr_value = {attr_value.get("custom_attribute_id"):
                                 attr_value.get("attribute_value")}
       if obj_attr_name == "comments":
         converted_attr_value = {
             k: (parser.parse(v).replace(tzinfo=tz.tzutc()) if
                 k == "created_at" and isinstance(v, unicode) else v)
             for k, v in attr_value.iteritems()
             if k in ["modified_by", "created_at", "description"]}
       if attr_name == "assertions":
         for name, assertion_id in ControlEntity.ASSERTIONS.iteritems():
           if assertion_id == attr_value["id"]:
             converted_attr_value = name
       return converted_attr_value
   origin_obj = copy.deepcopy(obj)
   for obj_attr_name in obj.__dict__.keys():
     # 'Ex', u'Ex', 1, None to 'Ex', u'Ex', 1, None
     obj_attr_value = getattr(obj, obj_attr_name)
     # REST like u'08-20-2017T04:30:45' to date=2017-08-20,
     # timetz=04:30:45+00:00
     if (obj_attr_name in ["updated_at", "created_at"] and
             isinstance(obj_attr_value, unicode)):
       obj_attr_value = (parser.parse(obj_attr_value).
                         replace(tzinfo=tz.tzutc()))
     if isinstance(obj_attr_value, dict) and obj_attr_value:
       # "modified_by" {"type": "Person", "id": x} to u'*****@*****.**'
       # todo: deprecated?
       if obj_attr_name == "modified_by":
         from lib.service import rest_service
         obj_attr_value = getattr(rest_service.ObjectsInfoService().get_obj(
             obj=Representation.repr_dict_to_obj(obj_attr_value)), "email")
       # {'name': u'Ex1', 'type': u'Ex2', ...} to u'Ex1'
       else:
         obj_attr_value = convert_attr_val_repr_dict_to_unicode(
             obj_attr_name, obj_attr_value)
     # [el1, el2, ...] or [{item1}, {item2}, ...] to [u'Ex1, u'Ex2', ...]
     if (isinstance(obj_attr_value, list) and
             all(isinstance(item, dict) for item in obj_attr_value)):
       obj_attr_value = [
           convert_attr_val_repr_dict_to_unicode(obj_attr_name, item) for
           item in obj_attr_value]
     setattr(obj, obj_attr_name, obj_attr_value)
   # merge "custom_attribute_definitions" and "custom_attribute_values"
   obj_cas_attrs_names = [
       "custom_attributes", "custom_attribute_definitions",
       "custom_attribute_values"]
   if set(obj_cas_attrs_names).issubset(obj.__dict__.keys()):
     cas_def = obj.custom_attribute_definitions
     cas_val = obj.custom_attribute_values
     # form CAs values of CAs definitions exist but CAs values not, or CAs
     # definitions have different then CAs values lengths
     if (cas_def and
             (not cas_val or (isinstance(cas_def and cas_val, list)) and
              len(cas_def) != len(cas_val))):
       from lib.entities.entities_factory import (
           CustomAttributeDefinitionsFactory)
       cas_val_dicts_keys = ([_.keys()[0] for _ in cas_val] if
                             isinstance(cas_val, list) else [None])
       _cas_val = [
           {k: v} for k, v in
           CustomAttributeDefinitionsFactory.generate_ca_title_id(
               [Representation.repr_dict_to_obj(cad)
                for cad in origin_obj.custom_attribute_definitions]
           ).iteritems() if k not in cas_val_dicts_keys]
       cas_val = _cas_val if not cas_val else cas_val + _cas_val
     cas_def_dict = (
         dict([_def.iteritems().next() for _def in cas_def]) if
         (isinstance(cas_def, list) and
          all(isinstance(_def, dict)
              for _def in cas_def)) else None)
     cas_val_dict = (
         dict([_val.iteritems().next() for _val in cas_val]) if
         (isinstance(cas_def, list) and
          all(isinstance(_def, dict)
              for _def in cas_def)) else None)
     cas = StringMethods.merge_dicts_by_same_key(cas_def_dict, cas_val_dict)
     if obj.custom_attributes:
       cas.update(obj.custom_attributes)
     if cas in [{None: None}, {}]:
       cas = None
     setattr(obj, "custom_attributes", cas)
   return obj
Beispiel #29
0
 def convert_obj_repr_from_rest_to_ui(obj):
   """Convert object's attributes from REST to UI like representation."""
   def convert_attr_value_from_dict_to_unicode(attr_name, attr_value):
     """Convert attribute value from dictionary to unicode representation
     (get value by key from dictionary 'attr_value' where key determine
     according to 'attr_name').
     """
     if isinstance(attr_value, dict):
       converted_attr_value = attr_value
       if attr_name in [
           "contact", "manager", "owners", "assignee", "creator",
           "verifier", "created_by", "modified_by", "Assignee", "Creator",
           "Verifier"
       ]:
         converted_attr_value = unicode(attr_value.get("email"))
       if attr_name in ["custom_attribute_definitions", "program", "audit",
                        "objects_under_assessment"]:
         converted_attr_value = (
             unicode(attr_value.get("title")) if
             attr_name != "custom_attribute_definitions" else
             {attr_value.get("id"): attr_value.get("title").upper()}
         )
       if attr_name in ["custom_attribute_values"]:
         converted_attr_value = {attr_value.get("custom_attribute_id"):
                                 attr_value.get("attribute_value")}
       if obj_attr_name == "comments":
         converted_attr_value = {
             k: (parser.parse(v).replace(tzinfo=tz.tzutc()) if
                 k == "created_at" and isinstance(v, unicode) else v)
             for k, v in attr_value.iteritems()
             if k in ["modified_by", "created_at", "description"]}
       return converted_attr_value
   origin_obj = copy.deepcopy(obj)
   for obj_attr_name in obj.__dict__.keys():
     # 'Ex', u'Ex', 1, None to 'Ex', u'Ex', 1, None
     obj_attr_value = (obj.assignees.get(obj_attr_name.title()) if (
         obj_attr_name in ["assignee", "creator", "verifier"] and
         "assignees" in obj.__dict__.keys())
         else getattr(obj, obj_attr_name))
     # REST like u'08-20-2017T04:30:45' to date=2017-08-20,
     # timetz=04:30:45+00:00
     if (obj_attr_name in ["updated_at", "created_at"] and
             isinstance(obj_attr_value, unicode)):
       obj_attr_value = (parser.parse(obj_attr_value).
                         replace(tzinfo=tz.tzutc()))
     if isinstance(obj_attr_value, dict) and obj_attr_value:
       # to "assignees" = {"Assignee": [], "Creator": [], "Verifier": []}
       if obj_attr_name == "assignees":
         obj_attr_value = {
             k: ([convert_attr_value_from_dict_to_unicode(k, _v)
                  for _v in v] if isinstance(v, list) else
                 convert_attr_value_from_dict_to_unicode(k, v))
             for k, v in obj_attr_value.iteritems()
             if k in ["Assignee", "Creator", "Verifier"]}
       # "modified_by" {"type": "Person", "id": x} to u'*****@*****.**'
       if obj_attr_name == "modified_by":
         from lib.service import rest_service
         obj_attr_value = getattr(rest_service.ObjectsInfoService().get_obj(
             obj=Entity.convert_dict_to_obj_repr(obj_attr_value)), "email")
       # {'name': u'Ex1', 'type': u'Ex2', ...} to u'Ex1'
       else:
         obj_attr_value = convert_attr_value_from_dict_to_unicode(
             obj_attr_name, obj_attr_value)
     # [el1, el2, ...] or [{item1}, {item2}, ...] to [u'Ex1, u'Ex2', ...]
     if (isinstance(obj_attr_value, list) and
             all(isinstance(item, dict) for item in obj_attr_value)):
       obj_attr_value = [
           convert_attr_value_from_dict_to_unicode(obj_attr_name, item) for
           item in obj_attr_value]
     setattr(obj, obj_attr_name, obj_attr_value)
   # merge "custom_attribute_definitions" and "custom_attribute_values"
   obj_cas_attrs_names = [
       "custom_attributes", "custom_attribute_definitions",
       "custom_attribute_values"]
   if set(obj_cas_attrs_names).issubset(obj.__dict__.keys()):
     cas_def = obj.custom_attribute_definitions
     cas_val = obj.custom_attribute_values
     # form CAs values of CAs definitions exist but CAs values not, or CAs
     # definitions have different then CAs values lengths
     if (cas_def and
             (not cas_val or (isinstance(cas_def and cas_val, list)) and
              len(cas_def) != len(cas_val))):
       from lib.entities.entities_factory import (
           CustomAttributeDefinitionsFactory)
       cas_val_dicts_keys = ([_.keys()[0] for _ in cas_val] if
                             isinstance(cas_val, list) else [None])
       _cas_val = [
           {k: v} for k, v in
           CustomAttributeDefinitionsFactory.generate_ca_values(
               list_ca_def_objs=origin_obj.custom_attribute_definitions,
               is_none_values=True).iteritems()
           if k not in cas_val_dicts_keys]
       cas_val = _cas_val if not cas_val else cas_val + _cas_val
     cas_def_dict = (
         dict([_def.iteritems().next() for _def in cas_def]) if
         (isinstance(cas_def, list) and
          all(isinstance(_def, dict)
              for _def in cas_def)) else {None: None})
     cas_val_dict = (
         dict([_val.iteritems().next() for _val in cas_val]) if
         (isinstance(cas_def, list) and
          all(isinstance(_def, dict)
              for _def in cas_def)) else {None: None})
     cas = StringMethods.merge_dicts_by_same_key(cas_def_dict, cas_val_dict)
     setattr(obj, "custom_attributes", cas)
   return obj
Beispiel #30
0
def _new_objs_rest(obj_name, obj_count, has_cas=False, factory_params=None):
  """Create new objects via REST API according to object name (plural form),
  objects count and requirements for presence of Custom Attributes.
  Return: [lib.entities.entity.*Entity, ...]
  """
  # pylint: disable=unused-argument
  global dict_executed_fixtures
  _list_cas_types = element.AdminWidgetCustomAttributes.ALL_CA_TYPES

  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 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])

  parent_obj_name = None
  if obj_name == objects.AUDITS:
    parent_obj_name = (objects.get_singular(objects.PROGRAMS) if obj_count == 1
                       else objects.PROGRAMS)
  if obj_name in (objects.ASSESSMENT_TEMPLATES, objects.ASSESSMENTS,
                  objects.ISSUES):
    parent_obj_name = (objects.get_singular(objects.AUDITS) if obj_count == 1
                       else objects.AUDITS)
  if (has_cas and obj_name in objects.ALL_OBJS and
          obj_name not in objects.ASSESSMENT_TEMPLATES):
    parent_obj_name = "cas_for_" + obj_name
  if parent_obj_name:
    parent_objs = _get_fixture_from_dict_fixtures(
        fixture="new_{}_rest".format(parent_obj_name))
    if has_cas and obj_name in objects.ASSESSMENT_TEMPLATES:
      parent_objs = (
          [CustomAttributeDefinitionsFactory().create(
              attribute_type=ca_type, definition_type="") for
              ca_type in _list_cas_types] + parent_objs)
    objs = create_objs_rest_used_exta_arrts(
        name=obj_name, factory_params=factory_params, extra_attrs=parent_objs)
  else:
    objs = create_objs_rest(
        name=obj_name, count=obj_count, factory_params=factory_params)
  return objs
Beispiel #31
0
 def convert_obj_repr_from_rest_to_ui(obj):
   """Convert object's attributes from REST to UI like representation."""
   def convert_attr_value_from_dict_to_unicode(attr_name, attr_value):
     """Convert attribute value from dictionary to unicode representation
     (get value by key from dictionary 'attr_value' where key determine
     according to 'attr_name').
     """
     if isinstance(attr_value, dict):
       converted_attr_value = attr_value
       if attr_name in [
           "contact", "manager", "owners", "assessor", "creator",
           "verifier", "created_by", "modified_by", "Assessor", "Creator",
           "Verifier"
       ]:
         converted_attr_value = unicode(attr_value.get("email"))
       if attr_name in ["custom_attribute_definitions", "program", "audit",
                        "objects_under_assessment"]:
         converted_attr_value = (
             unicode(attr_value.get("title")) if
             attr_name != "custom_attribute_definitions" else
             {attr_value.get("id"): attr_value.get("title").upper()}
         )
       if attr_name in ["custom_attribute_values"]:
         converted_attr_value = {attr_value.get("custom_attribute_id"):
                                 attr_value.get("attribute_value")}
       if obj_attr_name == "comments":
         converted_attr_value = {
             k: (parser.parse(v).replace(tzinfo=tz.tzutc()) if
                 k == "created_at" and isinstance(v, unicode) else v)
             for k, v in attr_value.iteritems()
             if k in ["modified_by", "created_at", "description"]}
       return converted_attr_value
   origin_obj = copy.deepcopy(obj)
   for obj_attr_name in obj.__dict__.keys():
     # 'Ex', u'Ex', 1, None to 'Ex', u'Ex', 1, None
     obj_attr_value = (obj.assignees.get(obj_attr_name.title()) if (
         obj_attr_name in ["assessor", "creator", "verifier"] and
         "assignees" in obj.__dict__.keys())
         else getattr(obj, obj_attr_name))
     # REST like u'08-20-2017T04:30:45' to date=2017-08-20,
     # timetz=04:30:45+00:00
     if (obj_attr_name in ["updated_at", "created_at"] and
             isinstance(obj_attr_value, unicode)):
       obj_attr_value = (parser.parse(obj_attr_value).
                         replace(tzinfo=tz.tzutc()))
     if isinstance(obj_attr_value, dict) and obj_attr_value:
       # to "assignees" = {"Assessor": [], "Creator": [], "Verifier": []}
       if obj_attr_name == "assignees":
         obj_attr_value = {
             k: ([convert_attr_value_from_dict_to_unicode(k, _v)
                  for _v in v] if isinstance(v, list) else
                 convert_attr_value_from_dict_to_unicode(k, v))
             for k, v in obj_attr_value.iteritems()
             if k in ["Assessor", "Creator", "Verifier"]}
       # "modified_by" {"type": "Person", "id": x} to u'*****@*****.**'
       if obj_attr_name == "modified_by":
         from lib.service import rest_service
         obj_attr_value = getattr(rest_service.ObjectsInfoService().get_obj(
             obj=Entity.convert_dict_to_obj_repr(obj_attr_value)), "email")
       # {'name': u'Ex1', 'type': u'Ex2', ...} to u'Ex1'
       else:
         obj_attr_value = convert_attr_value_from_dict_to_unicode(
             obj_attr_name, obj_attr_value)
     # [el1, el2, ...] or [{item1}, {item2}, ...] to [u'Ex1, u'Ex2', ...]
     if (isinstance(obj_attr_value, list) and
             all(isinstance(item, dict) for item in obj_attr_value)):
       obj_attr_value = [
           convert_attr_value_from_dict_to_unicode(obj_attr_name, item) for
           item in obj_attr_value]
     setattr(obj, obj_attr_name, obj_attr_value)
   # merge "custom_attribute_definitions" and "custom_attribute_values"
   obj_cas_attrs_names = [
       "custom_attributes", "custom_attribute_definitions",
       "custom_attribute_values"]
   if set(obj_cas_attrs_names).issubset(obj.__dict__.keys()):
     cas_def = obj.custom_attribute_definitions
     cas_val = obj.custom_attribute_values
     # form CAs values of CAs definitions exist but CAs values not, or CAs
     # definitions have different then CAs values lengths
     if (cas_def and
             (not cas_val or (isinstance(cas_def and cas_val, list)) and
              len(cas_def) != len(cas_val))):
       from lib.entities.entities_factory import (
           CustomAttributeDefinitionsFactory)
       cas_val_dicts_keys = ([_.keys()[0] for _ in cas_val] if
                             isinstance(cas_val, list) else [None])
       _cas_val = [
           {k: v} for k, v in
           CustomAttributeDefinitionsFactory.generate_ca_values(
               list_ca_def_objs=origin_obj.custom_attribute_definitions,
               is_none_values=True).iteritems()
           if k not in cas_val_dicts_keys]
       cas_val = _cas_val if not cas_val else cas_val + _cas_val
     cas_def_dict = (
         dict([_def.iteritems().next() for _def in cas_def]) if
         (isinstance(cas_def, list) and
          all(isinstance(_def, dict)
              for _def in cas_def)) else {None: None})
     cas_val_dict = (
         dict([_val.iteritems().next() for _val in cas_val]) if
         (isinstance(cas_def, list) and
          all(isinstance(_def, dict)
              for _def in cas_def)) else {None: None})
     cas = string_utils.merge_dicts_by_same_key(cas_def_dict, cas_val_dict)
     setattr(obj, "custom_attributes", cas)
   return obj