Пример #1
0
 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)
Пример #2
0
 def get_obj(self, obj):
   """Get and return object according to 'obj.type' and 'obj.id'."""
   obj_dict = (BaseRestService.get_items_from_resp(self.client.create_object(
       type=self.endpoint, object_name=unicode(obj.type),
       filters=query.Query.expression_get_obj_by_id(obj.id))).get(
       "values")[0])
   return Representation.repr_dict_to_obj(obj_dict)
Пример #3
0
 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
Пример #4
0
 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
Пример #5
0
 def get_filter_exprs_by_ca(self, ca_title, ca_val, ca_type, operator):
     """Return all possible filter expressions for CA according to CA type"""
     if ca_type == AdminWidgetCustomAttributes.CHECKBOX:
         values_to_filter = (StringMethods.get_list_of_all_cases(
             alias.YES_VAL) if StringMethods.get_bool_value_from_arg(ca_val)
                             else StringMethods.get_list_of_all_cases(
                                 alias.NO_VAL))
     elif ca_type == AdminWidgetCustomAttributes.PERSON:
         from lib.service import rest_service
         person = rest_service.ObjectsInfoService().get_obj(
             obj=Representation.repr_dict_to_obj(
                 dict(zip(["type", "id"], ca_val.split(":")))))
         values_to_filter = [person.name, person.email]
     elif ca_type == AdminWidgetCustomAttributes.DATE:
         date_formats = ["%m/%d/%Y", "%m/%Y", "%Y-%m-%d", "%Y-%m", "%Y"]
         date = parser.parse(ca_val).date()
         values_to_filter = [
             date.strftime(_format) for _format in date_formats
         ]
     else:
         values_to_filter = [ca_val]
     return [
         self.get_filter_exp(ca_title, operator, [val])
         for val in values_to_filter
     ]
Пример #6
0
    def get_snapshoted_obj(self, origin_obj, paren_obj):
        """Get and return snapshoted object according to 'origin_obj' and
    'paren_obj'.
    """
        def get_response():
            """Get response from query."""
            return self.client.create_object(
                type=self.endpoint,
                object_name=objects.get_obj_type(objects.SNAPSHOTS),
                filters=query.Query.expression_get_snapshoted_obj(
                    obj_type=origin_obj.type,
                    obj_id=origin_obj.id,
                    parent_type=paren_obj.type,
                    parent_id=paren_obj.id))

        def get_response_values():
            """Get values fom responese."""
            return json.loads(get_response().text,
                              encoding="utf-8")[0]["Snapshot"]["values"]

        test_utils.wait_for(get_response_values,
                            constants.ux.MAX_USER_WAIT_SECONDS * 2)
        snapshoted_obj_dict = (BaseRestService.get_items_from_resp(
            get_response()).get("values")[0])
        return Representation.repr_dict_to_obj(snapshoted_obj_dict)
Пример #7
0
 def get_obj(self, obj):
   """Get and return object according to 'obj.type' and 'obj.id'."""
   obj_dict = (BaseRestService.get_items_from_resp(self.client.create_object(
       type=self.endpoint, object_name=unicode(obj.type),
       filters=query.Query.expression_get_obj_by_id(obj.id))).get(
       "values")[0])
   return Representation.repr_dict_to_obj(obj_dict)
Пример #8
0
    def get_obj(self, obj):
        """Get and return object according to 'obj.type' and 'obj.id'."""
        @test_utils.wait_for
        def get_obj_response_values():
            """Get values fom response."""
            obj_type = obj.type if hasattr(obj, "type") else obj.obj_type()
            obj_id = obj.id if hasattr(obj, "id") else obj.obj_id
            filters = query.Query.expression_get_obj_by_id(obj_id)
            return self.get_obj_dict(obj_type, filters=filters)

        return Representation.repr_dict_to_obj(get_obj_response_values[0])
