Пример #1
0
    def test_edit_user_logged_in_username_change_by_id(self):
        user_pass = "******"
        user = factories.User(password=user_pass)
        app = self._get_test_app()

        # Have to do an actual login as this test relys on repoze cookie handling.
        # get the form
        response = app.get("/user/login")
        # ...it's the second one
        login_form = response.forms[1]
        # fill it in
        login_form["login"] = user["name"]
        login_form["password"] = user_pass
        # submit it
        login_form.submit()

        # Now the cookie is set, run the test
        response = app.get(url=url_for(controller="user", action="edit", id=user["id"]))
        # existing values in the form
        form = response.forms["user-edit-form"]

        # new values
        form["name"] = "new-name"
        response = submit_and_follow(app, form, name="save")
        response = helpers.webtest_maybe_follow(response)

        expected_url = url_for(controller="user", action="read", id="new-name")
        assert response.request.path == expected_url
Пример #2
0
    def test_registered_user_login_bad_password(self):
        '''
        Registered user is redirected to appropriate place if they submit
        invalid login details at /user/login.
        '''
        app = helpers._get_test_app()

        # make a user
        user = factories.User()

        # get the form
        response = app.get('/user/login')
        # ...it's the second one
        login_form = response.forms[1]

        # fill it in
        login_form['login'] = user['name']
        login_form['password'] = '******'

        # submit it
        submit_response = login_form.submit()
        # let's go to the last redirect in the chain
        final_response = helpers.webtest_maybe_follow(submit_response)

        # the response is the login page again
        final_response.mustcontain('<h1 class="page-heading">Login</h1>',
                                   'Login failed. Bad username or password.')
        # and we're definitely not on the dashboard.
        final_response.mustcontain(no='<a href="/dashboard">Dashboard</a>'),
        final_response.mustcontain(no='<span class="username">{0}</span>'
                                   .format(user['fullname']))
Пример #3
0
    def test_edit_user_logged_in_username_change_by_id(self):
        user_pass = '******'
        user = factories.User(password=user_pass)
        app = self._get_test_app()

        # Have to do an actual login as this test relys on repoze cookie handling.
        # get the form
        response = app.get('/user/login')
        # ...it's the second one
        login_form = response.forms[1]
        # fill it in
        login_form['login'] = user['name']
        login_form['password'] = user_pass
        # submit it
        login_form.submit()

        # Now the cookie is set, run the test
        response = app.get(
            url=url_for(controller='user', action='edit', id=user['id']),
        )
        # existing values in the form
        form = response.forms['user-edit-form']

        # new values
        form['name'] = 'new-name'
        response = submit_and_follow(app, form, name='save')
        response = helpers.webtest_maybe_follow(response)

        expected_url = url_for(controller='user', action='read', id='new-name')
        assert response.request.path == expected_url
Пример #4
0
    def test_registered_user_login_bad_password(self, app):
        """
    Registered user is redirected to appropriate place if they submit
    invalid login details at /user/login.
    """

        # make a user
        user = factories.User()

        # get the form
        response = app.get("/user/login")
        # ...it's the second one
        login_form = response.forms[1]

        # fill it in
        login_form["login"] = user["name"]
        login_form["password"] = "******"

        # submit it
        submit_response = login_form.submit()
        # let's go to the last redirect in the chain
        final_response = helpers.webtest_maybe_follow(submit_response)

        # the response is the login page again
        final_response.mustcontain(
            '<h1 class="page-heading">Login</h1>',
            "Login failed. Bad username or password.",
        )
        # and we're definitely not on the dashboard.
        final_response.mustcontain(no='<a href="/dashboard">Dashboard</a>'),
        final_response.mustcontain(
            no='<span class="username">{0}</span>'.format(user["fullname"]))
Пример #5
0
    def test_confirm_cancel_delete(self):
        '''Test confirmation of deleting datasets

        When package_delete is made as a get request, it should return a
        'do you want to delete this dataset? confirmation page'''
        user = factories.User()
        owner_org = factories.Organization(
            users=[{'name': user['id'], 'capacity': 'admin'}]
        )
        dataset = factories.Dataset(owner_org=owner_org['id'])

        app = helpers._get_test_app()
        env = {'REMOTE_USER': user['name'].encode('ascii')}
        response = app.get(
            url_for(controller='package', action='delete', id=dataset['name']),
            extra_environ=env,
        )
        assert_equal(200, response.status_int)
        message = 'Are you sure you want to delete dataset - {name}?'
        response.mustcontain(message.format(name=dataset['title']))

        form = response.forms['confirm-dataset-delete-form']
        response = form.submit('cancel')
        response = helpers.webtest_maybe_follow(response)
        assert_equal(200, response.status_int)
