Beispiel #1
0
 def get_session(self, obj_dict):
   """Return newly create session if it is external user needed else
   session from the pool."""
   return session_pool.create_session(
       users.current_user(), is_external=True) if (
       self.is_external_user_needed(obj_dict)) else (
       session_pool.get_session(users.current_user()))
Beispiel #2
0
def _login_if_needed(driver):
  """Login as current user if not already logged in"""
  current_user = users.current_user()
  current_logged_in_user = users.current_logged_in_user(users.UI_USER)
  if (not current_logged_in_user or
     current_logged_in_user.email != current_user.email):
    driver.delete_all_cookies()
    driver.get(url_module.Urls().gae_login(current_user))
    users.set_current_logged_in_user(users.UI_USER, users.current_user())
Beispiel #3
0
 def __init__(self):
   super(AssessmentsFactory, self).__init__(objects.ASSESSMENTS)
   self.admins = [users.current_user()]
   self._acl_roles = [
       ("creators", roles.ACLRolesIDs.ASSESSMENT_CREATORS,
        [users.current_user()]),
       ("assignees", roles.ACLRolesIDs.ASSESSMENT_ASSIGNEES,
        [users.current_user()]),
       ("verifiers", roles.ACLRolesIDs.ASSESSMENT_VERIFIERS, [])
   ]
Beispiel #4
0
def approve_obj_review(selenium, obj):
  """Approve obj review.
  Returns obj with approved review."""
  _get_ui_service(selenium, obj).approve_review(obj)
  exp_review = entities_factory.ReviewsFactory().create(
      is_add_rest_attrs=True,
      status=element.ReviewStates.REVIEWED,
      last_reviewed_by=users.current_user().email,
      last_reviewed_at=rest_facade.get_last_review_date(obj),
      reviewers=users.current_user())
  obj.review = exp_review.convert_review_to_dict()
  obj.review_status = exp_review.status
  return obj
Beispiel #5
0
def undo_obj_review_approval(selenium, obj):
  """Cancel approved obj review.
  Returns obj with reverted to unreviewed status review."""
  _get_ui_service(selenium, obj).undo_review_approval(obj)
  exp_review = entities_factory.ReviewsFactory().create(
      is_add_rest_attrs=True,
      status=element.ReviewStates.UNREVIEWED,
      last_reviewed_by=users.current_user().email,
      last_reviewed_at=rest_facade.get_last_review_date(obj),
      reviewers=users.current_user())
  obj.review = exp_review.convert_review_to_dict()
  obj.review_status = exp_review.status
  return obj
Beispiel #6
0
def approve_obj_review(obj):
  """Returns obj with approved review."""
  rest_review = get_obj_review(obj)
  rest_service.ReviewService().update_obj(
      obj=rest_review, status=element.ReviewStates.REVIEWED)
  exp_review = entities_factory.ReviewsFactory().create(
      is_add_rest_attrs=True,
      status=element.ReviewStates.REVIEWED,
      reviewers=users.current_user(),
      last_reviewed_by=users.current_user().email,
      last_reviewed_at=rest_review.last_reviewed_at)
  obj.review = exp_review.convert_review_to_dict()
  obj.review_status = exp_review.status
  return obj
Beispiel #7
0
def _login_if_needed(driver):
  """Login as current user if not already logged in"""
  current_user = users.current_user()
  current_logged_in_user = users.current_logged_in_user(users.UI_USER)
  if (not current_logged_in_user or
     current_logged_in_user.email != current_user.email):
    # Load another page to stop new cookies being set by the previous page.
    # Page could be any - GAE login page was chosen because it's loaded fast
    driver.get(url_module.Urls().gae_login(current_user))
    # remove `session` cookie
    driver.delete_all_cookies()
    # set `dev_appserver_login` cookie
    # `session` cookie will be set by any subsequent request based
    # on `dev_appserver_login` cookie
    driver.get(url_module.Urls().gae_login(current_user))
    users.set_current_logged_in_user(users.UI_USER, users.current_user())
Beispiel #8
0
 def generate_ca_value(cls, cad, attr_value=None):
   """Generate random CAV for CAD.
   Optionally set `attribute_value` of CAV to `attr_value`."""
   cad_type = cad.attribute_type
   attr_object = None
   attr_object_id = None
   if attr_value is None:
     if cad_type in (AdminWidgetCustomAttributes.TEXT,
                     AdminWidgetCustomAttributes.RICH_TEXT):
       attr_value = cls.generate_string(cad_type)
     if cad_type == AdminWidgetCustomAttributes.DATE:
       attr_value = unicode(cad.created_at[:10])
     if cad_type == AdminWidgetCustomAttributes.CHECKBOX:
       attr_value = random.choice((True, False))
     if cad_type == AdminWidgetCustomAttributes.DROPDOWN:
       attr_value = unicode(
           random.choice(cad.multi_choice_options.split(",")))
   if cad_type == AdminWidgetCustomAttributes.PERSON:
     person_id = users.current_user().id
     attr_object = {"id": person_id, "type": "Person"}
     attr_object_id = person_id
     attr_value = "Person"
   return entity.CustomAttributeValueEntity(
       attribute_object=attr_object,
       attribute_object_id=attr_object_id,
       attribute_value=attr_value,
       custom_attribute_id=cad.id
   )
