示例#1
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=unicode(ca_type),
         definition_type=unicode(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=unicode(ca.attribute_type),
             definition_type=unicode(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 = counters.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
示例#2
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
示例#3
0
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))
示例#4
0
 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
示例#5
0
 def test_asmt_and_issue_mapped_to_origin_control(
         self, create_audit_with_control_and_update_control,
         dynamic_objects, expected_state, selenium):
     """
 Check Assessment or Issue was mapped to origin control after mapping
 snapshot of control to Assessment or Issue.
 Test parameters:
   - check Assessment
   - check Issue
 """
     origin_control = create_audit_with_control_and_update_control[
         "update_control_rest"][0]
     snapshoted_control = create_audit_with_control_and_update_control[
         "new_control_rest"][0]
     expected_obj = (dynamic_objects.repr_ui().update_attrs(
         status=expected_state))
     (webui_service.ControlsService(selenium).map_objs_via_tree_view(
         src_obj=expected_obj, dest_objs=[snapshoted_control]))
     actual_objs = (get_cls_webui_service(
         objects.get_plural(
             expected_obj.type))(selenium).get_list_objs_from_tree_view(
                 src_obj=origin_control))
     # 'actual_controls': created_at, updated_at, custom_attributes (None)
     exclude_attrs = Representation.tree_view_attrs_to_exclude
     if dynamic_objects.type == entities_factory.EntitiesFactory.obj_issue:
         exclude_attrs = exclude_attrs + ("objects_under_assessment", )
     self.general_equal_assert([expected_obj], actual_objs, *exclude_attrs)
示例#6
0
 def create_obj_and_get_obj(self, obj):
     """Creates obj via LHN and returns a created obj."""
     object_name = objects.get_plural(obj.type)
     conftest_utils.get_lhn_accordion(self._driver,
                                      object_name).create_new()
     self.submit_obj_modal(obj)
     return self.build_obj_from_page()
示例#7
0
 def test_asmt_and_issue_mapped_to_origin_control(
     self, create_audit_with_control_and_update_control,
     dynamic_objects, expected_state, selenium
 ):
   """
   Check Assessment or Issue was mapped to origin control after mapping
   snapshot of control to Assessment or Issue.
   Test parameters:
     - check Assessment
     - check Issue
   """
   origin_control = create_audit_with_control_and_update_control[
       "update_control_rest"][0]
   snapshoted_control = create_audit_with_control_and_update_control[
       "new_control_rest"][0]
   expected_obj = (
       dynamic_objects.repr_ui().update_attrs(status=expected_state))
   (webui_service.ControlsService(selenium).map_objs_via_tree_view(
       src_obj=expected_obj, dest_objs=[snapshoted_control]))
   actual_objs = (get_cls_webui_service(
       objects.get_plural(expected_obj.type))(selenium).
       get_list_objs_from_tree_view(src_obj=origin_control))
   # 'actual_controls': created_at, updated_at, custom_attributes (None)
   exclude_attrs = Representation.tree_view_attrs_to_exclude
   if dynamic_objects.type == entities_factory.EntitiesFactory.obj_issue:
     exclude_attrs = exclude_attrs + ("objects_under_assessment", )
   self.general_equal_assert([expected_obj], actual_objs, *exclude_attrs)
示例#8
0
 def test_export_of_snapshoted_control_from_src_objs_pages_via_tree_view(
         self, create_tmp_dir, create_audit_with_control_and_update_control,
         dynamic_object, dynamic_relationships, selenium):
     """Check if snapshoted Control can be exported from (Audit's, Issue's,
 Assessment's) Info Page via mapped Controls's Tree View.
 Preconditions:
 - Execution and return of fixtures:
   - 'create_tmp_dir';
   - 'create_audit_and_update_first_of_two_original_controls'.
 Test parameters:
 - 'dynamic_object';
 - 'dynamic_relationships'.
 """
     audit_with_one_control = create_audit_with_control_and_update_control
     dynamic_object = (dynamic_object if dynamic_object else
                       audit_with_one_control["new_audit_rest"][0])
     # due to 'actual_control.custom_attributes = {None: None}'
     expected_control = (audit_with_one_control["new_control_rest"]
                         [0].repr_ui().update_attrs(
                             custom_attributes={None: None}))
     export_service = webui_service.BaseWebUiService(
         selenium, objects.get_plural(expected_control.type))
     export_service.export_objs_via_tree_view(src_obj=dynamic_object)
     actual_controls = export_service.get_list_objs_from_csv(
         path_to_export_dir=create_tmp_dir)
     self.extended_assert([expected_control], actual_controls,
                          "Issue in app GGRC-2750", "owners")
示例#9
0
 def _create_random_obj(self, is_add_rest_attrs):
     """Create Program entity with randomly and predictably filled fields, if
 'is_add_rest_attrs' then add attributes for REST."""
     program_obj = self.obj_inst().update_attrs(
         title=self.obj_title,
         slug=self.obj_slug,
         status=unicode(object_states.DRAFT),
         review=ReviewsFactory().default_review())
     if is_add_rest_attrs:
         program_obj.update_attrs(recipients=",".join((
             unicode(objects.get_plural(roles.PROGRAM_MANAGER, title=True)),
             unicode(objects.get_plural(roles.PROGRAM_EDITOR, title=True)),
             unicode(objects.get_plural(roles.PROGRAM_READER, title=True)),
             unicode(roles.PRIMARY_CONTACTS),
             unicode(roles.SECONDARY_CONTACTS))))
     return program_obj
