def test_user_list_link_superuser(self): """A logged-in superuser should see the "Users" link in the navbar. """ LoginPage(self).login(self.superuser['username'], self.superuser['password']) DashboardPage(self).go_to() assert DashboardPage(self).has_nav_link('Users')
def test_user_list_link_nonloggedin_user(self): """A non-logged-in superuser should NOT see the "Users" link in the navbar. """ DashboardPage(self).go_to() self.get_screenshot('dash') ulink = DashboardPage(self).has_nav_link('Users') print(ulink) plink = DashboardPage(self).has_nav_link('Projects') print(plink) assert not DashboardPage(self).has_nav_link('Users')
def check_project_pages(self, user_type, parent_org_idxs): orgs = self.test_data['orgs'] projects = self.test_data['projects'] # Note which projects are visible to the target user # and append org attributes as well for each project for project in projects: org_idx = project['_org'] org = orgs[org_idx] project_copy = project.copy() project_copy['_org_slug'] = org['slug'] project_copy['_org_name'] = org['name'] project_copy['_org_logo'] = (org['logo'] if 'logo' in org else '') is_visible = (True if ( user_type == 'superuser' or project['access'] == 'public' or (user_type == 'affiliated' and org_idx in parent_org_idxs)) else False) project_page = ProjectPage(self, org['slug'], project['slug']) project_page.go_to() if is_visible: assert project_page.is_on_page() project_page.check_page_contents(project_copy) else: assert DashboardPage(self).is_on_page() self.assert_has_message('alert', "have permission")
def test_nonsuperuser(self): """A logged-in non-superuser cannot access the users page.""" LoginPage(self).login(self.user1['username'], self.user1['password']) self.browser.get(UsersPage(self).url) self.assert_has_message('alert', "have permission") assert DashboardPage(self).is_on_page()
def setUp(self): #Initialize webdriver self.driver = webdriver.Chrome( "C:\Shehroz\Softwares\Dev Tools\chromedriver_win32\chromedriver.exe" ) self.register = RegisterPage(self.driver) self.dashboard = DashboardPage(self.driver)
def test_register_user(self): """An unregistered user can register with valid user details.""" page = RegistrationPage(self) page.go_to() fields = page.get_fields() # Try to submit an empty form and check for validation errors. page.try_submit(err=['username', 'email', 'password1', 'password2']) # Fill in required fields one by one, try to submit and check # for errors. fields = page.get_fields() fields['username'].send_keys('user3') page.try_submit( err=['email', 'password1', 'password2'], ok=['username'], ) fields = page.get_fields() fields['email'].send_keys('*****@*****.**') page.try_submit( err=['password1', 'password2'], ok=['username', 'email'], ) fields = page.get_fields() fields['password1'].send_keys('very_secret') page.try_submit( err=['password2'], ok=['username', 'email', 'password1'], ) fields = page.get_fields() fields['password2'].send_keys('not_very_secret') page.try_submit(err=['password2'], ok=['username', 'email', 'password1'], message='This value should be the same.') # Fill in extra fields, fill in final required form and submit fields = page.get_fields() fields['full_name'].send_keys('User Three') fields['password1'].clear() fields['password1'].send_keys('very_secret') fields['password2'].clear() fields['password2'].send_keys('very_secret') self.click_through(fields['register'], self.BY_DASHBOARD) self.assert_has_message('alert', "signed in") dashboard_page = DashboardPage(self) assert dashboard_page.is_on_page() dashboard_page.get_dashboard_map() self.logout() # Log in as new user sign_in = LoginPage(self).setup('user3', 'very_secret') self.click_through(sign_in, self.BY_ALERT) assert dashboard_page.is_on_page() dashboard_page.get_dashboard_map()
def test_valid_login(self): """A registered user can log in with their username and password and log out again. The logged in and logged out states are persistent across page refreshes.""" sign_in_button = LoginPage(self).setup( self.test_data['users'][0]['username'], self.test_data['users'][0]['password'], ) self.click_through(sign_in_button, self.BY_DASHBOARD) dashboard_page = DashboardPage(self) assert dashboard_page.is_on_page() dashboard_page.get_dashboard_map() self.browser.refresh() self.wait_for_no_alerts() dashboard_page.get_dashboard_map() self.logout() self.browser.refresh() self.wait_for_no_alerts() assert LoginPage(self).is_on_page()
def generic_test_orgadmin(self, access): assert access in ('public', 'private') # Log in as org admin LoginPage(self).login(self.orgadmin['username'], self.orgadmin['password']) # Declare working project data for verification project = {} proj_add_page = ProjectAddPage(self) proj_add_page.go_to() assert proj_add_page.is_on_page() assert proj_add_page.is_on_subpage('geometry') # Select country and submit geometry project['country'] = 'AU' if access == 'public' else 'BR' proj_add_page.set_geometry(project['country']) proj_add_page.submit_geometry() # Check that details are all blank/default project['org'] = '' project['name'] = "" project['access'] = 'public' project['description'] = "" project['url'] = '' proj_add_page.check_details(project) # TODO: Check that only valid orgs are provided # TODO: Vary org selection # Check that errors occurs when no org was selected # and no project name was set # Also toggle access and set description project['access'] = 'private' project['description'] = self.test_data['project_description'] proj_add_page.set_access(project['access']) proj_add_page.set_description(project['description']) proj_add_page.try_submit_details() proj_add_page.check_missing_org_error() proj_add_page.check_missing_name_error() proj_add_page.check_no_duplicate_name_error() proj_add_page.check_no_invalid_url_error() proj_add_page.check_details(project) # Select the first valid org # Check that an error occurs when the project name is only whitespace # Also toggle access and set URL project['org'] = 'unesco' project['name'] = " " project['access'] = 'public' project['url'] = self.test_data['project_url'] proj_add_page.set_org(project['org']) proj_add_page.set_name(project['name']) proj_add_page.set_access(project['access']) proj_add_page.set_proj_url(project['url']) proj_add_page.try_submit_details() proj_add_page.check_no_missing_org_error() proj_add_page.check_missing_name_error() proj_add_page.check_no_duplicate_name_error() proj_add_page.check_no_invalid_url_error() proj_add_page.check_details(project) # Unset the org, and set a valid project name # Check that an error occurs for the missing org project['org'] = '' project['name'] = self.test_data['project_name'] proj_add_page.set_org(project['org']) proj_add_page.set_name(project['name']) proj_add_page.try_submit_details() proj_add_page.check_missing_org_error() proj_add_page.check_no_missing_name_error() proj_add_page.check_no_duplicate_name_error() proj_add_page.check_no_invalid_url_error() proj_add_page.check_details(project) # Set final org, final access, and invalid URL # Check that the page is not submitted due to the invalid URL project['org'] = 'unesco' project['access'] = access project['url'] = "DEADBEEF" proj_add_page.set_org(project['org']) proj_add_page.set_name(project['name']) proj_add_page.set_access(project['access']) proj_add_page.set_proj_url(project['url']) proj_add_page.try_submit_details() proj_add_page.check_no_missing_org_error() proj_add_page.check_no_missing_name_error() proj_add_page.check_no_duplicate_name_error() proj_add_page.check_invalid_url_error() proj_add_page.check_details(project) # Correct the URL, press "Previous" then "Next" and ensure # that details settings are preserved. project['url'] = self.test_data['project_url'] proj_add_page.set_proj_url(project['url']) proj_add_page.click_previous_details() proj_add_page.submit_geometry() proj_add_page.check_details(project) # Finally submit details proj_add_page.submit_details() # Set permissions # TODO: Vary permissions and check permissions after proj_add_page.submit_permissions() # Set project slug and org details project['slug'] = self.test_data['project_slug'] orgs = self.test_data['orgs'] project['_org_slug'] = orgs[0]['slug'] project['_org_name'] = orgs[0]['name'] project['_org_logo'] = (orgs[0]['logo'] if 'logo' in orgs[0] else '') # Check that we are now in the project page # and that displayed project details are correct proj_page = ProjectPage(self, project['_org_slug'], project['slug']) assert proj_page.is_on_page() proj_page.check_page_contents(project) # Go to project list and check that details are correct proj_list_page = ProjectListPage(self) proj_list_page.go_to_and_check_on_page() proj_list_page.check_project_list([project]) self.logout() # Check new project as an org member LoginPage(self).login(self.orgmember['username'], self.orgmember['password']) proj_page.go_to() assert proj_page.is_on_page() proj_page.check_page_contents(project) proj_list_page = ProjectListPage(self) proj_list_page.go_to_and_check_on_page() proj_list_page.check_project_list([project]) self.logout() # Check new project as an unaffiliated user LoginPage(self).login(self.unaffuser['username'], self.unaffuser['password']) proj_page.go_to() if access == 'public': assert proj_page.is_on_page() proj_page.check_page_contents(project) else: assert DashboardPage(self).is_on_page() self.assert_has_message('alert', "have permission") proj_list_page = ProjectListPage(self) proj_list_page.go_to_and_check_on_page() if access == 'public': proj_list_page.check_project_list([project]) else: assert proj_list_page.is_list_empty() self.logout()