Beispiel #9
0
 def __init__(self, endpoint=""):
   self.endpoint = endpoint if endpoint == url_module.QUERY else (
       objects.get_singular(endpoint))
   self.is_api = "" if endpoint == url_module.QUERY else url_module.API
   self.endpoint_url = urlparse.urljoin(
       environment.app_url, "/".join([self.is_api, endpoint]))
   self.session = session_pool.get_session(users.current_user())
Beispiel #10
0
 def __init__(self):
   super(AuditsFactory, self).__init__(objects.AUDITS)
   self._acl_roles = [
       ("audit_captains", roles.ACLRolesIDs.AUDIT_CAPTAINS,
        [users.current_user()]),
       ("auditors", roles.ACLRolesIDs.AUDITORS, [])
   ]
Beispiel #11
0
 def test_data(self):
   """Creates an activated workflow with close due date."""
   if not TestActivateWorkflow._data:
     app_workflow = workflow_rest_facade.create_workflow()
     task_group = workflow_rest_facade.create_task_group(
         workflow=app_workflow)
     assignee = person_rest_facade.create_person_with_role(roles.CREATOR)
     due_date = date_utils.first_working_day_after_today(
         datetime.date.today())
     workflow_rest_facade.create_task_group_task(
         task_group=task_group, assignees=[assignee], due_date=due_date)
     workflow_rest_service.WorkflowRestService().activate(app_workflow)
     emails = daily_emails_ui_facade.get_emails_by_user_names(
         [users.current_user().name, assignee.name])
     TestActivateWorkflow._data = {
         "wf": app_workflow,
         "wf_creator_email": emails[users.current_user().name],
         "assignee_email": emails[assignee.name]}
   return TestActivateWorkflow._data
 def test_create_control_no_modal(self, soft_assert, selenium,
                                  login_as_person_with_role):
     """Test to check that no modal present
 after starting create object control."""
     if users.current_user().system_wide_role == roles.ADMINISTRATOR:
         pytest.xfail(reason="GGRC-6934 Create object is not present.")
     obj_modal = webui_facade.open_create_obj_modal(
         obj_type=objects.get_singular(objects.CONTROLS, title=True))
     webui_facade.soft_assert_no_modals_present(obj_modal, soft_assert)
     soft_assert.assert_expectations()
Beispiel #13
0
def create_asmt(selenium, audit):
  """Create audit via UI."""
  expected_asmt = entities_factory.AssessmentsFactory().create()
  asmts_ui_service = webui_service.AssessmentsService(selenium)
  asmts_ui_service.create_obj_via_tree_view(
      src_obj=audit, obj=expected_asmt)
  asmt_tree_view = generic_widget.TreeView(
      selenium, None, objects.ASSESSMENTS)
  expected_asmt.url = (
      asmt_tree_view.get_obj_url_from_tree_view_by_title(expected_asmt.title))
  expected_asmt.id = expected_asmt.url.split('/')[-1]
  expected_asmt_rest = rest_facade.get_obj(expected_asmt)
  expected_asmt.assignees = audit.audit_captains
  expected_asmt.creators = [users.current_user().email]
  expected_asmt.verifiers = audit.auditors
  expected_asmt.created_at = expected_asmt_rest.created_at
  expected_asmt.modified_by = users.current_user().email
  expected_asmt.updated_at = expected_asmt_rest.updated_at
  return expected_asmt
Beispiel #14
0
def create_asmt(selenium, audit):
    """Create audit via UI."""
    expected_asmt = entities_factory.AssessmentsFactory().create()
    asmts_ui_service = webui_service.AssessmentsService(selenium)
    asmts_ui_service.create_obj_via_tree_view(src_obj=audit, obj=expected_asmt)
    asmt_tree_view = generic_widget.TreeView(selenium, None,
                                             objects.ASSESSMENTS)
    expected_asmt_url = (asmt_tree_view.get_obj_url_from_tree_view_by_title(
        expected_asmt.title))
    expected_asmt.id = expected_asmt_url.split('/')[-1]
    expected_asmt_rest = rest_facade.get_obj(expected_asmt)
    expected_asmt.url = expected_asmt_url
    expected_asmt.assignees = audit.audit_captains
    expected_asmt.creators = [users.current_user().email]
    expected_asmt.verifiers = audit.auditors
    expected_asmt.created_at = expected_asmt_rest.created_at
    expected_asmt.modified_by = users.current_user().email
    expected_asmt.updated_at = expected_asmt_rest.updated_at
    return expected_asmt
