Пример #1
0
def add_user(url_origin):
    """If two processes log in as a new user at the same time,
  the second login may fail because of a race condition in dev code
  (user_generator.py).
  We workaround this issue by creating a user not in parallel as this issue
  is considered not worth to fix by developers.
  """
    from lib.entities import entities_factory
    import json
    from lib.service.rest.template_provider import TemplateProvider
    from lib.service.rest import session_pool
    environment.app_url = url_origin
    environment.app_url = urlparse.urljoin(environment.app_url, "/")
    session = requests.Session()
    test_utils.wait_for(
        lambda: session.get(environment.app_url).status_code == OK_CODE,
        constants.timeouts.TWO_MIN_USER_WAIT * 4)
    test_utils.wait_for(lambda: session.get(url_module.Urls().gae_login(
        users.FAKE_SUPER_USER)).status_code == OK_CODE)
    test_utils.wait_for(
        lambda: session.get(url_module.Urls().login).status_code == OK_CODE)
    person_dict = entities_factory.PeopleFactory().create(
        is_add_rest_attrs=True, **{}).__dict__
    url = environment.app_url + "api/people"
    body = json.dumps([
        TemplateProvider.generate_template_as_dict(json_tmpl_name='person',
                                                   **person_dict)
    ]).encode("string-escape")
    test_utils.wait_for(lambda: session.post(
        url=url, data=body, headers=session_pool.BASIC_HEADERS).status_code ==
                        OK_CODE)
Пример #2
0
 def get_session_cookie(self):
     """Send GET request to login URL, get response and return session
 cookie from response headers for further usage.
 """
     session = requests.Session()
     session.get(url.Urls().gae_login)
     session.get(url.Urls().login)
     self.session_cookie = session.cookies["session"]
Пример #3
0
def add_user(url_origin):
    """If two processes log in as a new user at the same time,
  the second login may fail because of a race condition in dev code
  (user_generator.py).
  We workaround this issue by creating a user not in parallel as this issue
  is considered not worth to fix by developers.
  """
    environment.app_url = url_origin
    environment.app_url = urlparse.urljoin(environment.app_url, "/")
    session = requests.Session()
    session.get(url_module.Urls().gae_login)
    session.get(url_module.Urls().login)
Пример #4
0
 def test_redirect(self, header_dashboard, selenium):
     """Tests if user is redirected to My Work page after clicking on
 the my work button in user dropdown."""
     header_dashboard.select_my_work()
     expected_url = url.Urls().dashboard + url.Widget.INFO
     actual_url = selenium.current_url
     assert expected_url == actual_url
Пример #5
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())
Пример #6
0
    def test_cannot_map_control_via_um_create_new_obj(self, control,
                                                      regulation,
                                                      dashboard_controls_tab,
                                                      selenium):
        """Tests that user cannot map control to scope objects/directives
    via unified mapper (create a new scope/directive object)."""
        expected_conditions = {
            "regulation_in_top_tabs": False,
            "new_tab_url": url.Urls().dashboard_info_tab
        }
        actual_conditions = copy.deepcopy(expected_conditions)

        dashboard_controls_tab.get_control(control).select_map_to_this_object()
        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()
        actual_conditions['new_tab_url'] = new_tab.url
        actual_conditions['regulation_in_top_tabs'] = (objects.get_normal_form(
            objects.REGULATIONS) in webui_service.ControlsService(
                selenium).open_info_page_of_obj(control).top_tabs.tab_names)
        assert expected_conditions == actual_conditions
Пример #7
0
def selenium(selenium, pytestconfig):
    """Create Web Driver instance."""
    if not selenium_utils.is_headless_chrome(pytestconfig):
        selenium.set_window_size(os.environ["SCREEN_WIDTH"],
                                 os.environ["SCREEN_HEIGHT"])
    dynamic_fixtures.dict_executed_fixtures.update({"selenium": selenium})
    selenium_utils.open_url(selenium, url.Urls().gae_login)
    yield selenium
Пример #8
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())
Пример #9
0
def get_lhn_accordion(driver, object_name):
  """Select relevant section in LHN and return relevant section accordion."""
  selenium_utils.open_url(url.Urls().dashboard)
  lhn_menu = dashboard.Header(driver).open_lhn_menu()
  # if object button not visible, open this section first
  if object_name in cache.LHN_SECTION_MEMBERS:
    method_name = factory.get_method_lhn_select(object_name)
    lhn_menu = getattr(lhn_menu, method_name)()
  return getattr(lhn_menu, constants.method.SELECT_PREFIX + object_name)()