Пример #9
0
 def get_snapshoted_obj(self, origin_obj, paren_obj):
   """Get and return snapshoted object according to 'origin_obj' and
   'paren_obj'.
   """
   snapshoted_obj_dict = (
       BaseRestService.get_items_from_resp(self.client.create_object(
           type=self.endpoint,
           object_name=objects.get_obj_type(objects.SNAPSHOTS),
           filters=query.Query.expression_get_snapshoted_obj(
               obj_type=origin_obj.type, obj_id=origin_obj.id,
               parent_type=paren_obj.type,
               parent_id=paren_obj.id))).get("values")[0])
   return Representation.repr_dict_to_obj(snapshoted_obj_dict)
Пример #10
0
 def get_snapshoted_obj(self, origin_obj, paren_obj):
   """Get and return snapshoted object according to 'origin_obj' and
   'paren_obj'.
   """
   snapshoted_obj_dict = (
       BaseRestService.get_items_from_resp(self.client.create_object(
           type=self.endpoint,
           object_name=objects.get_obj_type(objects.SNAPSHOTS),
           filters=query.Query.expression_get_snapshoted_obj(
               obj_type=origin_obj.type, obj_id=origin_obj.id,
               parent_type=paren_obj.type,
               parent_id=paren_obj.id))).get("values")[0])
   return Representation.repr_dict_to_obj(snapshoted_obj_dict)
Пример #11
0
  def get_obj(self, obj):
    """Get and return object according to 'obj.type' and 'obj.id'."""

    @test_utils.wait_for
    def get_obj_response_values():
      """Get values fom response."""
      obj_type = obj.type if hasattr(obj, "type") else obj.obj_type()
      obj_id = obj.id if hasattr(obj, "id") else obj.obj_id
      filters = query.Query.expression_get_obj_by_id(obj_id)
      obj_resp = self.get_obj_dict(obj_type, filters=filters)
      # Update object href that used in entities.
      obj_resp[0]["href"] = obj_resp[0]["selfLink"]
      return obj_resp
    return Representation.repr_dict_to_obj(get_obj_response_values[0])
Пример #12
0
 def get_comment_obj(self, paren_obj, comment_description):
   """Get and return comment object according to 'paren_obj' type) and
   comment_description 'paren_obj'. As default 'is_sort_by_created_at' and if
   even comments have the same descriptions query return selection w/ latest
   created datetime.
   """
   comment_obj_dict = (
       BaseRestService.get_items_from_resp(self.client.create_object(
           type=self.endpoint,
           object_name=objects.get_obj_type(objects.COMMENTS),
           filters=query.Query.expression_get_comment_by_desc(
               parent_type=paren_obj.type, parent_id=paren_obj.id,
               comment_desc=comment_description),
           order_by=[{"name": "created_at", "desc": True}])).get("values")[0])
   return Representation.repr_dict_to_obj(comment_obj_dict)
Пример #13
0
 def get_comment_obj(self, paren_obj, comment_description):
   """Get and return comment object according to 'paren_obj' type) and
   comment_description 'paren_obj'. As default 'is_sort_by_created_at' and if
   even comments have the same descriptions query return selection w/ latest
   created datetime.
   """
   comment_obj_dict = (
       BaseRestService.get_items_from_resp(self.client.create_object(
           type=self.endpoint,
           object_name=objects.get_obj_type(objects.COMMENTS),
           filters=query.Query.expression_get_comment_by_desc(
               parent_type=paren_obj.type, parent_id=paren_obj.id,
               comment_desc=comment_description),
           order_by=[{"name": "created_at", "desc": True}])).get("values")[0])
   return Representation.repr_dict_to_obj(comment_obj_dict)
Пример #14
0
  def get_snapshoted_obj(self, origin_obj, paren_obj):
    """Get and return snapshoted object according to 'origin_obj' and
    'paren_obj'.
    """
    @test_utils.wait_for
    def get_snapshoted_obj_response_values():
      """Get values fom response."""
      # pylint: disable=invalid-name
      filters = query.Query.expression_get_snapshoted_obj(
          obj_type=origin_obj.type, obj_id=origin_obj.id,
          parent_type=paren_obj.type, parent_id=paren_obj.id)
      return self.get_obj_dict(
          objects.get_obj_type(objects.SNAPSHOTS), filters=filters)

    return Representation.repr_dict_to_obj(
        get_snapshoted_obj_response_values[0])