Beispiel #15
0
def send_post(url, json_body):
  """Sends POST request to `url` with `json_body`."""
  url = urlparse.urljoin(environment.app_url, url)
  if objects.CONTROLS in url:
    return requests.post(
        url=url,
        data=json.dumps(json_body),
        headers=session_pool.create_session(
            users.current_user(), is_external=True).headers)
  return _user_session().post(url, json=json_body)
def custom_read_role(object_type):
    """Creates and returns custom access control role for object with 'Read'
  rights."""
    current_user = users.current_user()
    users.set_current_user(entities_factory.PeopleFactory.superuser)
    role = rest_facade.create_access_control_role(object_type=object_type,
                                                  read=True,
                                                  update=False,
                                                  delete=False)
    users.set_current_user(current_user)
    return role
Beispiel #17
0
 def test_create_risk(self, selenium):
     """Tests risk creation via UI."""
     risk = entities_factory.RisksFactory().create()
     actual_risk = webui_service.RisksService(
         selenium).create_obj_and_get_obj(risk)
     rest_risk = rest_facade.get_obj(actual_risk)
     risk.update_attrs(created_at=rest_risk.created_at,
                       updated_at=rest_risk.updated_at,
                       modified_by=users.current_user(),
                       slug=rest_risk.slug,
                       url=rest_risk.url).repr_ui()
     self.general_equal_assert(risk, actual_risk, "custom_attributes")
Beispiel #18
0
def _assert_title_editable(obj, ui_service, info_page):
  """Assert that user can edit object's title"""
  new_title = "[EDITED]" + obj.title
  info_page.open_info_3bbs().select_edit().edit_minimal_data(
      title=new_title).save_and_close()
  obj.update_attrs(
      title=new_title, modified_by=users.current_user().email,
      updated_at=rest_service.ObjectsInfoService().get_obj(
          obj=obj).updated_at)
  new_ui_obj = ui_service.get_obj_from_info_page(obj)
  base.Test.general_equal_assert(
      obj.repr_ui(), new_ui_obj, "custom_attributes")
Beispiel #19
0
def _assert_title_editable(obj, ui_service, info_page):
  """Assert that user can edit object's title"""
  new_title = "[EDITED]" + obj.title
  info_page.open_info_3bbs().select_edit().edit_minimal_data(
      title=new_title).save_and_close()
  obj.update_attrs(
      title=new_title, modified_by=users.current_user().email,
      updated_at=rest_service.ObjectsInfoService().get_obj(
          obj=obj).updated_at)
  new_ui_obj = ui_service.get_obj_from_info_page(obj)
  base.Test.general_equal_assert(
      obj.repr_ui(), new_ui_obj, "audit", "custom_attributes")
Beispiel #20
0
 def generate_custom_attributes(cls, cads):
   """Generate random dictionary of {cad.title: value}."""
   result_dict = {}
   for cad in cads:
     cad_type = cad.attribute_type
     if cad_type == AdminWidgetCustomAttributes.PERSON:
       attr_value = users.current_user().email
     else:
       attr_value = CustomAttributeDefinitionsFactory.generate_cav(
           cad).attribute_value
     result_dict[cad.title.upper()] = attr_value
   return result_dict
Beispiel #21
0
 def _create_random_obj(self, is_add_rest_attrs):
   """Create Comment entity with randomly and predictably filled fields, if
   'is_add_rest_attrs' then add attributes for REST."""
   comment_obj = self.obj_inst().update_attrs(
       description=self.obj_title,
       modified_by=users.current_user().name)
   if is_add_rest_attrs:
     comment_obj.update_attrs(
         assignee_type=",".join((
             unicode(roles.PRIMARY_CONTACTS),
             unicode(roles.SECONDARY_CONTACTS))))
   return comment_obj
Beispiel #22
0
 def test_obj_history_is_updated(self, program_with_approved_review,
                                 selenium):
   """Confirm Review history is updated in Change Log."""
   expected_entry = {
       "author": users.current_user().email,
       "Review State": {"original_value": element.ReviewStates.UNREVIEWED,
                        "new_value": element.ReviewStates.REVIEWED}}
   actual_entries = (webui_service.ProgramsService(selenium).
                     open_info_page_of_obj(program_with_approved_review).
                     get_changelog_entries())
   assert (expected_entry == actual_entries.pop(0) and
           expected_entry not in actual_entries)
Beispiel #23
0
 def generate_custom_attributes(cls, cads):
     """Generate random dictionary of {cad.title: value}."""
     result_dict = {}
     for cad in cads:
         cad_type = cad.attribute_type
         if cad_type == AdminWidgetCustomAttributes.PERSON:
             attr_value = users.current_user().email
         else:
             attr_value = CustomAttributeDefinitionsFactory.generate_cav(
                 cad).attribute_value
         result_dict[cad.title.upper()] = attr_value
     return result_dict
 def _create_random_obj(self, is_add_rest_attrs):
   """Create Comment entity with randomly and predictably filled fields, if
   'is_add_rest_attrs' then add attributes for REST."""
   comment_obj = self.obj_inst().update_attrs(
       description=self.obj_title,
       modified_by=users.current_user().email)
   if is_add_rest_attrs:
     comment_obj.update_attrs(
         assignee_type=",".join((
             unicode(roles.PRIMARY_CONTACTS),
             unicode(roles.SECONDARY_CONTACTS))))
   return comment_obj
