def check_project_list(self, user_type, parent_org_idxs): orgs = self.test_data["orgs"] projects = self.test_data["projects"] # Go to the project list page page = ProjectListPage(self) page.go_to_and_check_on_page() # Collect projects that are visible to the target user visible_projects = [] for project in projects: if project["archived"] is False: if ( user_type == "superuser" or project["access"] == "public" or (user_type == "affiliated" and project["_org"] in parent_org_idxs) ): project_copy = project.copy() org = orgs[project["_org"]] project_copy["_org_slug"] = org["slug"] project_copy["_org_name"] = org["name"] project_copy["_org_logo"] = org["logo"] if "logo" in org else "" visible_projects.append(project_copy) # Check that visible projects are present with correct details page.check_project_list(visible_projects)
def test_nonsuperuser(self): """Verify that a non-superuser can access the project list page.""" uid = 5 LoginPage(self).login(self.test_data['users'][uid]['username'], self.test_data['users'][uid]['password']) ProjectListPage(self).go_to_and_check_on_page()
def check_project_list(self, user_type, parent_org_idxs): orgs = self.test_data['orgs'] projects = self.test_data['projects'] # Go to the project list page page = ProjectListPage(self) page.go_to_and_check_on_page() # Collect projects that are visible to the target user visible_projects = [] for project in projects: if (user_type == 'superuser' or project['access'] == 'public' or (user_type == 'affiliated' and project['_org'] in parent_org_idxs)): project_copy = project.copy() org = orgs[project['_org']] project_copy['_org_slug'] = org['slug'] project_copy['_org_name'] = org['name'] project_copy['_org_logo'] = (org['logo'] if 'logo' in org else '') visible_projects.append(project_copy) # Check that visible projects are present with correct details page.check_project_list(visible_projects)
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()
def test_superuser(self): """Verify that a superuser can access the project list page.""" LoginPage(self).login(self.superuser['username'], self.superuser['password']) ProjectListPage(self).go_to_and_check_on_page()
def test_nonloggedin_user(self): """Verify that a non-logged-in user can access the project list page.""" ProjectListPage(self).go_to_and_check_on_page()
def test_archived_projects_appear_in_long_lists(self): """If the project list spans two pages, and an archived project appears on the second page, the archive filter option should still appear""" ProjectFactory.create_batch(10) LoginPage(self).login('default5', 'password1') page = ProjectListPage(self) page.go_to_and_check_on_page() project_title = page.get_project_title_in_table() assert project_title == 'Linux Kernel' project_title = page.sort_table_by("descending") assert project_title == 'Project Gutenberg' page.sort_table_by("ascending") page.click_archive_filter("Archived") project_title = page.get_project_title_in_table() assert project_title == 'Zealous Archived Project Archived' project_title = page.sort_table_by("descending") assert project_title == 'Zealous Archived Project Archived' page.sort_table_by("ascending") page.click_archive_filter("All") project_title = page.get_project_title_in_table() assert project_title == 'Linux Kernel' project_title = page.sort_table_by("descending") assert project_title == 'Zealous Archived Project Archived' page.sort_table_by("ascending") page.click_archive_filter("Archived") page.click_archive_filter("Active") project_title = page.get_project_title_in_table() assert project_title == 'Linux Kernel'
def test_archived_projects_appear_for_admin_user(self): """The option to filter active/archived projects is available to organization administrators.""" LoginPage(self).login('default5', 'password1') page = ProjectListPage(self) page.go_to_and_check_on_page() project_title = page.get_project_title_in_table() assert project_title == 'Linux Kernel' project_title = page.sort_table_by("descending") assert project_title == 'Project Gutenberg' page.sort_table_by("ascending") page.click_archive_filter("Archived") project_title = page.get_project_title_in_table() assert project_title == 'Zealous Archived Project Archived' project_title = page.sort_table_by("descending") assert project_title == 'Zealous Archived Project Archived' page.sort_table_by("ascending") page.click_archive_filter("All") project_title = page.get_project_title_in_table() assert project_title == 'Linux Kernel' project_title = page.sort_table_by("descending") assert project_title == 'Zealous Archived Project Archived' page.sort_table_by("ascending") page.click_archive_filter("Archived") page.click_archive_filter("Active") project_title = page.get_project_title_in_table() assert project_title == 'Linux Kernel'
def generic_test_add_duplicate_project(self, from_same_org=True): org = self.test_data['orgs'][0] project = { 'description': "", 'country': '', 'access': 'public', '_org_slug': org['slug'], '_org_name': org['name'], '_org_logo': org['logo'] if 'logo' in org else '', } duplicated_proj_idx = 0 if from_same_org else 1 duplicated_proj = self.test_data['projects'][duplicated_proj_idx] project['name'] = duplicated_proj['name'] project['slug'] = duplicated_proj['slug'] + '-1' # Log in as org admin LoginPage(self).login(self.orgadmin['username'], self.orgadmin['password']) # Go to the add project wizard and # proceed to step 2 and input the project name proj_add_page = ProjectAddPage(self) proj_add_page.go_to() proj_add_page.submit_geometry() proj_add_page.set_name(project['name']) if from_same_org: # If project name is duplicate from the same org, expect that # submitting step 2 will result in an error proj_add_page.try_submit_details() proj_add_page.check_duplicate_name_error() # Make the name unique project['name'] = project['name'] + " 1" proj_add_page.set_name(project['name']) # successfully complete the add project wizard proj_add_page.submit_details() proj_add_page.submit_permissions() # Check that we are now in the new project page # and that the 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) # Construct final list of projects that should be in the DB expected_projs = [] for proj in self.test_data['projects']: proj_copy = proj.copy() proj_org = self.test_data['orgs'][proj['_org']] proj_copy['_org_slug'] = proj_org['slug'] proj_copy['_org_name'] = proj_org['name'] proj_copy['_org_logo'] = ( proj_org['logo'] if 'logo' in proj_org else '') expected_projs.append(proj_copy) expected_projs.append(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(expected_projs) self.logout()
def test_archived_projects_appear_in_long_lists(self): """If the project list spans two pages, and an archived project appears on the second page, the archive filter option should still appear""" ProjectFactory.create_batch(10) LoginPage(self).login("default5", "password1") page = ProjectListPage(self) page.go_to_and_check_on_page() project_title = page.get_project_title_in_table() assert project_title == "Linux Kernel" project_title = page.sort_table_by("descending") assert project_title == "Project Gutenberg" page.sort_table_by("ascending") page.click_archive_filter("Archived") project_title = page.get_project_title_in_table() assert project_title == "Zealous Archived Project Archived" project_title = page.sort_table_by("descending") assert project_title == "Zealous Archived Project Archived" page.sort_table_by("ascending") page.click_archive_filter("All") project_title = page.get_project_title_in_table() assert project_title == "Linux Kernel" project_title = page.sort_table_by("descending") assert project_title == "Zealous Archived Project Archived" page.sort_table_by("ascending") page.click_archive_filter("Archived") page.click_archive_filter("Active") project_title = page.get_project_title_in_table() assert project_title == "Linux Kernel"
def test_archived_projects_appear_for_admin_user(self): """The option to filter active/archived projects is available to organization administrators.""" LoginPage(self).login("default5", "password1") page = ProjectListPage(self) page.go_to_and_check_on_page() project_title = page.get_project_title_in_table() assert project_title == "Linux Kernel" project_title = page.sort_table_by("descending") assert project_title == "Project Gutenberg" page.sort_table_by("ascending") page.click_archive_filter("Archived") project_title = page.get_project_title_in_table() assert project_title == "Zealous Archived Project Archived" project_title = page.sort_table_by("descending") assert project_title == "Zealous Archived Project Archived" page.sort_table_by("ascending") page.click_archive_filter("All") project_title = page.get_project_title_in_table() assert project_title == "Linux Kernel" project_title = page.sort_table_by("descending") assert project_title == "Zealous Archived Project Archived" page.sort_table_by("ascending") page.click_archive_filter("Archived") page.click_archive_filter("Active") project_title = page.get_project_title_in_table() assert project_title == "Linux Kernel"
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()