コード例 #1
0
    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")
コード例 #2
0
    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 and project['archived'] is False:
                assert project_page.is_on_page()
                project_page.check_page_contents(project_copy)
            elif project['archived'] is False:
                assert DashboardPage(self).is_on_page()
                self.assert_has_message('alert', "have permission")
コード例 #3
0
    def test_resource_attach_button_for_non_project_user(self):
        """Attach button will be hidden from users who doesn't have
            permission to add resource."""

        LoginPage(self).login('testuser', 'password')
        page = ProjectPage(self, self.org.slug, self.prj.slug)
        page.go_to()

        # Test resource tab
        page.click_on_resources_tab()
        try:
            page.click_on_add_button('panel-body', success=False)
        except NoSuchElementException:
            assert True
コード例 #4
0
    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()
コード例 #5
0
    def test_project_archived_view(self):
        LoginPage(self).login('admin_user', 'password')
        page = ProjectPage(self, self.org.slug, self.prj.slug)
        page.go_to()
        self.get_screenshot('project page')
        assert 'ARCHIVED' in page.get_project_name()

        # Test main dashboard page
        page.click_on_add_location_button(success=False)
        page.click_on_add_resource_button_from_dropdown(success=False)
        page.click_on_edit_boundary_button('geometry', success=False)
        page.click_on_edit_boundary_button('details', success=False)
        page.click_on_edit_boundary_button('permissions', success=False)

        # Test spatial unit
        page.click_on_location()
        page.click_on_edit_button(success=False)
        page.click_on_delete_button(success=False)

        # Test spatial unit resource tab
        page.click_on_location_resource_tab()
        page.click_on_add_button('active', success=False)
        page.click_on_location_resource_tab()
        page.click_on_detach_resource_button('detail', success=False)

        # Test spatial unit relationship tab
        page.click_on_location_relationship_tab()
        page.click_on_add_button('active', success=False)
        page.click_on_location_relationship_tab()

        # Test spatial unit relationship tab
        page.click_on_relationship_in_table()
        page.click_on_edit_button(success=False)
        page.click_on_delete_button(success=False)
        page.click_on_add_button('detail', success=False)
        page.click_on_detach_resource_button('detail', success=False)

        # Test party page
        page.click_on_party_in_table()
        page.click_on_edit_button(success=False)
        page.click_on_delete_button(success=False)
        page.click_on_add_button('panel-body', success=False)
        page.click_on_detach_resource_button('panel-body', success=False)

        # Test project resource page
        page.click_on_resources_tab()
        page.click_on_add_button('panel-body', success=False)
        page.click_on_detach_resource_button('panel-body', success=False)

        page.click_on_resource_in_table()
        page.click_on_edit_resource_button(success=False)
        page.click_on_delete_resource_button_and_confirm(success=False)
コード例 #6
0
    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()
コード例 #7
0
    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()