示例#10
0
 def test_availability_mapping_of_objects_to_snapshotable_objs(
     self, create_audit_with_control_and_update_control, dynamic_objects,
     selenium
 ):
   """Check availability mapping of objects to Control's snapshots via UI
   using Unified Mapper functionality and AddWidget button on Horizontal
   Nav Bar.
   Steps:
     - Get list of available objects from HNB
     - Get list of available objects from Unified Mapper
     - Compare their with constant of snapshotable objects
   """
   mapped_audit = create_audit_with_control_and_update_control[
       'new_audit_rest'][0]
   obj_ui_service = get_cls_webui_service(
       objects.get_plural(dynamic_objects.type))(selenium)
   objs_types_from_mapper = (
       obj_ui_service.get_objs_available_to_map_via_mapper(
           src_obj=mapped_audit))
   objs_types_from_add_widget = (
       obj_ui_service.get_objs_available_to_map_via_add_widget(
           src_obj=dynamic_objects))
   expected_objs_types = sorted(
       objects.get_normal_form(snap_obj)
       for snap_obj in objects.ALL_SNAPSHOTABLE_OBJS)
   assert (expected_objs_types == objs_types_from_mapper ==
           objs_types_from_add_widget)
示例#11
0
 def test_asmt_and_issue_mapped_to_origin_control(
         self, create_audit_with_control_and_update_control,
         dynamic_objects, dynamic_relationships, expected_state, selenium):
     """
 Check Assessment, Issue was mapped to origin Control after mapping:
 - snapshot of Control to Assessment;
 - Assessment with mapped snapshot of Control to Issue.
 """
     is_issue_flow = (isinstance(dynamic_objects, dict)
                      and dynamic_objects.get("new_issue_rest") is not None)
     origin_control = create_audit_with_control_and_update_control[
         "update_control_rest"][0]
     snapshoted_control = create_audit_with_control_and_update_control[
         "new_control_rest"][0]
     expected_obj = (dynamic_objects.get("new_issue_rest") if is_issue_flow
                     else dynamic_objects).repr_ui().update_attrs(
                         status=expected_state)
     ui_mapping_service, src_obj, dest_objs = (
         (webui_service.IssuesService(selenium),
          dynamic_objects.get("new_assessment_rest"),
          [dynamic_objects.get("new_issue_rest")]) if is_issue_flow else
         (webui_service.ControlsService(selenium), expected_obj,
          [snapshoted_control]))
     ui_mapping_service.map_objs_via_tree_view(src_obj=src_obj,
                                               dest_objs=dest_objs)
     actual_objs = (get_cls_webui_service(
         objects.get_plural(
             expected_obj.type))(selenium).get_list_objs_from_tree_view(
                 src_obj=origin_control))
     # 'actual_controls': created_at, updated_at, custom_attributes (None)
     exclude_attrs = Representation.tree_view_attrs_to_exclude
     if is_issue_flow:
         exclude_attrs += ("objects_under_assessment", )
     self.general_equal_assert([expected_obj], actual_objs, *exclude_attrs)
示例#12
0
 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 = 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
示例#13
0
 def is_snapshoted_panel(self):
   """Check is the current page is Info Panel of snapshoted object."""
   return (not self.is_info_page and
           (self.source_obj_from_url in (objects.AUDITS, objects.ASSESSMENTS,
                                         objects.ISSUES)) and
           (objects.get_plural(self.widget_name_from_url.lower())
            in objects.ALL_SNAPSHOTABLE_OBJS))
示例#14
0
 def assert_objs_diff_corresponds_to_proposal(self, obj, proposal):
   """Check if objs difference corresponds to the proposal."""
   self.open_obj_change_proposals_tab(obj).click_review_apply_btn(proposal)
   comparison_window = apply_decline_proposal.CompareApplyDeclineModal()
   comparison_window.modal.wait_until(lambda e: e.exists)
   obj_name = objects.get_plural(obj.type)
   service_cls = factory.get_cls_webui_service(obj_name)(self._driver)
   current_obj = service_cls.build_obj_from_page(
       comparison_window.curr_version_obj_root_elem.wait_until(
           lambda e: e.exists))
   obj_after_proposal = service_cls.build_obj_from_page(
       comparison_window.proposal_version_obj_root_elem.wait_until(
           lambda e: e.exists))
   actual_proposal = entities_factory.ProposalsFactory().create()
   proposal_obj_dict = obj_after_proposal.__dict__
   current_obj_dict = current_obj.__dict__
   actual_proposal.changes = []
   for key in obj_after_proposal.__dict__.keys():
     if proposal_obj_dict[key] != current_obj_dict[key]:
       actual_proposal.changes.append(
           {"obj_attr_type": key.title(),
            "cur_value": current_obj_dict[key],
            "proposed_value": proposal_obj_dict[key]})
   actual_proposal.author = comparison_window.get_proposal_version_author()
   actual_proposal.datetime = (
       comparison_window.get_proposal_version_datetime())
   comparison_window.click_cancel_btn()
   assert actual_proposal == proposal
示例#15
0
 def is_snapshoted_panel(self):
     """Check is the current page is Info Panel of snapshoted object."""
     return (not self.is_info_page
             and (self.source_obj_from_url
                  in (objects.AUDITS, objects.ASSESSMENTS, objects.ISSUES))
             and (objects.get_plural(self.widget_name_from_url.lower())
                  in objects.ALL_SNAPSHOTABLE_OBJS))