Beispiel #25
0
 def test_obj_history_is_updated(self, program_with_approved_review,
                                 selenium):
   """Confirm Review history is updated in Change Log."""
   expected_entry = {
       "author": users.current_user().email,
       "Review State": {"original_value": element.ReviewStates.UNREVIEWED,
                        "new_value": element.ReviewStates.REVIEWED}}
   actual_entries = (webui_service.ProgramsService(selenium).
                     open_info_page_of_obj(program_with_approved_review).
                     get_changelog_entries())
   assert (expected_entry == actual_entries.pop(0) and
           expected_entry not in actual_entries)
Beispiel #26
0
 def test_create_program(self, selenium):
     """Tests program creation via UI."""
     program = entities_factory.ProgramsFactory().create()
     actual_program = webui_service.ProgramsService(
         selenium).create_obj_and_get_obj(program)
     rest_program = rest_facade.get_obj(actual_program)
     program.update_attrs(created_at=rest_program.created_at,
                          updated_at=rest_program.updated_at,
                          modified_by=users.current_user(),
                          slug=rest_program.slug,
                          url=rest_program.url).repr_ui()
     self.general_equal_assert(program, actual_program, "custom_attributes")
Beispiel #27
0
 def test_create_program(self, selenium):
   """Tests program creation via UI."""
   program = entities_factory.ProgramsFactory().create()
   actual_program = webui_service.ProgramsService(
       selenium).create_obj_and_get_obj(program)
   rest_program = rest_facade.get_obj(actual_program)
   program.update_attrs(
       created_at=rest_program.created_at,
       updated_at=rest_program.updated_at,
       modified_by=users.current_user(),
       slug=rest_program.slug,
       url=rest_program.url).repr_ui()
   self.general_equal_assert(program, actual_program, "custom_attributes")
Beispiel #28
0
 def test_data(self):
     """Creates an activated workflow with close due date."""
     if not TestActivateWorkflow._data:
         app_workflow = workflow_rest_facade.create_workflow()
         task_group = workflow_rest_facade.create_task_group(
             workflow=app_workflow)
         assignee = person_rest_facade.create_person_with_role(
             roles.CREATOR)
         due_date = date_utils.first_working_day_after_today(
             datetime.date.today())
         workflow_rest_facade.create_task_group_task(task_group=task_group,
                                                     assignees=[assignee],
                                                     due_date=due_date)
         workflow_rest_service.WorkflowRestService().activate(app_workflow)
         emails = daily_emails_ui_facade.get_emails_by_user_names(
             [users.current_user().name, assignee.name])
         TestActivateWorkflow._data = {
             "wf": app_workflow,
             "wf_creator_email": emails[users.current_user().name],
             "assignee_email": emails[assignee.name]
         }
     return TestActivateWorkflow._data
Beispiel #29
0
 def test_create_risk(self, selenium):
   """Tests risk creation via UI."""
   risk = entities_factory.RisksFactory().create()
   actual_risk = webui_service.RisksService(
       selenium).create_obj_and_get_obj(risk)
   rest_risk = rest_facade.get_obj(actual_risk)
   risk.update_attrs(
       created_at=rest_risk.created_at,
       updated_at=rest_risk.updated_at,
       modified_by=users.current_user(),
       slug=rest_risk.slug,
       url=rest_risk.url).repr_ui()
   self.general_equal_assert(risk, actual_risk, "custom_attributes")
Beispiel #30
0
 def test_create_org_group(self, selenium):
   """Tests Org Group creation via UI."""
   org_group = entities_factory.OrgGroupsFactory().create()
   actual_org_group = webui_service.OrgGroupsService(
       selenium).create_obj_and_get_obj(org_group)
   rest_org_group = rest_facade.get_obj(actual_org_group)
   org_group.update_attrs(
       created_at=rest_org_group.created_at,
       updated_at=rest_org_group.updated_at,
       modified_by=users.current_user(),
       slug=rest_org_group.slug,
       url=rest_org_group.url).repr_ui()
   self.general_equal_assert(org_group, actual_org_group, "custom_attributes")
 def test_create_org_group(self, selenium):
     """Tests Org Group creation via UI."""
     org_group = entities_factory.OrgGroupsFactory().create()
     actual_org_group = webui_service.OrgGroupsService(
         selenium).create_obj_and_get_obj(org_group)
     rest_org_group = rest_facade.get_obj(actual_org_group)
     org_group.update_attrs(created_at=rest_org_group.created_at,
                            updated_at=rest_org_group.updated_at,
                            modified_by=users.current_user(),
                            slug=rest_org_group.slug,
                            url=rest_org_group.url).repr_ui()
     self.general_equal_assert(org_group, actual_org_group,
                               "custom_attributes")
