def test_filter_of_snapshotable_control( self, create_audit_with_control_and_update_control, selenium, version_of_ctrl, is_found): """Check via UI that filtering work for snapshoted version of Control only, filtering by actual values returns no items in scope of Audit page. """ 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[version_of_ctrl][0].repr_ui().update_attrs( custom_attributes={None: None})) filter_exp = FilterUtils.get_filter_exp_by_title( expected_control.title) actual_controls = (webui_service.ControlsService( selenium).filter_list_objs_from_tree_view(src_obj=audit, filter_exp=filter_exp)) assert (expected_control in [ ctrls for ctrls in actual_controls ]) == is_found, (messages.AssertionMessages.format_err_msg_contains( expected_control, [ctrls for ctrls in actual_controls]))
def test_snapshot_cannot_be_unmapped_from_audit(self, create_audit_with_control, selenium): """Check Snapshot cannot be unmapped from audit using "Unmap" button on info panel. Check that snapshot cannot be mapped from tree-view using "Map to this object" button. Preconditions: - Audit with mapped Control Snapshot created via REST API """ audit_with_one_control = create_audit_with_control audit = audit_with_one_control["new_audit_rest"][0] control = audit_with_one_control["new_control_rest"][0] controls_ui_service = webui_service.ControlsService(selenium) is_mappable_on_tree_view_item = ( controls_ui_service.is_obj_mappable_via_tree_view(audit, control)) is_unmappable_on_info_panel = ( controls_ui_service.is_obj_unmappable_via_info_panel(src_obj=audit, obj=control)) assert (False is is_mappable_on_tree_view_item is is_unmappable_on_info_panel)
def test_audit_contains_snapshotable_control( self, new_cas_for_controls_rest, dynamic_create_audit_with_control, expected_control, is_openable, is_updateable, selenium ): """Test snapshotable Control and check via UI that: - Audit contains snapshotable Control after updating Control. - Audit contains snapshotable Control after deleting Control. - Audit contains snapshotable Control after updating Control with CAs. - "Audit contains snapshotable Control after deleting CAs of Control. Preconditions: Execution and return of dynamic fixtures used REST API: - 'new_cas_for_controls_rest' *(due to Issue in app GGRC-2344) - 'create_audit_with_control_and_update_control'. - 'create_audit_with_control_and_delete_control'. - 'create_audit_with_control_with_cas_and_update_control_with_cas'. - 'create_audit_with_control_with_cas_and_delete_cas_for_controls'. """ audit_with_one_control = dynamic_create_audit_with_control audit = audit_with_one_control["new_audit_rest"][0] expected_control = audit_with_one_control[expected_control][0].repr_ui() controls_ui_service = webui_service.ControlsService(selenium) actual_controls_tab_count = controls_ui_service.get_count_objs_from_tab( src_obj=audit) assert len([expected_control]) == actual_controls_tab_count is_control_updateable = ( controls_ui_service.is_obj_updateble_via_info_panel( src_obj=audit, obj=expected_control)) is_control_openable = controls_ui_service.is_obj_page_exist_via_info_panel( src_obj=audit, obj=expected_control) actual_control = controls_ui_service.get_list_objs_from_info_panels( src_obj=audit, objs=expected_control) assert is_control_updateable is is_updateable assert is_control_openable is is_openable # 'actual_control': created_at, updated_at, modified_by (None) self.general_equal_assert( expected_control, actual_control, "created_at", "updated_at", "modified_by", "custom_attributes") self.xfail_equal_assert( expected_control, actual_control, "Issue in app GGRC-2344", "custom_attributes")
def test_destructive_update_snapshotable_control_to_latest_ver( self, obj, selenium ): """Test snapshotable Control and check via UI that: - Update snapshotable Control to latest ver after updating Control. - Update snapshotable Control to latest ver after updating Control with CAs. - Update snapshotable Control to latest ver after deleting CAs of Control. Preconditions: Execution and return of dynamic fixtures used REST API: - 'new_cas_for_controls_rest' *(due to Issue in app GGRC-2344) - 'create_audit_with_control_and_update_control'. - 'create_audit_with_control_with_cas_and_update_control_with_cas'. - 'create_audit_with_control_with_cas_and_delete_cas_for_controls'. """ audit_with_one_control = obj audit = audit_with_one_control["audit"] control = audit_with_one_control["control"] expected_control = audit_with_one_control["updated_control"].repr_ui() controls_ui_service = webui_service.ControlsService(selenium) actual_controls_tab_count = controls_ui_service.get_count_objs_from_tab( src_obj=audit) assert len([expected_control]) == actual_controls_tab_count controls_ui_service.update_obj_ver_via_info_panel( src_obj=audit, obj=control) is_control_updateable = ( controls_ui_service.is_obj_updateble_via_info_panel( src_obj=audit, obj=expected_control)) is_control_openable = controls_ui_service.is_obj_page_exist_via_info_panel( src_obj=audit, obj=expected_control) actual_control = controls_ui_service.get_list_objs_from_info_panels( src_obj=audit, objs=expected_control) assert is_control_updateable is False assert is_control_openable is True # 'actual_control': created_at, updated_at, modified_by (None) self.general_equal_assert( expected_control, actual_control, "created_at", "updated_at", "modified_by", *Representation.tree_view_attrs_to_exclude)
def test_destructive_audit_contains_snapshotable_control( self, login_as_creator, obj, expected_control, is_openable, is_updateable, selenium): """Test snapshotable Control and check via UI that: - Audit contains snapshotable Control after updating Control. - Audit contains snapshotable Control after deleting Control. - Audit contains snapshotable Control after updating Control with CAs. - "Audit contains snapshotable Control after deleting CAs of Control. Preconditions: Execution and return of dynamic fixtures used REST API: - 'new_cas_for_controls_rest' *(due to Issue in app GGRC-2344) - 'create_audit_with_control_and_update_control'. - 'create_audit_with_control_and_delete_control'. - 'create_audit_with_control_with_cas_and_update_control_with_cas'. - 'create_audit_with_control_with_cas_and_delete_cas_for_controls'. This test is marked as destructive as deletion of GCA leads to changing of modified_by and updated_at of all objects with this GCA. Bug wasn't filed for this as deletion of GCA doesn't work currently and considered not critical (see GGRC-4055). """ audit_with_one_control = obj audit = audit_with_one_control["audit"] expected_control = audit_with_one_control[expected_control].repr_ui() controls_ui_service = webui_service.ControlsService(selenium) actual_controls_tab_count = controls_ui_service.get_count_objs_from_tab( src_obj=audit) assert len([expected_control]) == actual_controls_tab_count is_control_updateable = ( controls_ui_service.is_obj_updateble_via_info_panel( src_obj=audit, obj=expected_control)) is_control_openable = controls_ui_service.is_obj_page_exist_via_info_panel( src_obj=audit, obj=expected_control) actual_control = controls_ui_service.get_list_objs_from_info_panels( src_obj=audit, objs=expected_control) assert is_control_updateable is is_updateable assert is_control_openable is is_openable # 'actual_control': created_at, updated_at, modified_by (None) self.general_equal_assert(expected_control, actual_control, "modified_by", *Representation.tree_view_attrs_to_exclude)
def test_clonable_not_audit_related_objs_move_to_cloned_audit( self, create_and_clone_audit, selenium): """Check via UI that clonable not audit related objects Control, Program move to cloned Audit. Preconditions: -Execution and return of fixture 'create_and_clone_audit'. """ actual_audit = create_and_clone_audit["actual_audit"] expected_control = create_and_clone_audit["control"].repr_ui() # due to 'actual_program.custom_attributes = {None: None}' expected_program = ( create_and_clone_audit["program"].repr_ui().update_attrs( custom_attributes={None: None})) actual_controls = (webui_service.ControlsService( selenium).get_list_objs_from_tree_view(src_obj=actual_audit)) actual_programs = (webui_service.ProgramsService( selenium).get_list_objs_from_tree_view(src_obj=actual_audit)) # due to 'actual_control.custom_attributes = {None: None}' self.general_assert([expected_control], actual_controls, "custom_attributes") self.extended_assert([expected_program], actual_programs, "Issue in app GGRC-2381", "manager")
def test_filter_of_snapshotable_control( self, create_audit_with_control_and_update_control, version_of_ctrl, is_found, selenium): """Check via UI that filtering work for snapshoted version of Control only, filtering by actual values returns no items in scope of Audit page. """ audit_with_one_control = create_audit_with_control_and_update_control audit = audit_with_one_control["new_audit_rest"][0] expected_control = audit_with_one_control[version_of_ctrl][0].repr_ui() filter_exp = FilterUtils.get_filter_exp_by_title( expected_control.title) actual_controls = (webui_service.ControlsService( selenium).filter_and_get_list_objs_from_tree_view( src_obj=audit, filter_exp=filter_exp)) # 'actual_controls': created_at, updated_at, custom_attributes (None) expected_controls, actual_controls = entity.Entity.extract_objs( [expected_control], actual_controls, *Representation.tree_view_attrs_to_exclude) expected_control = expected_controls[0] assert is_found is (expected_control in actual_controls), ( messages.AssertionMessages.format_err_msg_contains( expected_control, actual_controls))
def test_destructive_mapping_controls_to_program_via_unified_mapper( self, program, controls, selenium): """Check if Controls can be mapped to Program from Controls widget under Program page via unified mapper. Preconditions: - Program, Controls created via REST API. """ expected_controls = [ expected_control.repr_ui() for expected_control in controls ] controls_ui_service = webui_service.ControlsService(selenium) controls_ui_service.map_objs_via_tree_view(src_obj=program, dest_objs=expected_controls) actual_controls_tab_count = controls_ui_service.get_count_objs_from_tab( src_obj=program) assert len(expected_controls) == actual_controls_tab_count actual_controls = controls_ui_service.get_list_objs_from_tree_view( src_obj=program) # 'actual_controls': created_at, updated_at, custom_attributes (None) self.general_equal_assert(sorted(expected_controls), sorted(actual_controls), *Representation.tree_view_attrs_to_exclude)
def test_filter_of_snapshotable_control( self, create_audit_and_update_original_control, selenium, version_of_ctrl, is_found, ): """Check via UI that filtering work for snapshoted version of Control only, filtering by actual values returns no items in scope of Audit page. """ audit_with_one_control = create_audit_and_update_original_control audit = audit_with_one_control["audit"] expected_control = audit_with_one_control[version_of_ctrl] filter_exp = FilterUtils.get_filter_exp_by_title( expected_control.title) actual_controls = (webui_service.ControlsService( selenium).filter_list_objs_from_tree_view(src_obj=audit, filter_exp=filter_exp)) assert (expected_control in [ ctrls for ctrls in actual_controls if len(actual_controls) != 0 ]) == is_found, messages.ERR_MSG_FORMAT.format([expected_control], actual_controls)
def test_dashboard_gca(self, new_control_rest, selenium): # pylint: disable=anomalous-backslash-in-string """Check Dashboard Tab is exist if 'Dashboard' GCA filled with right value. Possible values match to regexp r"^https?://[^\s]+$". Steps: - Create 'Dashboard' gcas for object. - Fill with values - Check if 'Dashboard' tab exist. - Navigate to 'Dashboard' tab. - Check only GCAs filled with right values displayed on the tab. """ urls = [ "https://gmail.by/", "https://www.google.com/", environment.app_url, StringMethods.random_string(), "ftp://something.com/" ] cads_rest_service = rest_service.CustomAttributeDefinitionsService() gca_defs = (cads_rest_service.create_dashboard_gcas( new_control_rest.type, count=len(urls))) control_rest_service = rest_service.ControlsService() control_rest_service.update_obj( obj=new_control_rest, custom_attributes=dict( zip([gca_def.id for gca_def in gca_defs], urls))) expected_dashboards_items = dict( zip([ gca_def.title.replace(aliases.DASHBOARD + "_", "") for gca_def in gca_defs ], urls[:3])) controls_ui_service = webui_service.ControlsService(selenium) is_dashboard_tab_exist = ( controls_ui_service.is_dashboard_tab_exist(new_control_rest)) assert is_dashboard_tab_exist actual_dashboards_items = ( controls_ui_service.get_items_from_dashboard_widget( new_control_rest)) assert expected_dashboards_items == actual_dashboards_items cads_rest_service.delete_objs(gca_defs)
def test_mapped_to_program_controls_does_not_added_to_existing_audit( self, create_audit_and_update_first_of_two_original_controls, selenium): """Check via UI that Audit contains snapshotable Control that equal to original Control does not contain Control that was mapped to Program after Audit creation. Preconditions: - Execution and return of fixture 'create_audit_and_update_first_of_two_original_controls'. """ audit_with_two_controls = ( create_audit_and_update_first_of_two_original_controls) audit = audit_with_two_controls["audit"] expected_control = audit_with_two_controls["control"].repr_ui() controls_ui_service = webui_service.ControlsService(selenium) actual_controls_tab_count = controls_ui_service.get_count_objs_from_tab( src_obj=audit) assert len([expected_control]) == actual_controls_tab_count actual_controls = controls_ui_service.get_list_objs_from_tree_view( src_obj=audit) # 'actual_controls': created_at, updated_at, custom_attributes (None) self.general_equal_assert([expected_control], actual_controls, *Representation.tree_view_attrs_to_exclude)
def test_cannot_map_control_via_um_create_new_obj(self, control, regulation, dashboard_controls_tab, soft_assert, selenium): """Tests that user cannot map control to scope objects/directives via unified mapper (create a new scope/directive object).""" dashboard_controls_tab.get_control(control).select_map_to_this_object() map_modal = webui_facade.map_object_via_unified_mapper( selenium=selenium, obj_name=objects.CONTROLS, dest_objs_type=objects.get_singular(plural=objects.REGULATIONS, title=True), obj_to_map=regulation, proceed_in_new_tab=True) new_tab = browsers.get_browser().windows()[1] soft_assert.expect(new_tab.url == url.Urls().dashboard_info_tab, "Dashboard info page should be opened in new tab.") soft_assert.expect( not(objects.get_normal_form(objects.REGULATIONS) in webui_service.ControlsService(selenium).open_info_page_of_obj( control).top_tabs.tab_names), "There should be no scope/directive object mapped to Control.") new_tab.use() soft_assert.expect(not map_modal.is_present, "There should be no modal windows in new browser tab.") soft_assert.assert_expectations()
def test_destructive_asmt_and_issue_mapped_to_origin_control( self, create_audit_with_control_and_update_control, assessment, obj, 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 = obj["issue"] is not None origin_control = create_audit_with_control_and_update_control[ "updated_control"] snapshoted_control = create_audit_with_control_and_update_control[ "control"] expected_obj = (obj["issue"] if is_issue_flow else obj["assessment"]).repr_ui().update_attrs( status=obj["expected_state"]) ui_mapping_service, src_obj, dest_objs = ( (webui_service.IssuesService(selenium), obj["assessment"], [obj["issue"]]) 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([], actual_objs, *exclude_attrs) else: self.general_equal_assert([expected_obj], actual_objs, *exclude_attrs)
def test_related_asmts_on_control_snapshot_page( self, control_mapped_to_program, audit, selenium ): """Objects structure: Program -> Control -> Audit -> Asmt-1 mapped to Control -> Asmt-2 mapped to Control Check Related Assessments on Control snapshot's page """ assessments = [_create_mapped_asmt( audit=audit, assessment_type="Control", objs_to_map=[control_mapped_to_program]) for _ in xrange(2)] control_panel = webui_service.ControlsService( selenium).open_info_panel_of_obj_by_title( assessments[0], control_mapped_to_program) related_asmts_table = control_panel.show_related_assessments() related_asmts_titles = [ (assessment.title, control_mapped_to_program.title, audit.title) for assessment in assessments] assert related_asmts_table.get_related_titles(asmt_type="Control") ==\ related_asmts_titles[::-1]
def test_mapping_of_assessments_and_issues_to_snapshots( self, create_audit_with_control_and_update_control, dynamic_object, selenium): """Check mapping of assessments or issues to snapshot of control via info widget. Test parameters: "Checking assessment" "Checking issue" """ expected_control = ( create_audit_with_control_and_update_control["new_control_rest"] [0].repr_ui()) source_obj = dynamic_object controls_ui_service = webui_service.ControlsService(selenium) controls_ui_service.map_objs_via_tree_view( src_obj=source_obj, dest_objs=[expected_control]) actual_controls_count_in_tab = ( controls_ui_service.get_count_objs_from_tab(src_obj=source_obj)) actual_controls = ( controls_ui_service.get_list_objs_from_tree_view(source_obj)) assert len([expected_control]) == actual_controls_count_in_tab # 'actual_controls': created_at, updated_at, custom_attributes (None) self.general_equal_assert([expected_control], actual_controls, *Representation.tree_view_attrs_to_exclude)
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, 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)
def test_mapping_control_to_existing_audit(self, new_program_rest, new_audit_rest, new_control_rest, selenium): """Check if Control can be mapped to existing Audit and mapping between Control and Program of this Audit automatically created. Preconditions: - Audit and program, and different control created via REST API """ # 'actual_controls': created_at, updated_at, custom_attributes (None) expected_control = entity.Entity.extract_objs_wo_excluded_attrs( [new_control_rest.repr_ui()], *Representation.tree_view_attrs_to_exclude)[0] controls_ui_service = webui_service.ControlsService(selenium) controls_ui_service.map_objs_via_tree_view( src_obj=new_audit_rest, dest_objs=[new_control_rest]) actual_controls_count_in_tab_audit = ( controls_ui_service.get_count_objs_from_tab( src_obj=new_audit_rest)) actual_controls_in_audit = ( controls_ui_service.get_list_objs_from_tree_view( src_obj=new_audit_rest)) actual_controls_count_in_tab_program = ( controls_ui_service.get_count_objs_from_tab( src_obj=new_program_rest)) actual_controls_in_program = ( controls_ui_service.get_list_objs_from_tree_view( src_obj=new_program_rest)) assert (len([expected_control]) == actual_controls_count_in_tab_audit == actual_controls_count_in_tab_program) assert ([expected_control] == actual_controls_in_audit == actual_controls_in_program), ( messages.AssertionMessages.format_err_msg_equal( messages.AssertionMessages.format_err_msg_equal( [expected_control], actual_controls_in_audit), messages.AssertionMessages.format_err_msg_equal( [expected_control], actual_controls_in_program)))
def test_clonable_not_audit_related_objs_move_to_cloned_audit( self, create_and_clone_audit_w_params_to_update, selenium): """Check via UI that clonable not audit related objects Control, Program move to cloned Audit. Preconditions: -Execution and return of fixture 'create_and_clone_audit_w_params_to_update'. """ actual_audit = create_and_clone_audit_w_params_to_update[ "actual_audit"] expected_control = ( create_and_clone_audit_w_params_to_update["control"].repr_ui()) expected_program = ( create_and_clone_audit_w_params_to_update["program"].repr_ui()) actual_controls = (webui_service.ControlsService( selenium).get_list_objs_from_tree_view(src_obj=actual_audit)) actual_programs = (webui_service.ProgramsService( selenium).get_list_objs_from_tree_view(src_obj=actual_audit)) # 'actual_controls, actual_programs': created_at, updated_at, # custom_attributes (None) self.general_equal_assert([expected_control], actual_controls, *Representation.tree_view_attrs_to_exclude) self.general_equal_assert([expected_program], actual_programs, *Representation.tree_view_attrs_to_exclude)
def controls_service(selenium): """Controls service fixture.""" return webui_service.ControlsService(selenium)
def assert_cannot_delete_control(selenium, cntrl): """Assert that current user cannot delete control via UI.""" cntrl_info_page = webui_service.ControlsService( selenium).open_info_page_of_obj(cntrl) if cntrl_info_page.three_bbs.exists: assert cntrl_info_page.three_bbs.delete_option.exists is False
def create_control(selenium): """Create control via UI""" return webui_service.ControlsService(selenium).create_obj()