示例#16
0
 def _create_random_obj(self, is_add_rest_attrs):
   """Create Program entity with randomly and predictably filled fields, if
   'is_add_rest_attrs' then add attributes for REST."""
   program_obj = self.obj_inst().update_attrs(
       title=self.obj_title, slug=self.obj_slug,
       status=unicode(object_states.DRAFT),
       review=ReviewsFactory().default_review()
   )
   if is_add_rest_attrs:
     program_obj.update_attrs(
         recipients=",".join((
             unicode(objects.get_plural(roles.PROGRAM_MANAGER, title=True)),
             unicode(objects.get_plural(roles.PROGRAM_EDITOR, title=True)),
             unicode(objects.get_plural(roles.PROGRAM_READER, title=True)),
             unicode(roles.PRIMARY_CONTACTS),
             unicode(roles.SECONDARY_CONTACTS))))
   return program_obj
示例#17
0
 def opened_obj(self, obj, proposal_email):
     """Build obj from page after clicking on the Open btn in the proposal
 notification email."""
     fast_emails_digest.FastEmailsDigest(
         self._driver).click_proposal_email_open_btn(proposal_email)
     obj_name = objects.get_plural(obj.type)
     service_cls = factory.get_cls_webui_service(obj_name)(self._driver)
     return service_cls.build_obj_from_page()
示例#18
0
 def opened_obj(self, obj, proposal_email):
   """Build obj from page after clicking on the Open btn in the proposal
   notification email."""
   proposal_digest.ProposalDigest(
       self._driver).click_proposal_email_open_btn(proposal_email)
   obj_name = objects.get_plural(obj.type)
   service_cls = factory.get_cls_webui_service(obj_name)(self._driver)
   return service_cls.build_obj_from_page()
示例#19
0
 def test_cannot_unmap_disabled_obj(self, obj, mapped_obj, selenium):
   """Check that user cannot unmap Risk/Control from Scope Objects/Directives
   and new tab opens."""
   webui_service.BaseWebUiService(
       objects.get_plural(obj.type)).open_info_panel_of_mapped_obj(
           mapped_obj, obj).three_bbs.select_unmap_in_new_frontend()
   _, new_tab = browsers.get_browser().windows()
   expected_url = mapped_obj.url + url.Widget.INFO
   assert new_tab.url == expected_url
示例#20
0
def get_ui_service(object_name):
  """Get and return class of UI service according to name of object
  Returns:
    class of ui service by object_name
  """
  service_name = objects.get_plural(object_name, title=True)
  from lib.service import webui_service
  service_classname = service_name + constants.cls_name.SERVICE
  return getattr(webui_service, service_classname)
示例#21
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_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
示例#22
0
 def test_deprecated_obj_review_buttons(self, control, soft_assert, selenium):
   """Check that buttons 'Mark Reviewed' and 'Request Review' are not
   displayed at Control Info page."""
   info_page = factory.get_cls_webui_service(objects.get_plural(
       control.type))().open_info_page_of_obj(control)
   soft_assert.expect(not info_page.mark_reviewed_btn.exists,
                      "There should be no 'Mark Reviewed' button.")
   soft_assert.expect(not info_page.request_review_btn.exists,
                      "There should be no 'Request Review button.")
   soft_assert.assert_expectations()
示例#23
0
文件: tables.py 项目: zdqf/ggrc-core
 def get_related_titles(self, asmt_type):
     """Get titles of Related assessments, their `asmt_type` objects and
 Audits.`
 Return list of tuples, tuples with 3 strings:
   [(str, str, str ), (str, str, str) ...]
 """
     return [(r_asmt[self._elements.ASSESSMENT_TITLE.upper()],
              r_asmt[self._elements.RELATED_OBJECTS.format(
                  objects.get_plural(asmt_type)).upper()],
              r_asmt[self._elements.AUDIT_TITLE.upper()])
             for r_asmt in self.get_items()]
示例#24
0
 def get_related_titles(self, asmt_type):
   """Get titles of Related assessments, their `asmt_type` objects and
   Audits.`
   Return list of tuples, tuples with 3 strings:
     [(str, str, str ), (str, str, str) ...]
   """
   return [(r_asmt[self._elements.ASSESSMENT_TITLE.upper()],
            r_asmt[self._elements.RELATED_OBJECTS.format(
                objects.get_plural(asmt_type)).upper()],
            r_asmt[self._elements.AUDIT_TITLE.upper()])
           for r_asmt in self.get_items()]
示例#25
0
def export_objects(path_to_export_dir, obj_type, src_obj=None,
                   is_versions_widget=False):
  """Opens generic widget of objects or mapped objects
    and exports objects to test's temporary directory as CSV file.
    Returns: list of objects from CSV file in test's temporary directory
    'path_to_export_dir'."""
  ui_service = factory.get_cls_webui_service(
      objects.get_plural(singular=obj_type, title=True))(is_versions_widget)
  widget = (ui_service.open_widget_of_mapped_objs(src_obj) if src_obj
            else ui_service.open_obj_dashboard_tab())
  return ui_service.exported_objs_via_tree_view(path_to_export_dir, widget)
示例#26
0
def soft_assert_cannot_add_comment(soft_assert, obj):
    """Performs soft assert that comment input field is not displayed when
  'Add Comment' button is clicked."""
    info_page = factory.get_cls_webui_service(objects.get_plural(
        obj.type))().open_info_page_of_obj(obj)
    info_page.comments_panel.click_add_button()
    # wait until new tab contains info page url
    _, new_tab = browsers.get_browser().windows()
    test_utils.wait_for(lambda: new_tab.url.endswith(url.Widget.INFO))
    soft_assert.expect(not info_page.comments_panel.comment_input.exists,
                       "There should be no input field in comments panel.")