Beispiel #32
0
def _assert_title_editable(obj, selenium, info_page):
    """Assert that user can edit object's title"""
    new_title = "[EDITED]" + obj.title
    info_page.three_bbs.select_edit()
    modal = object_modal.get_modal_obj(obj.type, selenium)
    modal.fill_form(title=new_title)
    modal.save_and_close()
    obj.update_attrs(title=new_title,
                     modified_by=users.current_user().email,
                     updated_at=rest_service.ObjectsInfoService().get_obj(
                         obj=obj).updated_at)
    new_ui_obj = _get_ui_service(selenium, obj).get_obj_from_info_page(obj)
    base.Test.general_equal_assert(obj.repr_ui(), new_ui_obj, "audit",
                                   "custom_attributes")
Beispiel #33
0
def _assert_title_editable(obj, selenium, info_page):
  """Assert that user can edit object's title"""
  new_title = "[EDITED]" + obj.title
  info_page.three_bbs.select_edit()
  modal = object_modal.get_modal_obj(obj.type, selenium)
  modal.fill_form(title=new_title)
  modal.save_and_close()
  obj.update_attrs(
      title=new_title, modified_by=users.current_user().email,
      updated_at=rest_service.ObjectsInfoService().get_obj(
          obj=obj).updated_at)
  new_ui_obj = _get_ui_service(selenium, obj).get_obj_from_info_page(obj)
  base.Test.general_equal_assert(
      obj.repr_ui(), new_ui_obj, "audit", "custom_attributes")
Beispiel #34
0
 def test_create_audit(self, program, selenium):
   """Test creation of an audit via UI."""
   audit = entities_factory.AuditsFactory().create()
   audits_service = webui_service.AuditsService(selenium)
   audits_service.create_obj_via_tree_view(program, audit)
   tree_view_audit = audits_service.get_list_objs_from_tree_view(program)[0]
   actual_audit = audits_service.get_obj_from_info_page(tree_view_audit)
   rest_audit = rest_facade.get_obj(actual_audit)
   audit.update_attrs(
       created_at=rest_audit.created_at,
       updated_at=rest_audit.updated_at,
       modified_by=users.current_user(),
       slug=rest_audit.slug).repr_ui()
   self.check_ggrc_7048(audit, actual_audit)
Beispiel #35
0
 def test_create_audit(self, program, selenium):
     """Test creation of an audit via UI."""
     audit = entities_factory.AuditsFactory().create()
     audits_service = webui_service.AuditsService(selenium)
     audits_service.create_obj_via_tree_view(program, audit)
     tree_view_audit = audits_service.get_list_objs_from_tree_view(
         program)[0]
     actual_audit = audits_service.get_obj_from_info_page(tree_view_audit)
     rest_audit = rest_facade.get_obj(actual_audit)
     audit.update_attrs(created_at=rest_audit.created_at,
                        updated_at=rest_audit.updated_at,
                        modified_by=users.current_user(),
                        slug=rest_audit.slug).repr_ui()
     self.general_equal_assert(audit, actual_audit, "custom_attributes")
Beispiel #36
0
 def test_object_creation(self, role, selenium):
   """Test that users with all global roles can create, then edit and delete
   objects.
   """
   user = rest_facade.create_user_with_role(role_name=role)
   users.set_current_user(user)
   objs = [rest_facade.create_program(), rest_facade.create_control(
       admins=[users.current_user()])]
   for obj in objs:
     if obj.type == "Control":
       webui_facade.assert_can_edit_control(selenium, obj, can_edit=True)
       webui_facade.assert_cannot_delete_control(selenium, obj)
     else:
       webui_facade.assert_can_edit(selenium, obj, can_edit=True)
       webui_facade.assert_can_delete(selenium, obj, can_delete=True)