Пример #6
0
    def test_confirm_cancel_delete(self):
        '''Test confirmation of deleting datasets

        When package_delete is made as a get request, it should return a
        'do you want to delete this dataset? confirmation page'''
        user = factories.User()
        owner_org = factories.Organization(users=[{
            'name': user['id'],
            'capacity': 'admin'
        }])
        dataset = factories.Dataset(owner_org=owner_org['id'])

        app = helpers._get_test_app()
        env = {'REMOTE_USER': user['name'].encode('ascii')}
        response = app.get(
            url_for(controller='package', action='delete', id=dataset['name']),
            extra_environ=env,
        )
        assert_equal(200, response.status_int)
        message = 'Are you sure you want to delete dataset - {name}?'
        response.mustcontain(message.format(name=dataset['name']))

        form = response.forms['confirm-dataset-delete-form']
        response = form.submit('cancel')
        response = helpers.webtest_maybe_follow(response)
        assert_equal(200, response.status_int)
Пример #7
0
    def test_registered_user_login(self):
        '''
        Registered user can submit valid login details at /user/login and
        be returned to appropriate place.
        '''
        app = helpers._get_test_app()

        # make a user
        user = factories.User()

        # get the form
        response = app.get('/user/login')
        # ...it's the second one
        login_form = response.forms[1]

        # fill it in
        login_form['login'] = user['name']
        login_form['password'] = '******'

        # submit it
        submit_response = login_form.submit()
        # let's go to the last redirect in the chain
        final_response = helpers.webtest_maybe_follow(submit_response)

        # the response is the user dashboard, right?
        final_response.mustcontain('<a href="/dashboard/">Dashboard</a>',
                                   '<span class="username">{0}</span>'
                                   .format(user['fullname']))
        # and we're definitely not back on the login page.
        final_response.mustcontain(no='<h1 class="page-heading">Login</h1>')
Пример #8
0
    def test_registered_user_login(self):
        '''
        Registered user can submit valid login details at /user/login and
        be returned to appropriate place.
        '''
        app = helpers._get_test_app()

        # make a user
        user = factories.User()

        # get the form
        response = app.get('/user/login')
        # ...it's the second one
        login_form = response.forms[1]

        # fill it in
        login_form['login'] = user['name']
        login_form['password'] = '******'

        # submit it
        submit_response = login_form.submit()
        # let's go to the last redirect in the chain
        final_response = helpers.webtest_maybe_follow(submit_response)

        # the response is the user dashboard, right?
        final_response.mustcontain(
            '<a href="/dashboard/">Dashboard</a>',
            '<span class="username">{0}</span>'.format(user['fullname']))
        # and we're definitely not back on the login page.
        final_response.mustcontain(no='<h1 class="page-heading">Login</h1>')
    def test_location_mapper_tab_contains_new_resource_url(self):
        app = helpers.FunctionalTestBase._get_test_app()
        user, resource, context = self._create_context()

        output_buffer = self._create_correctly_formatted_csv()

        extras = {
            "location_column" : "Local Authority District",
            "location_type" : "local_authority_district_name" 
        }

        resource, package = self._create_csv_resource(output_buffer, extras)
       

        response = helpers.webtest_maybe_follow(app.get("/dataset/" + package['id'] + "/resource/" + resource['id']+ "/map_location",
            extra_environ={'REMOTE_USER': str(user['name'])}))

        # refresh the package
        package = helpers.call_action('package_show', id=package['id'])

        # get the resource list for the package, sort them in descending order so the most recently created on is first

        resources = sorted(package['resources'], key=operator.itemgetter('created'), reverse=True)

        new_resource = resources[0]

        response.mustcontain("Added new resource to dataset " \
                                + config.get('ckan.site_url')  \
                                + h.url_for(controller='package', 
                                            action='resource_read', 
                                            id=new_resource['package_id'], 
                                            resource_id=new_resource['id']))
    def test_map_location_with_correctly_formatted_file_uploads_expected_resources_to_dataset(self):
        app = helpers.FunctionalTestBase._get_test_app()
        user, resource, context = self._create_context()

        output_buffer = self._create_correctly_formatted_csv()

        extras = {
            "location_column" : "Local Authority District",
            "location_type" : "local_authority_district_name" 
        }

        resource, package = self._create_csv_resource(output_buffer, extras)
       

        helpers.webtest_maybe_follow(app.get("/dataset/" + package['id'] + "/resource/" + resource['id']+ "/map_location",
            extra_environ={'REMOTE_USER': str(user['name'])}))

        package = helpers.call_action('package_show', id=resource['package_id'])
        
        assert_true((len(package['resources'])), 2)