示例#27
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=unicode(ca_type),
                 definition_type=unicode(
                     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=unicode(ca.attribute_type),
                     definition_type=unicode(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 = counters.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
示例#28
0
def soft_assert_role_cannot_be_edited(soft_assert, obj, role):
  """Performs soft assert that click on role's pencil icon doesn't open
  an input field."""
  info_widget = factory.get_cls_webui_service(
      objects.get_plural(obj.type))().open_info_page_of_obj(obj)
  role_field_element = getattr(info_widget, role)
  role_field_element.inline_edit.open()
  # wait until new tab contains info page url
  _, new_tab = browsers.get_browser().windows()
  test_utils.wait_for(lambda: new_tab.url.endswith(url.Widget.INFO))
  soft_assert.expect(not role_field_element.add_person_text_field.exists,
                     "There should be no input field.")
示例#29
0
    def edit_custom_attribute(self, ca_to_edit, new_ca):
        """Open Custom Attribute Definition Modal window for ca_to_edit (found
    by title) and submit form with ca_to_edit data.

    Returns:
      edited CA from ui.
    """
        definition_type = objects.get_normal_form(
            objects.get_plural(ca_to_edit.definition_type))
        self.ca_widget.open_edit_modal(definition_type,
                                       ca_to_edit.title).submit_obj(new_ca)
        return self.get_custom_attribute(definition_type, new_ca.title)
示例#30
0
 def update_acl(self, obj, role_name, role_id, people, rewrite_acl=False):
     """Update or rewrite access control list of existing object via REST API.
  Returns: updated object."""
     # pylint: disable=too-many-arguments
     factory.get_cls_entity_factory(objects.get_plural(obj.type)).set_acl(
         obj,
         role_name,
         people,
         role_id,
         is_add_rest_attrs=True,
         rewrite_acl=rewrite_acl)
     self.update_obj(obj, access_control_list=obj.access_control_list)
     return obj
示例#31
0
 def test_user_cannot_update_custom_attribute(self, obj, selenium,
                                              soft_assert):
   """Tests that user cannot update custom attribute."""
   cad = rest_facade.create_gcad(
       definition_type=obj.type.lower(),
       attribute_type=element.AdminWidgetCustomAttributes.RICH_TEXT)
   soft_assert.expect(
       not factory.get_cls_webui_service(objects.get_plural(
           obj.type))().has_gca_inline_edit(obj, ca_title=cad.title),
       "GCA field should not be editable.")
   soft_assert.expect(webui_facade.are_tabs_urls_equal(),
                      "Tabs urls should be equal.")
   soft_assert.assert_expectations()
 def snapshots(self):
     """List of snapshots related to the snapshoted control."""
     obj_list = []
     self.expand()
     for item in self._root.divs(class_name="mapped-object-info"):
         obj = {}
         for field in item.divs(class_name="mapped-object-info__item"):
             key, value = field.text.splitlines()[:2]
             obj[key.lower()] = value if value != 'None' else None
         obj_list.append(
             factory.get_cls_entity_factory(objects.get_plural(
                 self.type))().create(**obj))
     return obj_list
示例#33
0
 def new_ui_fixture(web_driver, fixture):
   """Extract arguments of 'new_ui_fixture' fixture from fixture name,
   create new objects via UI (LHN) and return UI page object.
   """
   fixture_params = fixture.replace("new_", "").replace("_ui", "")
   obj_name = fixture_params
   obj_count = batch.COUNT
   if (objects.get_plural(obj_name) in objects.ALL_OBJS and
           objects.get_plural(obj_name) != objects.PROGRAMS):
     obj_name = objects.get_plural(obj_name)
     obj_count = 1
     objs_info_pages = [conftest_utils.create_obj_via_lhn(
         web_driver,
         getattr(element.Lhn, obj_name.upper())) for _ in xrange(obj_count)]
     return objs_info_pages
   elif objects.get_plural(obj_name) == objects.PROGRAMS:
     modal = conftest_utils.get_lhn_accordion(
         web_driver,
         getattr(element.Lhn, objects.PROGRAMS.upper())).create_new()
     test_utils.ModalNewPrograms.enter_test_data(modal)
     modal.save_and_close()
     program_info_page = info_widget.Programs(web_driver)
     return modal, program_info_page
示例#34
0
 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
示例#35
0
 def new_ui_fixture(web_driver, fixture):
   """Extract arguments of 'new_ui_fixture' fixture from fixture name,
   create new objects via UI (LHN) and return UI page object.
   """
   fixture_params = fixture.replace("new_", "").replace("_ui", "")
   obj_name = fixture_params
   obj_count = counters.BATCH_COUNT
   if (objects.get_plural(obj_name) in objects.ALL_OBJS and
           objects.get_plural(obj_name) != objects.PROGRAMS):
     obj_name = objects.get_plural(obj_name)
     obj_count = 1
     objs_info_pages = [conftest_utils.create_obj_via_lhn(
         web_driver,
         getattr(element.Lhn, obj_name.upper())) for _ in xrange(obj_count)]
     return objs_info_pages
   elif objects.get_plural(obj_name) == objects.PROGRAMS:
     modal = conftest_utils.get_lhn_accordion(
         web_driver,
         getattr(element.Lhn, objects.PROGRAMS.upper())).create_new()
     test_utils.ModalNewPrograms.enter_test_data(modal)
     modal.save_and_close()
     program_info_page = info_widget.Programs(web_driver)
     return modal, program_info_page
示例#36
0
 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
示例#37
0
 def create_proposal(self, obj):
   """Create a proposal for an obj."""
   obj_info_page = factory.get_cls_webui_service(objects.get_plural(
       obj.type))(self._driver).open_info_page_of_obj(obj)
   obj_info_page.click_propose_changes()
   proposal_factory = entities_factory.ProposalsFactory()
   proposal = proposal_factory.create()
   proposed_description = proposal_factory.generate_string("Proposal")
   proposal_modal = object_modal.BaseObjectModal(self._driver)
   proposal_modal.set_description(proposed_description)
   proposal_modal.click_propose()
   proposal.changes = [{"obj_attr_type": "Description",
                        "cur_value": obj.description,
                        "proposed_value": proposed_description}]
   return proposal
示例#38
0
 def create_proposal(self, obj):
   """Create a proposal for an obj."""
   obj_info_page = factory.get_cls_webui_service(objects.get_plural(
       obj.type))(self._driver).open_info_page_of_obj(obj)
   obj_info_page.click_propose_changes()
   proposal_factory = entities_factory.ProposalsFactory()
   proposal = proposal_factory.create()
   proposed_description = proposal_factory.generate_string("Proposal")
   proposal_modal = object_modal.BaseObjectModal(self._driver)
   proposal_modal.set_description(proposed_description)
   proposal_modal.click_propose()
   proposal.changes = [{"obj_attr_type": "Description",
                        "cur_value": obj.description,
                        "proposed_value": proposed_description}]
   return proposal
示例#39
0
 def test_message_with_undo_btn_appears(self, second_creator,
                                        program_w_approved_via_ui_review,
                                        selenium):
   """Confirm floating message 'Review is complete' with 'Undo' button
   appears."""
   info_page = factory.get_cls_widget(
       objects.get_plural(program_w_approved_via_ui_review.type),
       is_info=True)(selenium)
   actual_elements_state = {
       "is_floating_message_visible": info_page.floating_message.exists,
       "is_undo_btn_visible": info_page.undo_button.exists}
   expected_elements_state = copy.deepcopy(actual_elements_state)
   expected_elements_state["is_floating_message_visible"] = True
   expected_elements_state["is_undo_btn_visible"] = True
   assert actual_elements_state == expected_elements_state
示例#40
0
 def test_message_with_undo_btn_appears(self, reviewer,
                                        program_w_approved_via_ui_review,
                                        selenium):
   """Confirm floating message 'Review is complete' with 'Undo' button
   appears."""
   info_page = factory.get_cls_widget(
       objects.get_plural(program_w_approved_via_ui_review.type),
       is_info=True)(selenium)
   actual_elements_state = {
       "is_floating_message_visible": info_page.floating_message.exists,
       "is_undo_btn_visible": info_page.undo_button.exists}
   expected_elements_state = copy.deepcopy(actual_elements_state)
   expected_elements_state["is_floating_message_visible"] = True
   expected_elements_state["is_undo_btn_visible"] = True
   assert actual_elements_state == expected_elements_state
示例#41
0
def generate_snapshots_fixtures(fixture):
    """Generate, run and return of results for snapshots dynamic fixtures
  according to tuple of fixture name.
  Example: 'create_audit_with_control__risk_and_update_control'
           'create_audit_with_controls'
           'create_audit_with_controls_and_update_control'
           'create_audit_with_control__risk_and_update_control__risk
  """
    global dict_executed_fixtures
    if isinstance(fixture, str) and fixture.startswith("create_audit_with_"):
        _creation_params = None
        _action_params = None
        updating_params = []
        deleting_params = []
        fixture_params = fixture.replace("create_audit_with_", "")
        if "_and_" in fixture_params:
            _creation_params, _action_params = fixture_params.split("_and_")
        if "_and_" not in fixture_params:
            _creation_params = fixture_params
        creation_params = StringMethods.convert_list_elements_to_list([
            "new_{}_rest".format(param) if "_with_cas" not in param else [
                "new_cas_for_{}_rest".format(
                    objects.get_plural(param.split("_")[0])),
                "new_{}_rest".format(param)
            ] for param in _creation_params.split("__")
        ])
        mapping_params = [
            "map_new_program_rest_to_new_{}_rest".format(param)
            for param in _creation_params.split("__")
        ]
        creation_part = (["new_program_rest"] + creation_params +
                         mapping_params + ["new_audit_rest"])
        if _action_params:
            if "update" in _action_params:
                updating_params = [
                    "update_{}_rest".format(param) for param in
                    _action_params.replace("update_", "").split("__")
                ]
            if "delete" in _action_params:
                deleting_params = [
                    "delete_{}_rest".format(param) for param in
                    _action_params.replace("delete_", "").split("__")
                ]
        action_part = (updating_params + deleting_params)
        all_manipulations = creation_part + action_part
        generate_common_fixtures(*all_manipulations)
        executed_snapshots_fixtures = copy.deepcopy(dict_executed_fixtures)
        return executed_snapshots_fixtures
示例#42
0
def soft_assert_cannot_view_version_history(obj, soft_assert, selenium):
  """Performs soft assertion that user cannot view Version History for disabled
  object."""
  info_page = factory.get_cls_webui_service(objects.get_plural(
      obj.type))(selenium).open_info_page_of_obj(obj)
  info_page.click_version_history()
  soft_assert.expect(are_tabs_urls_equal(), "Tabs urls should be equal.")
  soft_assert.expect(
      info_page.version_history_tab_or_link_name
      not in info_page.tabs.tab_names,
      "'Version History' tab should not be displayed.")
  for tab_num, tab in enumerate(browsers.get_browser().windows(), start=1):
    tab.use()
    soft_assert.expect(
        not version_history.VersionHistory().is_version_history_displayed(),
        "Version history should not be displayed in browser tab number {}.".
        format(tab_num))
示例#43
0
 def test_destructive_mapping_of_objects_to_snapshots(
         self, create_audit_with_control_and_update_control,
         is_via_tw_map_btn_not_item, expected_snapshoted_control,
         dynamic_objects, dynamic_relationships, selenium):
     """Check mapping of objects to Control's snapshots via UI using Unified
 Mapper functionality (Tree View's 'MAP' button and item):
 - Assessments: using Audit's scope;
 - Issues: using auto-mapping in Assessment's with mapped snapshoted object
           scope.
 """
     audit_with_one_control = create_audit_with_control_and_update_control
     is_issue_flow = (isinstance(dynamic_objects, dict)
                      and dynamic_objects.get("new_issue_rest") is not None)
     expected_control = (
         audit_with_one_control[expected_snapshoted_control][0].repr_ui())
     source_obj_for_map, destination_obj_for_map = (
         (dynamic_objects.get("new_assessment_rest"),
          dynamic_objects.get("new_issue_rest")) if is_issue_flow else
         (dynamic_objects, expected_control))
     obj_for_map = (destination_obj_for_map
                    if is_via_tw_map_btn_not_item else source_obj_for_map)
     objs_ui_service = (get_cls_webui_service(
         objects.get_plural(obj_for_map.type))(selenium))
     ui_action = ("map_objs_via_tree_view" if is_via_tw_map_btn_not_item
                  else "map_objs_via_tree_view_item")
     getattr(objs_ui_service, ui_action)(
         src_obj=(source_obj_for_map if is_via_tw_map_btn_not_item else
                  audit_with_one_control["new_audit_rest"][0]),
         dest_objs=[destination_obj_for_map])
     source_obj_for_controls = (dynamic_objects.get("new_issue_rest")
                                if is_issue_flow else dynamic_objects)
     # check snapshoted Controls
     controls_ui_service = webui_service.ControlsService(
         selenium, is_versions_widget=is_issue_flow)
     self.get_controls_and_general_assert(controls_ui_service,
                                          expected_control,
                                          source_obj_for_controls)
     # check original Controls when Issue is source object
     if is_issue_flow:
         expected_control = (
             audit_with_one_control["update_control_rest"][0].repr_ui())
         controls_ui_service = webui_service.ControlsService(selenium)
         self.get_controls_and_general_assert(controls_ui_service,
                                              expected_control,
                                              source_obj_for_controls)
示例#44
0
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))
示例#45
0
 def get_list_objs_from_csv(self, path_to_exported_file):
   """Get and return list of objects from CSV file of exported objects in
   test's temporary directory 'path_to_export_dir'.
   """
   # pylint: disable=invalid-name
   dict_list_objs_scopes = file_utils.get_list_objs_scopes_from_csv(
       path_to_csv=path_to_exported_file)
   dict_key = dict_list_objs_scopes.iterkeys().next()
   # 'Control' to 'controls', 'Control Snapshot' to 'controls'
   obj_name_from_dict = objects.get_plural(
       StringMethods.get_first_word_from_str(dict_key))
   if self.obj_name == obj_name_from_dict:
     return self._create_list_objs(
         entity_factory=self.entities_factory_cls,
         list_scopes=dict_list_objs_scopes[dict_key])
   else:
     raise ValueError(messages.ExceptionsMessages.err_csv_format.
                      format(dict_list_objs_scopes))