Beispiel #37
0
def soft_assert_bulk_verify_filter_ui_elements(modal, soft_assert):
  """Checks that filter section of bulk verify modal has 'Reset to Default'
  button, exactly 2 states options: 'Select all', 'In Review', and default
  filter for current user as a verifier."""
  filter_section_element = modal.filter_section.expand()
  soft_assert.expect(
      filter_section_element.reset_to_default_button.exists,
      "'Reset to Default' button should be displayed in filter section.")
  soft_assert.expect(
      filter_section_element.get_state_filter_options() == [
          'Select All', 'In Review'],
      "Filter should contain exactly 2 options: 'Select All', 'In Review'.")
  expected_filters = [{"attr_name": "Verifiers", "compare_op": "Contains",
                       "value": users.current_user().email}]
  soft_assert.expect(
      filter_section_element.get_filters_dicts() == expected_filters,
      "Modal should contain default filter for current user as a verifier.")
 def test_create_and_map_control(self, program, selenium):
     """Test that control can be created and mapped using Unified mapper."""
     controls_service = webui_service.ControlsService(selenium)
     controls_service.open_widget_of_mapped_objs(
         program).tree_view.open_map().click_create_and_map_obj()
     control = entities_factory.ControlsFactory().create()
     controls_service.submit_obj_modal(control)
     tree_view_control = controls_service.get_list_objs_from_tree_view(
         program)[0]
     actual_control = controls_service.get_obj_from_info_page(
         tree_view_control)
     rest_control = rest_facade.get_obj(actual_control)
     control.update_attrs(created_at=rest_control.created_at,
                          updated_at=rest_control.updated_at,
                          modified_by=users.current_user(),
                          slug=rest_control.slug).repr_ui()
     self.general_equal_assert(control, actual_control, "custom_attributes")
 def test_create_and_map_control(self, set_external_user_as_current_user,
                                 program, selenium):
     """Test that control can be created and mapped using Unified mapper."""
     # pylint: disable=unused-argument
     from lib.service import webui_facade
     control = webui_facade.create_control_in_program_scope(
         selenium, program)
     controls_service = webui_service.ControlsService(selenium)
     tree_view_control = controls_service.get_list_objs_from_tree_view(
         program)[0]
     actual_control = controls_service.get_obj_from_info_page(
         tree_view_control)
     rest_control = rest_facade.get_obj(actual_control)
     control.update_attrs(created_at=rest_control.created_at,
                          updated_at=rest_control.updated_at,
                          modified_by=users.current_user(),
                          slug=rest_control.slug).repr_ui()
     self.general_equal_assert(control, actual_control, "custom_attributes")
Beispiel #40
0
 def test_object_creation(self, role, selenium):
     """Test that users with all global roles can create, then edit and delete
 objects.
 """
     user = rest_facade.create_user_with_role(role_name=role)
     users.set_current_user(user)
     objs = [
         rest_facade.create_program(),
         rest_facade.create_control(admins=[users.current_user()])
     ]
     for obj in objs:
         if obj.type == "Control":
             webui_facade.assert_can_edit_control(selenium,
                                                  obj,
                                                  can_edit=True)
             webui_facade.assert_cannot_delete_control(selenium, obj)
         else:
             webui_facade.assert_can_edit(selenium, obj, can_edit=True)
             webui_facade.assert_can_delete(selenium, obj, can_delete=True)
Beispiel #41
0
 def test_auditor_can_assign_user_to_asmt(self, selenium, test_data):
     """Preconditions:
 Global editor creates program with mapped control.
 Global editor creates audit and assigns Global Creator user as an auditor
 - log in as GC
 - navigate to audit page => Assessments tab
 Test that GC can assign user to new asmt in audit."""
     # pylint: disable=invalid-name
     creator = test_data["creator"]
     users.set_current_user(creator)
     audit = test_data["audit"]
     expected_asmt = rest_facade.create_asmt(audit)
     asmt_service = webui_service.AssessmentsService(selenium)
     asmt_service.add_asignee(expected_asmt, test_data["editor"])
     expected_asmt.update_attrs(
         updated_at=rest_facade.get_obj(expected_asmt).updated_at,
         assignees=[creator.email, test_data["editor"].email],
         modified_by=users.current_user().email)
     webui_facade.assert_can_view(selenium, expected_asmt)
Beispiel #42
0
 def test_auditor_can_assign_user_to_asmt(
     self, selenium, test_data
 ):
   """Preconditions:
   Global editor creates program with mapped control.
   Global editor creates audit and assigns Global Creator user as an auditor
   - log in as GC
   - navigate to audit page => Assessments tab
   Test that GC can assign user to new asmt in audit."""
   # pylint: disable=invalid-name
   creator = test_data["creator"]
   users.set_current_user(creator)
   audit = test_data["audit"]
   expected_asmt = rest_facade.create_assessment(audit)
   asmt_service = webui_service.AssessmentsService(selenium)
   asmt_service.add_asignee(expected_asmt, test_data["editor"])
   expected_asmt.update_attrs(
       updated_at=rest_facade.get_obj(expected_asmt).updated_at,
       assignees=[creator.email, test_data["editor"].email],
       modified_by=users.current_user().email)
   webui_facade.assert_can_view(selenium, expected_asmt)
Beispiel #43
0
 def test_asmt_creation_with_mapping(self, program, obj, audit, selenium):
     """Check if Assessment can be created with mapped snapshot via
 Modal Create on Assessments TreeView.
 Objects structure:
 Program
 -> Obj (Control or Objective)
 -> Audit
 """
     expected_asmt = (entities_factory.AssessmentsFactory().create(
         mapped_objects=[obj]))
     asmts_service = webui_service.AssessmentsService(selenium)
     asmts_service.create_obj_via_tree_view(src_obj=audit,
                                            obj=expected_asmt)
     tree_view_asmt = asmts_service.get_list_objs_from_tree_view(audit)[0]
     actual_asmt = asmts_service.get_obj_from_info_page(tree_view_asmt)
     rest_asmt = rest_facade.get_obj(actual_asmt)
     expected_asmt.update_attrs(created_at=rest_asmt.created_at,
                                updated_at=rest_asmt.updated_at,
                                modified_by=users.current_user(),
                                slug=rest_asmt.slug).repr_ui()
     self.general_equal_assert(expected_asmt, actual_asmt,
                               "custom_attributes")