Пример #15
0
  def get_comment_obj(self, paren_obj, comment_description):
    """Get and return comment object according to 'paren_obj' type) and
    comment_description 'paren_obj'. As default 'is_sort_by_created_at' and if
    even comments have the same descriptions query return selection w/ latest
    created datetime.
    """
    @test_utils.wait_for
    def get_obj_comment_response_values():
      """Get values fom response."""
      # pylint: disable=invalid-name
      filters = query.Query.expression_get_comment_by_desc(
          parent_type=paren_obj.type, parent_id=paren_obj.id,
          comment_desc=comment_description)
      order_by = [{"name": "created_at", "desc": True}]
      return self.get_obj_dict(objects.get_obj_type(objects.COMMENTS),
                               filters=filters, order_by=order_by)

    return Representation.repr_dict_to_obj(get_obj_comment_response_values[0])
Пример #16
0
    def get_snapshoted_obj(self, origin_obj, paren_obj):
        """Get and return snapshoted object according to 'origin_obj' and
    'paren_obj'.
    """
        @test_utils.wait_for
        def get_snapshoted_obj_response_values():
            """Get values fom response."""
            # pylint: disable=invalid-name
            filters = query.Query.expression_get_snapshoted_obj(
                obj_type=origin_obj.type,
                obj_id=origin_obj.id,
                parent_type=paren_obj.type,
                parent_id=paren_obj.id)
            return self.get_obj_dict(objects.get_obj_type(objects.SNAPSHOTS),
                                     filters=filters)

        return Representation.repr_dict_to_obj(
            get_snapshoted_obj_response_values[0])
Пример #17
0
 def get_filter_exprs_by_ca(self, cad, cav, operator):
   """Return all possible filter expressions for CA according to CA type"""
   ca_type = cad.attribute_type
   if ca_type == AdminWidgetCustomAttributes.CHECKBOX:
     value = alias.YES_VAL if StringMethods.get_bool_value_from_arg(
         cav.attribute_value) else alias.NO_VAL
     values_to_filter = StringMethods.get_list_of_all_cases(value)
   elif ca_type == AdminWidgetCustomAttributes.PERSON:
     from lib.service import rest_service
     person = rest_service.ObjectsInfoService().get_obj(
         obj=Representation.repr_dict_to_obj(cav.attribute_object))
     values_to_filter = [person.name, person.email]
   elif ca_type == AdminWidgetCustomAttributes.DATE:
     date_formats = ["%m/%d/%Y", "%m/%Y", "%Y-%m-%d", "%Y-%m", "%Y"]
     date = parser.parse(cav.attribute_value).date()
     values_to_filter = [date.strftime(_format) for _format in date_formats]
   else:
     values_to_filter = [cav.attribute_value]
   return [self.get_filter_exp(cad.title, operator, [val])
           for val in values_to_filter]
Пример #18
0
    def get_comment_obj(self, paren_obj, comment_description):
        """Get and return comment object according to 'paren_obj' type) and
    comment_description 'paren_obj'. As default 'is_sort_by_created_at' and if
    even comments have the same descriptions query return selection w/ latest
    created datetime.
    """
        @test_utils.wait_for
        def get_obj_comment_response_values():
            """Get values fom response."""
            # pylint: disable=invalid-name
            filters = query.Query.expression_get_comment_by_desc(
                parent_type=paren_obj.type,
                parent_id=paren_obj.id,
                comment_desc=comment_description)
            order_by = [{"name": "created_at", "desc": True}]
            return self.get_obj_dict(objects.get_obj_type(objects.COMMENTS),
                                     filters=filters,
                                     order_by=order_by)

        return Representation.repr_dict_to_obj(
            get_obj_comment_response_values[0])