示例#46
0
 def get_list_objs_from_csv(self, path_to_exported_file):
   """Get and return list of objects from CSV file of exported objects in
   test's temporary directory 'path_to_export_dir'.
   """
   # pylint: disable=invalid-name
   dict_list_objs_scopes = file_utils.get_list_objs_scopes_from_csv(
       path_to_csv=path_to_exported_file)
   dict_key = dict_list_objs_scopes.iterkeys().next()
   # 'Control' to 'controls', 'Control Snapshot' to 'controls'
   obj_name_from_dict = objects.get_plural(
       StringMethods.get_first_word_from_str(dict_key))
   if self.obj_name == obj_name_from_dict:
     return self._create_list_objs(
         entity_factory=self.entities_factory_cls,
         list_scopes=dict_list_objs_scopes[dict_key])
   else:
     raise ValueError(messages.ExceptionsMessages.err_csv_format.
                      format(dict_list_objs_scopes))
示例#47
0
 def get_list_objs_from_csv(self, path_to_export_dir):
   """Get and return list of objects from CSV file of exported objects in
   test's temporary directory 'path_to_export_dir'.
   """
   # pylint: disable=invalid-name
   path_to_exported_file = os.path.join(
       path_to_export_dir, path.EXPORTED_FILE_NAME)
   dict_list_objs_scopes = file_utils.get_list_objs_scopes_from_csv(
       path_to_csv=path_to_exported_file)
   dict_key = dict_list_objs_scopes.iterkeys().next()
   # 'Control' to 'controls', 'Control Snapshot' to 'controls'
   obj_name_from_dict = objects.get_plural(
       string_utils.get_first_word_from_str(dict_key))
   if self.obj_name == obj_name_from_dict:
     return self.create_list_objs(entity_factory=self.entities_factory_cls,
                                  list_scopes=dict_list_objs_scopes[dict_key])
   else:
     raise ValueError(messages.ERR_CSV_FORMAT.format(dict_list_objs_scopes))