Beispiel #44
0
 def test_asmt_creation_with_mapping(
     self, program, obj, audit, selenium
 ):
   """Check if Assessment can be created with mapped snapshot via
   Modal Create on Assessments TreeView.
   Objects structure:
   Program
   -> Obj (Control or Objective)
   -> Audit
   """
   expected_asmt = (
       entities_factory.AssessmentsFactory().create(mapped_objects=[obj]))
   asmts_service = webui_service.AssessmentsService(selenium)
   asmts_service.create_obj_via_tree_view(src_obj=audit, obj=expected_asmt)
   tree_view_asmt = asmts_service.get_list_objs_from_tree_view(audit)[0]
   actual_asmt = asmts_service.get_obj_from_info_page(tree_view_asmt)
   rest_asmt = rest_facade.get_obj(actual_asmt)
   expected_asmt.update_attrs(
       created_at=rest_asmt.created_at,
       updated_at=rest_asmt.updated_at,
       modified_by=users.current_user(),
       slug=rest_asmt.slug).repr_ui()
   self.general_equal_assert(expected_asmt, actual_asmt, "custom_attributes")
Beispiel #45
0
 def __init__(self):
   super(ProgramsFactory, self).__init__(objects.PROGRAMS)
   self._acl_roles = [
       ("managers", roles.ACLRolesIDs.PROGRAM_MANAGERS,
        [users.current_user()])
   ]
Beispiel #46
0
 def _create_random_obj(self, is_add_rest_attrs):
     """Create Proposal entity."""
     return self.obj_inst().update_attrs(is_allow_none=False,
                                         author=users.current_user().email,
                                         status=unicode(
                                             object_states.PROPOSED))
Beispiel #47
0
 def __init__(self):
     super(IssuesFactory, self).__init__(objects.ISSUES)
     self._acl_roles = [("admins", roles.ACLRolesIDs.ISSUE_ADMINS,
                         [users.current_user()])]
Beispiel #48
0
 def __init__(self):
     super(AuditsFactory, self).__init__(objects.AUDITS)
     self._acl_roles = [("audit_captains", roles.ACLRolesIDs.AUDIT_CAPTAINS,
                         [users.current_user()]),
                        ("auditors", roles.ACLRolesIDs.AUDITORS, [])]
Beispiel #49
0
 def __init__(self):
     super(OrgGroupsFactory, self).__init__(objects.ORG_GROUPS)
     self._acl_roles = [("admins", roles.ACLRolesIDs.ORG_GROUPS_ADMINS,
                         [users.current_user()])]
Beispiel #50
0
 def __init__(self):
     super(RisksFactory, self).__init__(objects.RISKS)
     self._acl_roles = [("admins", roles.ACLRolesIDs.RISK_ADMINS,
                         [users.current_user()])]