Пример #11
0
    def test_user_logout_url_redirect(self, app):
        """_logout url redirects to logged out page.

    Note: this doesn't test the actual logout of a logged in user, just
    the associated redirect.
    """

        logout_url = url_for("user.logout")
        logout_response = app.get(logout_url, status=302)
        final_response = helpers.webtest_maybe_follow(logout_response)

        assert "You are now logged out." in final_response
    def test_map_location_with_missing_resource_information(self):
        app = helpers.FunctionalTestBase._get_test_app()
        user, resource, context = self._create_context()

        output_buffer = self._create_correctly_formatted_csv()

        resource, package = self._create_csv_resource(output_buffer)

        response = helpers.webtest_maybe_follow(app.get("/dataset/" + package['id'] + "/resource/" + resource['id']+ "/map_location",
            extra_environ={'REMOTE_USER': str(user['name'])})) 

        response.mustcontain("Location column not specified for resource")
Пример #13
0
    def test_user_logout_url_redirect(self):
        '''_logout url redirects to logged out page.

        Note: this doesn't test the actual logout of a logged in user, just
        the associated redirect.
        '''
        app = self._get_test_app()

        logout_url = url_for(controller='user', action='logout')
        logout_response = app.get(logout_url, status=302)
        final_response = helpers.webtest_maybe_follow(logout_response)

        assert_true('You are now logged out.' in final_response)
Пример #14
0
    def test_non_root_user_logout_url_redirect(self):
        '''_logout url redirects to logged out page.

        Note: this doesn't test the actual logout of a logged in user, just
        the associated redirect.
        '''
        app = self._get_test_app()

        logout_url = url_for(controller='user', action='logout')
        logout_response = app.get(logout_url, status=302)
        try:
            final_response = helpers.webtest_maybe_follow(logout_response)
        except Exception as e:
            assert_true('/my/prefix/user/logout' in e.message)
Пример #15
0
    def test_non_root_user_logout_url_redirect(self):
        '''_logout url redirects to logged out page.

        Note: this doesn't test the actual logout of a logged in user, just
        the associated redirect.
        '''
        app = self._get_test_app()

        logout_url = url_for(controller='user', action='logout')
        logout_response = app.get(logout_url, status=302)
        try:
            final_response = helpers.webtest_maybe_follow(logout_response)
        except Exception as e:
            assert_true('/my/prefix/user/logout' in e.message)
    def test_map_location_with_sample_file(self):
        app = helpers.FunctionalTestBase._get_test_app()
        user, resource, context = self._create_context()

        output_buffer = self._load_correctly_formatted_csv()

        extras = {
            "location_column" : "Local authority",
            "location_type" : "local_authority_district_name" 
        }

        resource, package = self._create_csv_resource(output_buffer, extras)
       

        response = helpers.webtest_maybe_follow(app.get("/dataset/" + package['id'] + "/resource/" + resource['id']+ "/map_location",
            extra_environ={'REMOTE_USER': str(user['name'])}))

        response.mustcontain('Complete')
Пример #17
0
    def test_confirm_cancel_delete(self):
        """Test confirmation of deleting datasets

        When package_delete is made as a get request, it should return a
        'do you want to delete this dataset? confirmation page"""
        user = factories.User()
        owner_org = factories.Organization(users=[{"name": user["id"], "capacity": "admin"}])
        dataset = factories.Dataset(owner_org=owner_org["id"])

        app = helpers._get_test_app()
        env = {"REMOTE_USER": user["name"].encode("ascii")}
        response = app.get(url_for(controller="package", action="delete", id=dataset["name"]), extra_environ=env)
        assert_equal(200, response.status_int)
        message = "Are you sure you want to delete dataset - {name}?"
        response.mustcontain(message.format(name=dataset["name"]))

        form = response.forms["confirm-dataset-delete-form"]
        response = form.submit("cancel")
        response = helpers.webtest_maybe_follow(response)
        assert_equal(200, response.status_int)