示例#48
0
 def test_destructive_mapping_of_objects_to_snapshots(
     self, create_audit_with_control_and_update_control,
     is_via_tw_map_btn_not_item, expected_snapshoted_control, dynamic_objects,
     dynamic_relationships, selenium
 ):
   """Check mapping of objects to Control's snapshots via UI using Unified
   Mapper functionality (Tree View's 'MAP' button and item):
   - Assessments: using Audit's scope;
   - Issues: using auto-mapping in Assessment's with mapped snapshoted object
             scope.
   """
   audit_with_one_control = create_audit_with_control_and_update_control
   is_issue_flow = (isinstance(dynamic_objects, dict) and
                    dynamic_objects.get("new_issue_rest") is not None)
   expected_control = (
       audit_with_one_control[expected_snapshoted_control][0].repr_ui())
   source_obj_for_map, destination_obj_for_map = (
       (dynamic_objects.get("new_assessment_rest"),
        dynamic_objects.get("new_issue_rest")) if is_issue_flow else
       (dynamic_objects, expected_control))
   obj_for_map = (destination_obj_for_map if is_via_tw_map_btn_not_item else
                  source_obj_for_map)
   objs_ui_service = (
       get_cls_webui_service(objects.get_plural(obj_for_map.type))(selenium))
   ui_action = ("map_objs_via_tree_view" if is_via_tw_map_btn_not_item else
                "map_objs_via_tree_view_item")
   getattr(objs_ui_service, ui_action)(
       src_obj=(source_obj_for_map if is_via_tw_map_btn_not_item else
                audit_with_one_control["new_audit_rest"][0]),
       dest_objs=[destination_obj_for_map])
   source_obj_for_controls = (dynamic_objects.get("new_issue_rest") if
                              is_issue_flow else dynamic_objects)
   # check snapshoted Controls
   controls_ui_service = webui_service.ControlsService(
       selenium, is_versions_widget=is_issue_flow)
   self.get_controls_and_general_assert(
       controls_ui_service, expected_control, source_obj_for_controls)
   # check original Controls when Issue is source object
   if is_issue_flow:
     expected_control = (
         audit_with_one_control["update_control_rest"][0].repr_ui())
     controls_ui_service = webui_service.ControlsService(selenium)
     self.get_controls_and_general_assert(
         controls_ui_service, expected_control, source_obj_for_controls)