Beispiel #51
0
    def tested_events(self, selenium):
        """Create events to verify events functionality:
    0. Save event log count before test data creation,
    1. Create objective editor role, create 2 users with global creator role
    under admin
    2. Create objective#1 under global creator#1 and set global creator#2 to
    newly created objective editor role
    3. Create objective#2 under global objective#2 and map it objective#1
    """
        if not self.__class__._data:
            # generate enough data, so test can be executed independently
            for _ in xrange(6):
                rest_facade.create_user_with_role(roles.READER)

            initial_count = self.get_event_tab().tab_events.count
            objctv1_creator = rest_facade.create_user_with_role(roles.CREATOR)
            objctv2_creator = rest_facade.create_user_with_role(roles.CREATOR)
            objctv_editor_role = rest_facade.create_access_control_role(
                object_type="Objective", read=True, update=True, delete=True)
            admin = users.current_user()
            users.set_current_user(objctv1_creator)
            objctv_custom_roles = [(objctv_editor_role.name,
                                    objctv_editor_role.id, [objctv2_creator])]
            objctv1 = rest_facade.create_objective(
                custom_roles=objctv_custom_roles)
            # wait until notification and acl will assigned by background task
            rest_facade.get_obj(objctv1_creator)

            users.set_current_user(objctv2_creator)
            objctv2 = rest_facade.create_objective()
            rest_facade.map_objs(objctv1, objctv2)

            users.set_current_user(admin)
            # generate expected event data
            from lib.constants.roles import ACLRolesIDs
            # 3 predefined program roles and 1 predefined reviewer role
            acl_roles_len = len(ACLRolesIDs.object_roles(objctv1.type)) - 4
            exp_event_data = [{
                "actions":
                sorted([
                    objctv1_creator.email + " created",
                    u"PersonProfile created"
                ]),
                "user_email":
                admin.email,
                "time":
                date_utils.iso8601_to_local_datetime(
                    objctv1_creator.updated_at)
            }, {
                "actions": ["Creator linked to " + objctv1_creator.email],
                "user_email":
                admin.email,
                "time":
                date_utils.iso8601_to_local_datetime(
                    objctv1_creator.updated_at)
            }, {
                "actions":
                sorted([
                    objctv2_creator.email + " created",
                    u"PersonProfile created"
                ]),
                "user_email":
                admin.email,
                "time":
                date_utils.iso8601_to_local_datetime(
                    objctv2_creator.updated_at)
            }, {
                "actions": ["Creator linked to " + objctv2_creator.email],
                "user_email":
                admin.email,
                "time":
                date_utils.iso8601_to_local_datetime(
                    objctv2_creator.updated_at)
            }, {
                "actions": [objctv_editor_role.name + " created"],
                "user_email":
                admin.email,
                "time":
                date_utils.iso8601_to_local_datetime(
                    objctv_editor_role.updated_at)
            }, {
                "actions": [u"AccessControlList created"] * acl_roles_len +
                [u"AccessControlPerson created"] * 2 +
                [objctv1.title + " created"],
                "user_email":
                objctv1_creator.email,
                "time":
                date_utils.iso8601_to_local_datetime(objctv1.updated_at)
            }, {
                "actions": [u"AccessControlList created"] * acl_roles_len +
                [u"AccessControlPerson created", objctv2.title + " created"],
                "user_email":
                objctv2_creator.email,
                "time":
                date_utils.iso8601_to_local_datetime(objctv2.updated_at)
            }, {
                "actions": [
                    u"{type2}:{id2} linked to {type1}:{id1}".format(
                        id1=objctv1.id,
                        id2=objctv2.id,
                        type1=objctv1.type,
                        type2=objctv2.type)
                ],
                "user_email":
                objctv2_creator.email,
                "time":
                date_utils.iso8601_to_local_datetime(objctv2.updated_at)
            }]
            exp_event_data.reverse()
            self.__class__._data = {
                "objctv1_creator": objctv1_creator,
                "objctv2_creator": objctv2_creator,
                "objctv_editor_role": objctv_editor_role,
                "objctv1": objctv1,
                "objctv2": objctv2,
                "exp_added_events": exp_event_data,
                "initial_count": initial_count
            }
        return self.__class__._data
Beispiel #52
0
 def __init__(self):
     super(ControlsFactory, self).__init__(objects.CONTROLS)
     self._acl_roles = [("admins", roles.ACLRolesIDs.CONTROL_ADMINS,
                         [users.current_user()])]
Beispiel #53
0
 def __init__(self):
     super(ProgramsFactory, self).__init__(objects.PROGRAMS)
     self._acl_roles = [("managers", roles.ACLRolesIDs.PROGRAM_MANAGERS,
                         [users.current_user()])]
Beispiel #54
0
 def __init__(self):
   super(ControlsFactory, self).__init__(objects.CONTROLS)
   self._acl_roles = [
       ("admins", roles.ACLRolesIDs.CONTROL_ADMINS, [users.current_user()])
   ]
Beispiel #55
0
def check_user_menu_has_icons(user_menu):
    """Check user menu list has icons."""
    for item in user_menu.user_menu_items:
        assert item.element.find_element_by_class_name('fa').get_attribute(
            'class') != ''
    assert user_menu.email.text == users.current_user().name
Beispiel #56
0
 def __init__(self):
   super(ObjectivesFactory, self).__init__(objects.OBJECTIVES)
   self._acl_roles = [
       ("admins", roles.ACLRolesIDs.OBJECTIVE_ADMINS, [users.current_user()])
   ]
Beispiel #57
0
 def __init__(self, endpoint=""):
   self.is_api = "" if endpoint == url_module.QUERY else url_module.API
   self.endpoint_url = urlparse.urljoin(
       environment.app_url, "/".join([self.is_api, endpoint]))
   self.session = session_pool.get_session(users.current_user())
Beispiel #58
0
def check_user_menu_has_icons(user_menu):
  """Check user menu list has icons."""
  for item in user_menu.user_menu_items:
    assert item.element.find_element_by_class_name(
        'fa').get_attribute('class') != ''
  assert user_menu.email.text == users.current_user().name
Beispiel #59
0
 def __init__(self):
     super(ObjectivesFactory, self).__init__(objects.OBJECTIVES)
     self._acl_roles = [("admins", roles.ACLRolesIDs.OBJECTIVE_ADMINS,
                         [users.current_user()])]
Beispiel #60
0
 def __init__(self):
   super(IssuesFactory, self).__init__(objects.ISSUES)
   self._acl_roles = [
       ("admins", roles.ACLRolesIDs.ISSUE_ADMINS, [users.current_user()])
   ]