Пример #10
0
 def test_add_obj_to_task_group(self, app_workflow, app_task_group,
                                app_control, selenium):
     """Test mapping of object to a task group."""
     workflow_ui_facade.add_obj_to_task_group(obj=app_control,
                                              task_group=app_task_group)
     # open another page to check mapping is saved
     selenium_utils.open_url(url.Urls().dashboard)
     objs = workflow_ui_facade.get_objs_added_to_task_group(app_task_group)
     test_utils.list_obj_assert(objs, [app_control])
Пример #11
0
    def _open_custom_attributes_tab(self):
        """Open Custom Attributes widget on Admin dashboard.

    Returns:
      lib.page.widget.admin_widget.CustomAttributes
    """
        selenium_utils.open_url(url.Urls().admin_dashboard)
        return dashboard.AdminDashboard(
            self._driver).select_custom_attributes()
Пример #12
0
 def test_destructive_obj_count(self, selenium):
     """Checks if count updates in LHN after creating new program."""
     selenium_utils.open_url(url.Urls().dashboard)
     count_before = dashboard.Header(selenium).open_lhn_menu(
     ).select_my_objects().toggle_programs.members_count
     rest_facade.create_program()
     selenium.refresh()
     count_after = dashboard.Header(selenium).open_lhn_menu(
     ).select_my_objects().toggle_programs.members_count
     assert count_after == count_before + 1
Пример #13
0
 def test_lhn_remembers_tab_state(self, header_dashboard, selenium):
     """Tests if LHN remembers which tab is selected (my or all objects) after
 closing it."""
     lhn_menu = header_dashboard.open_lhn_menu()
     # check if my objects tab saves state
     lhn_menu.select_my_objects()
     header_dashboard.close_lhn_menu()
     header_dashboard.open_user_list()
     selenium.get(url.Urls().dashboard)
     new_lhn_menu = dashboard.Header(selenium).open_lhn_menu()
     assert selenium_utils.is_value_in_attr(
         new_lhn_menu.my_objects.element) is True
     # check if all objects tab saves state
     lhn_menu = header_dashboard.open_lhn_menu()
     lhn_menu.select_all_objects()
     header_dashboard.close_lhn_menu()
     header_dashboard.open_user_list()
     assert selenium_utils.is_value_in_attr(
         new_lhn_menu.all_objects.element) is True
Пример #14
0
 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()
Пример #15
0
 def login(self):
     """Set dev_appserver_login and session cookies."""
     self.session.get(url.Urls().gae_login)
     self.session.get(url.Urls().login)
Пример #16
0
 def get_event_tab(cls):
     """Return Event tab page object."""
     selenium_utils.open_url(url.Urls().admin_dashboard)
     return dashboard.AdminDashboard().select_events()
Пример #17
0
 def _open_admin_people_tab(self):
     """Open People widget on Admin dashboard.
   - Return: lib.page.widget.admin_widget.People"""
     selenium_utils.open_url(url.Urls().admin_people_tab)
     return dashboard.AdminDashboard(self._driver).select_people()
Пример #18
0
def dashboard_controls_tab(selenium):
    """Open My Work Dashboard Controls Tab URL and
  return Controls Tab page objects model."""
    selenium_utils.open_url(url.Urls().dashboard_controls_tab)
    return controls_tab.ControlsTab()
Пример #19
0
def my_work_dashboard(selenium):
    """Open My Work Dashboard URL and
  return My Work Dashboard page objects model."""
    selenium_utils.open_url(url.Urls().dashboard)
    return dashboard.Dashboard(selenium)
Пример #20
0
def header_dashboard(selenium):
    """Open My Work Dashboard URL and
  return Header Dashboard page objects model."""
    selenium_utils.open_url(url.Urls().dashboard)
    return dashboard.Header(selenium)
Пример #21
0
 def test_login_as_admin(self, selenium):
   """Logs in and verifies that we're logged in as admin."""
   selenium_utils.open_url(selenium, url.Urls().login)
   selenium.find_element(*locator.PageHeader.BUTTON_ADMIN_DASHBOARD)
Пример #22
0
def lhn_menu(selenium):
    """Open LHN menu and return LHN page objects model."""
    selenium_utils.open_url(url.Urls().dashboard)
    return dashboard.Dashboard(selenium).open_lhn_menu()
Пример #23
0
def _set_login_cookie(session, user):
    """Sets dev_appserver_login and session cookies."""
    session.get(url_module.Urls().gae_login(user))
    session.get(url_module.Urls().login)
 def admin_dashboard(self, selenium):
   """Open Admin Dashboard URL and
   return AdminDashboard page objects model."""
   selenium_utils.open_url(selenium, url.Urls().admin_dashboard)
   return dashboard.AdminDashboard(selenium)
Пример #25
0
 def login(self):
     """Set dev_appserver_login and session cookies."""
     self.session.get(url_module.Urls().gae_login(users.current_user()))
     self.session.get(url_module.Urls().login)