示例#49
0
  def test_availability_mapping_of_objects_via_mapper_and_add_widget(
      self, create_audit_with_control_and_update_control, dynamic_objects,
      dynamic_relationships, selenium
  ):
    """Check availability mapping of objects to Assessment and Issue via UI
    using Unified Mapper functionality and AddWidget button on Horizontal
    Nav Bar.

    Steps:
      - Get list of available objects from Unified Mapper;
      - Get list of available objects from HNB;
      - Compare their with constant of expected objects accordingly.
    """
    expected_objs_names_from_mapper = (
        objects.ALL_SNAPSHOTABLE_OBJS + (objects.ISSUES, ))
    if dynamic_objects.type == objects.get_obj_type(objects.ISSUES):
      expected_objs_names_from_mapper = expected_objs_names_from_mapper + (
          objects.PROGRAMS, objects.PROJECTS, objects.DOCUMENTS)
    expected_objs_names_from_add_widget = expected_objs_names_from_mapper
    expected_objs_types_from_mapper = sorted(
        objects.get_normal_form(obj_name)
        for obj_name in expected_objs_names_from_mapper)
    expected_objs_types_from_add_widget = sorted(
        objects.get_normal_form(obj_name)
        for obj_name in expected_objs_names_from_add_widget)
    mapped_audit = create_audit_with_control_and_update_control[
        "new_audit_rest"][0]
    obj_ui_service = get_cls_webui_service(
        objects.get_plural(dynamic_objects.type))(selenium)
    actual_objs_types_from_mapper = (
        obj_ui_service.get_objs_available_to_map_via_mapper(
            src_obj=mapped_audit))
    actual_objs_types_from_add_widget = (
        obj_ui_service.get_objs_available_to_map_via_add_widget(
            src_obj=dynamic_objects))
    assert (expected_objs_types_from_mapper ==
            actual_objs_types_from_mapper), (
        messages.AssertionMessages.format_err_msg_equal(
            expected_objs_types_from_mapper, actual_objs_types_from_mapper))
    assert (expected_objs_types_from_add_widget ==
            actual_objs_types_from_add_widget), (
        messages.AssertionMessages.format_err_msg_equal(
            expected_objs_types_from_add_widget,
            actual_objs_types_from_add_widget))
示例#50
0
def generate_snapshots_fixtures(fixture):
  """Generate, run and return of results for snapshots dynamic fixtures
  according to tuple of fixture name.
  Example: 'create_audit_with_control__risk_and_update_control'
           'create_audit_with_controls'
           'create_audit_with_controls_and_update_control'
           'create_audit_with_control__risk_and_update_control__risk
  """
  global dict_executed_fixtures
  if isinstance(fixture, str) and fixture.startswith("create_audit_with_"):
    _creation_params = None
    _action_params = None
    updating_params = []
    deleting_params = []
    fixture_params = fixture.replace("create_audit_with_", "")
    if "_and_" in fixture_params:
      _creation_params, _action_params = fixture_params.split("_and_")
    if "_and_" not in fixture_params:
      _creation_params = fixture_params
    creation_params = StringMethods.convert_list_elements_to_list([
        "new_{}_rest".format(param) if "_with_cas" not in param else
        ["new_cas_for_{}_rest".format(objects.get_plural(param.split("_")[0])),
         "new_{}_rest".format(param)]
        for param in _creation_params.split("__")])
    mapping_params = [
        "map_new_program_rest_to_new_{}_rest".format(param) for param in
        _creation_params.split("__")]
    creation_part = (["new_program_rest"] + creation_params +
                     mapping_params + ["new_audit_rest"])
    if _action_params:
      if "update" in _action_params:
        updating_params = ["update_{}_rest".format(param) for param in
                           _action_params.replace("update_", "").split("__")]
      if "delete" in _action_params:
        deleting_params = ["delete_{}_rest".format(param) for param in
                           _action_params.replace("delete_", "").split("__")]
    action_part = (updating_params + deleting_params)
    all_manipulations = creation_part + action_part
    generate_common_fixtures(*all_manipulations)
    executed_snapshots_fixtures = copy.deepcopy(dict_executed_fixtures)
    return executed_snapshots_fixtures
示例#51
0
 def test_destructive_asmt_and_issue_mapped_to_origin_control(
     self, create_audit_with_control_and_update_control,
     dynamic_objects, dynamic_relationships, expected_state, selenium
 ):
   """
   Check Assessment, Issue was mapped to origin Control after mapping:
   - snapshot of Control to Assessment;
   - Assessment with mapped snapshot of Control to Issue.
   """
   is_issue_flow = (isinstance(dynamic_objects, dict) and
                    dynamic_objects.get("new_issue_rest") is not None)
   origin_control = create_audit_with_control_and_update_control[
       "update_control_rest"][0]
   snapshoted_control = create_audit_with_control_and_update_control[
       "new_control_rest"][0]
   expected_obj = (
       dynamic_objects.get("new_issue_rest") if is_issue_flow
       else dynamic_objects).repr_ui().update_attrs(status=expected_state)
   ui_mapping_service, src_obj, dest_objs = (
       (webui_service.IssuesService(selenium),
        dynamic_objects.get("new_assessment_rest"),
        [dynamic_objects.get("new_issue_rest")]) if is_issue_flow else
       (webui_service.ControlsService(selenium), expected_obj,
        [snapshoted_control]))
   ui_mapping_service.map_objs_via_tree_view(
       src_obj=src_obj, dest_objs=dest_objs)
   actual_objs = (get_cls_webui_service(
       objects.get_plural(expected_obj.type))(selenium).
       get_list_objs_from_tree_view(src_obj=origin_control))
   # 'actual_controls': created_at, updated_at, custom_attributes, audit
   #                    assessment_type, modified_by (None)
   exclude_attrs = (Representation.tree_view_attrs_to_exclude +
                    ("audit", "assessment_type", "modified_by"))
   if is_issue_flow:
     exclude_attrs += ("objects_under_assessment", )
   self.general_equal_assert([expected_obj], actual_objs, *exclude_attrs)
示例#52
0
 def test_export_of_snapshoted_control_from_audit_via_tree_view(
     self, create_tmp_dir, create_audit_with_control_and_update_control,
     selenium
 ):
   """Check if snapshoted Control can be exported from Audit via Tree View.
   Preconditions:
   - Execution and return of fixture
     'create_audit_and_update_first_of_two_original_controls'.
   Test parameters: None
   """
   audit_with_one_control = create_audit_with_control_and_update_control
   audit = audit_with_one_control["new_audit_rest"][0]
   # due to 'actual_control.custom_attributes = {None: None}'
   expected_control = (audit_with_one_control["new_control_rest"][0].
                       repr_ui().update_attrs(custom_attributes={None: None}))
   export_service = webui_service.BaseWebUiService(
       selenium, objects.get_plural(expected_control.type))
   export_service.export_objs_via_tree_view(src_obj=audit)
   actual_controls = export_service.get_list_objs_from_csv(
       path_to_export_dir=create_tmp_dir)
   actual_controls = [
       actual_control.repr_ui() for actual_control in actual_controls]
   assert [expected_control] == actual_controls, (
       messages.ERR_MSG_FORMAT.format([expected_control], actual_controls))
示例#53
0
def obj_view_link(obj):
  """Returns `viewLink` for the object."""
  plural = objects.get_plural(obj.obj_name())
  return "{}/{}".format(plural, obj.obj_id)
示例#54
0
def delete_control(control):
  """Delete control."""
  return (factory.get_cls_rest_service(
      objects.get_plural(control.type))().delete_objs(control))
示例#55
0
 def open_obj_change_proposals_tab(self, obj):
   """Open change proposals tab of an obj."""
   obj_info_page = factory.get_cls_webui_service(objects.get_plural(
       obj.type))(self._driver).open_info_page_of_obj(obj)
   return obj_info_page.related_proposals()
示例#56
0
 def plural_obj_name(cls):
   """Returns plural object name (e.g. TaskGroup -> task_groups)."""
   return objects.get_plural(cls.obj_name())
示例#57
0
 def _plural_obj_name(self):
   """Returns plural obj name."""
   return objects.get_plural(self._obj_name)
示例#58
0
def _get_ui_service(selenium, obj):
  """Get webui_service for object"""
  obj_type = objects.get_plural(obj.type)
  return webui_service.BaseWebUiService(selenium, obj_type)
示例#59
0
 def _related_asmts_of_obj(obj, selenium):
   """Return related assessments of obj (Control or Objective)"""
   return factory.get_cls_webui_service(objects.get_plural(
       obj.type))(selenium).get_obj_related_asmts_titles(obj)