Exemplo n.º 1
0
    def test_basic_query(self):
        schema = default_create_package_schema()
        context = {'model':model,'session':Session,'user':'******','extras_as_string':True,'schema':schema,'api_version':2}
        package_dict = package_create(context,self.package_fixture_data)
        package_id = context.get('id')

        # Point inside bbox
        offset = self._offset_with_bbox()

        res = self.app.get(offset, status=200)
        res_dict = self.data_from_res(res)

        assert res_dict['count'] == 1
        assert res_dict['results'][0] == package_id

        # Point outside bbox
        offset = self._offset_with_bbox(-10,10,-20,20)

        res = self.app.get(offset, status=200)
        res_dict = self.data_from_res(res)

        assert res_dict['count'] == 0
        assert res_dict['results'] == []

        # Delete the package and ensure it does not come up on
        # search results
        package_delete(context,{'id':package_id})
        offset = self._offset_with_bbox()

        res = self.app.get(offset, status=200)
        res_dict = self.data_from_res(res)

        assert res_dict['count'] == 0
        assert res_dict['results'] == []
 def teardown(self):
     """Clean up after each test"""
     datastore_delete(TestMapActions.context, {'resource_id': self.resource['resource_id']})
     package_delete(TestMapActions.context, {'id': self.dataset['id']})
     tm_config.update({
         'tiledmap.geom_field': '_the_geom_webmercator',
         'tiledmap.geom_field_4326': '_geom'
     })
Exemplo n.º 3
0
def package_delete(context, data_dict):
    model = context['model']
    delete.package_delete(context, data_dict)
    package = Package.get(data_dict['id'])
    package.purge()
    model.repo.commit_and_remove()
    send_dataset_log(context, data_dict, 'Dataset removed',
                     'DatasetRemoved')
    delete_de(data_dict)
    return None
Exemplo n.º 4
0
    def test_basic_query(self):
        schema = default_create_package_schema()
        context = {
            'model': model,
            'session': Session,
            'user': '******',
            'extras_as_string': True,
            'schema': schema,
            'api_version': 2
        }
        package_dict = package_create(context, self.package_fixture_data)
        package_id = context.get('id')

        # Point inside bbox
        offset = self._offset_with_bbox()

        res = self.app.get(offset, status=200)
        res_dict = self.data_from_res(res)

        assert res_dict['count'] == 1
        assert res_dict['results'][0] == package_id

        # Point outside bbox
        offset = self._offset_with_bbox(-10, 10, -20, 20)

        res = self.app.get(offset, status=200)
        res_dict = self.data_from_res(res)

        assert res_dict['count'] == 0
        assert res_dict['results'] == []

        # Delete the package and ensure it does not come up on
        # search results
        package_delete(context, {'id': package_id})
        offset = self._offset_with_bbox()

        res = self.app.get(offset, status=200)
        res_dict = self.data_from_res(res)

        assert res_dict['count'] == 0
        assert res_dict['results'] == []
Exemplo n.º 5
0
def dataset_delete(context, data_dict=None):
    ret_val = package_delete(context, data_dict)
    
    # has to have name too, because of queue filtering
    dataset = get_action('package_show')(context, data_dict)
    log.debug("package_delete sync dataset: {0}".format(dataset['name']))
    if dataset['state'] == 'deleted':
        queue.put(dataset)
    else:
        log.error("package '{0}' wasn't deleted, cancelling synchronization".format(dataset['name']))
    
    return ret_val
Exemplo n.º 6
0
    def test_user_activity(self):
        """Test user activity streams HTML rendering."""

        # Register a new user.
        user_dict = {'name': 'billybeane',
                'fullname': 'Billy Beane',
                'about': 'General Manager, Oakland Athletics',
                'email': '*****@*****.**',
                'password': '******'}
        context = {
            'model': ckan.model,
            'session': ckan.model.Session,
            'user': self.sysadmin_user.name,
            'allow_partial_update': True,
            }
        user = user_create(context, user_dict)
        offset = url_for('user.activity', id=user['id'])
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s signed up' % user['fullname'] in stripped, stripped

        # Create a new package.
        package = {
            'name' : 'baseball_stats',
            'title' : "Billy's Stats about Baseball Players",
        }
        context['user'] = user['name']
        # FIXME This test use an old way to get at the schema to
        # recreate this we need to pretend to be using the api. We
        # should not be calling package_create like this we should be
        # going via the api or package controllers
        context['api_version'] = 3
        context['ignore_auth'] = True
        package = package_create(context, package)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s created the dataset %s ' % (
                user['fullname'], package['title']) in stripped, stripped

        # Add a resource to the package.
        resource = {
            'url': 'http://www.example.com',
            'description': "Chad Bradford's OBP Stats`",
            'format': 'cvs',
            'name': 'Chad Bradford Stats',
            }
        package['resources'].append(resource)
        request_data = {
                'id': package['id'],
                'resources': package['resources'],
                }
        package = package_update(context, request_data)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s added the resource %s to the dataset %s' % \
                (user['fullname'], resource['name'], package['title']) \
                in stripped, stripped

        # Update the package.
        package['title'] =  "Billy's Updated Stats about Baseball Players"
        package = package_update(context, package)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s updated the dataset %s' \
                % (user['fullname'], package['title']) \
                in stripped, stripped

        # Update the resource.
        resource = package['resources'][0]
        resource['name'] = 'Chad Bradford Updated Stats'
        resource = resource_update(context, resource)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s updated the resource %s in the dataset %s' \
                % (user['fullname'], resource['name'], package['title']) \
                in stripped, stripped

        # Delete the resource.
        context['allow_partial_update'] = False
        package['resources'] = []
        package_update(context, package)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s deleted the resource %s from the dataset %s' % \
                (user['fullname'], resource['name'], package['title']) \
                in stripped, stripped

        # Follow the package.
        follow_dataset(context, {'id': package['id']})
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s started following %s' % (user['fullname'],
                package['title']) not in stripped, stripped

        # Follow another user.
        follow_user(context, {'id': 'joeadmin'})
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s started following %s' % (user['fullname'],
                'joeadmin') not in stripped, stripped

        # Create a new group.
        group = {
            'name': 'baseball-stats-group',
            'title': 'A Group for Datasets about Baseball'
            }
        context['allow_partial_update'] = True
        group = group_create(context, group)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s created the group %s' % (user['fullname'], group['title']) \
                in stripped, stripped

        # Update the group.
        group['title'] = 'updated'
        group = group_update(context, group)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s updated the group %s' % (user['fullname'], group['title']) \
                in stripped, stripped

        # Delete the group.
        group['state'] = 'deleted'
        group_update(context, group)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s deleted the group %s' % (user['fullname'], group['title']) \
                in stripped, stripped

        # Add a new tag to the package.
        tag = {'name': 'baseball'}
        package['tags'].append(tag)
        package = package_update(context, package)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s added the tag %s to the dataset %s' % \
                (user['fullname'], tag['name'], package['title']) \
                in stripped, stripped

        # Remove the tag from the package.
        package['tags'] = []
        context['allow_partial_update'] = False
        package_update(context, package)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s removed the tag %s from the dataset %s' % \
                (user['fullname'], tag['name'], package['title']) \
                in stripped, stripped

        # Add an extra to the package.
        package['extras'].append({'key': 'quality', 'value': '10000'})
        package = package_update(context, package)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s added the extra "%s" to the dataset %s' % \
                (user['fullname'], 'quality', package['title']) \
                in stripped, stripped

        # Update the extra.
        package['extras'][0]['value'] = 'updated'
        package = package_update(context, package)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s changed the extra "%s" of the dataset %s' % \
                (user['fullname'], 'quality', package['title']) \
                in stripped, stripped

        # Delete the extra.
        del package['extras'][0]
        package = package_update(context, package)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s deleted the extra "%s" from the dataset %s' % \
                (user['fullname'], 'quality', package['title']) \
                in stripped, stripped

        # Delete the package.
        # we need to get round the delete permission
        context['ignore_auth'] = True
        package_delete(context, package)
        del context['ignore_auth']
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s deleted the dataset %s' % \
                (user['fullname'], package['title']) \
                in stripped, stripped

        # Update the user's profile.
        user['about'] = ''
        user_update(context, user)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s updated their profile' % user['fullname'] \
                in stripped, stripped

        # By now we've created >15 activities, but only the latest 15 should
        # appear on the page.
        result = self.app.get(offset, status=200)
        assert result.body.count('<span class="actor">') \
                == 15, result.body.count('<span class="actor">')

        # The user's dashboard page should load successfully and have the
        # latest 15 activities on it.
        offset = url_for('dashboard.index')
        extra_environ = {'Authorization':
                str(ckan.model.User.get('billybeane').apikey)}
        result = self.app.get(offset, extra_environ=extra_environ,
                status=200)
        assert result.body.count('<span class="actor">') == 15, \
            result.body.count('<span class="actor">')
Exemplo n.º 7
0
    def test_activity(self):
        """Test activity streams HTML rendering."""

        # Register a new user.
        user_dict = {'name': 'billybeane',
                'fullname': 'Billy Beane',
                'about': 'General Manager, Oakland Athletics',
                'email': '*****@*****.**',
                'password': '******'}
        context = {
            'model': ckan.model,
            'session': ckan.model.Session,
            'user': self.sysadmin_user.name,
            'allow_partial_update': True,
            'extras_as_string': True,
            }
        user = user_create(context, user_dict)
        offset = url_for(controller='user', action='read', id=user['id'])
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s signed up.' % user['fullname'] in stripped, stripped

        # Create a new package.
        package = {
            'name' : 'baseball_stats',
            'title' : "Billy's Stats about Baseball Players",
        }
        context['user'] = user['name']
        package = package_create(context, package)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s created the dataset %s ' % (
                user['fullname'], package['title']) in stripped, stripped

        # Add a resource to the package.
        resource = {
            'url': 'http://www.example.com',
            'description': "Chad Bradford's OBP Stats`",
            'format': 'cvs',
            'name': 'Chad Bradford Stats',
            }
        package['resources'].append(resource)
        request_data = {
                'id': package['id'],
                'resources': package['resources'],
                }
        package = package_update(context, request_data)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s added the resource %s to the dataset %s' % \
                (user['fullname'], resource['name'], package['title']) \
                in stripped, stripped

        # Update the package.
        package['title'] =  "Billy's Updated Stats about Baseball Players"
        package = package_update(context, package)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s updated the dataset %s' \
                % (user['fullname'], package['title']) \
                in stripped, stripped

        # Update the resource.
        resource = package['resources'][0]
        resource['name'] = 'Chad Bradford Updated Stats'
        resource = resource_update(context, resource)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s updated the resource %s in the dataset %s' \
                % (user['fullname'], resource['name'], package['title']) \
                in stripped, stripped

        # Delete the resource.
        context['allow_partial_update'] = False
        package['resources'] = []
        package_update(context, package)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s deleted the resource %s from the dataset %s' % \
                (user['fullname'], resource['name'], package['title']) \
                in stripped, stripped

        # Create a new group.
        group = {
            'name': 'baseball-stats-group',
            'title': 'A Group for Datasets about Baseball'
            }
        context['allow_partial_update'] = True
        group = group_create(context, group)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s created the group %s' % (user['fullname'], group['name']) \
                in stripped, stripped

        # Update the group.
        group['title'] = 'updated'
        group = group_update(context, group)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s updated the group %s' % (user['fullname'], group['name']) \
                in stripped, stripped

        # Delete the group.
        group['state'] = 'deleted'
        group_update(context, group)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s deleted the group %s' % (user['fullname'], group['name']) \
                in stripped, stripped

        # Add a new tag to the package.
        tag = {'name': 'baseball'}
        package['tags'].append(tag)
        package = package_update(context, package)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s added the tag %s to the dataset %s' % \
                (user['fullname'], tag['name'], package['title']) \
                in stripped, stripped

        # Remove the tag from the package.
        package['tags'] = []
        context['allow_partial_update'] = False
        package_update(context, package)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s removed the tag %s from the dataset %s' % \
                (user['fullname'], tag['name'], package['title']) \
                in stripped, stripped

        # Add an extra to the package.
        package['extras'].append({'key': 'quality', 'value': '10000'})
        package = package_update(context, package)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s added the extra "%s" to the dataset %s' % \
                (user['fullname'], 'quality', package['title']) \
                in stripped, stripped

        # Update the extra.
        package['extras'][0]['value'] = 'updated'
        package = package_update(context, package)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s changed the extra "%s" of the dataset %s' % \
                (user['fullname'], 'quality', package['title']) \
                in stripped, stripped

        # Delete the extra.
        del package['extras'][0]
        package = package_update(context, package)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s deleted the extra "%s" from the dataset %s' % \
                (user['fullname'], 'quality', package['title']) \
                in stripped, stripped

        # Delete the package.
        package_delete(context, package)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s deleted the dataset %s' % \
                (user['fullname'], package['title']) \
                in stripped, stripped

        # Update the user's profile.
        user['about'] = ''
        user_update(context, user)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert '%s updated their profile.' % user['fullname'] \
                in stripped, stripped

        # By now we've created >15 activities, but only the latest 15 should
        # appear on the page.
        result = self.app.get(offset, status=200)
        assert result.body.count('<div class="activity">') \
                == 15
 def teardown(self):
     """Clean up after each test"""
     datastore_delete(TestViewCreated.context, {'resource_id': self.resource['resource_id']})
     package_delete(TestViewCreated.context, {'id': self.dataset['id']})
Exemplo n.º 9
0
    def test_user_activity(self):
        """Test user activity streams HTML rendering."""

        # Register a new user.
        user_dict = {
            "name": "billybeane",
            "fullname": "Billy Beane",
            "about": "General Manager, Oakland Athletics",
            "email": "*****@*****.**",
            "password": "******",
        }
        context = {
            "model": ckan.model,
            "session": ckan.model.Session,
            "user": self.sysadmin_user.name,
            "allow_partial_update": True,
            "extras_as_string": True,
        }
        user = user_create(context, user_dict)
        offset = url_for(controller="user", action="read", id=user["id"])
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert "%s signed up" % user["fullname"] in stripped, stripped

        # Create a new package.
        package = {"name": "baseball_stats", "title": "Billy's Stats about Baseball Players"}
        context["user"] = user["name"]
        # FIXME This test use an old way to get at the schema to
        # recreate this we need to pretend to be using the api. We
        # should not be calling package_create like this we should be
        # going via the api or package controllers
        context["api_version"] = 3
        context["ignore_auth"] = True
        package = package_create(context, package)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert "%s created the dataset %s " % (user["fullname"], package["title"]) in stripped, stripped

        # Add a resource to the package.
        resource = {
            "url": "http://www.example.com",
            "description": "Chad Bradford's OBP Stats`",
            "format": "cvs",
            "name": "Chad Bradford Stats",
        }
        package["resources"].append(resource)
        request_data = {"id": package["id"], "resources": package["resources"]}
        package = package_update(context, request_data)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert (
            "%s added the resource %s to the dataset %s" % (user["fullname"], resource["name"], package["title"])
            in stripped
        ), stripped

        # Update the package.
        package["title"] = "Billy's Updated Stats about Baseball Players"
        package = package_update(context, package)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert "%s updated the dataset %s" % (user["fullname"], package["title"]) in stripped, stripped

        # Update the resource.
        resource = package["resources"][0]
        resource["name"] = "Chad Bradford Updated Stats"
        resource = resource_update(context, resource)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert (
            "%s updated the resource %s in the dataset %s" % (user["fullname"], resource["name"], package["title"])
            in stripped
        ), stripped

        # Delete the resource.
        context["allow_partial_update"] = False
        package["resources"] = []
        package_update(context, package)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert (
            "%s deleted the resource %s from the dataset %s" % (user["fullname"], resource["name"], package["title"])
            in stripped
        ), stripped

        # Follow the package.
        follow_dataset(context, {"id": package["id"]})
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert "%s started following %s" % (user["fullname"], package["title"]) not in stripped, stripped

        # Follow another user.
        follow_user(context, {"id": "joeadmin"})
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert "%s started following %s" % (user["fullname"], "joeadmin") not in stripped, stripped

        # Create a new group.
        group = {"name": "baseball-stats-group", "title": "A Group for Datasets about Baseball"}
        context["allow_partial_update"] = True
        group = group_create(context, group)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert "%s created the group %s" % (user["fullname"], group["title"]) in stripped, stripped

        # Update the group.
        group["title"] = "updated"
        group = group_update(context, group)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert "%s updated the group %s" % (user["fullname"], group["title"]) in stripped, stripped

        # Delete the group.
        group["state"] = "deleted"
        group_update(context, group)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert "%s deleted the group %s" % (user["fullname"], group["title"]) in stripped, stripped

        # Add a new tag to the package.
        tag = {"name": "baseball"}
        package["tags"].append(tag)
        package = package_update(context, package)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert (
            "%s added the tag %s to the dataset %s" % (user["fullname"], tag["name"], package["title"]) in stripped
        ), stripped

        # Remove the tag from the package.
        package["tags"] = []
        context["allow_partial_update"] = False
        package_update(context, package)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert (
            "%s removed the tag %s from the dataset %s" % (user["fullname"], tag["name"], package["title"]) in stripped
        ), stripped

        # Add an extra to the package.
        package["extras"].append({"key": "quality", "value": "10000"})
        package = package_update(context, package)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert (
            '%s added the extra "%s" to the dataset %s' % (user["fullname"], "quality", package["title"]) in stripped
        ), stripped

        # Update the extra.
        package["extras"][0]["value"] = "updated"
        package = package_update(context, package)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert (
            '%s changed the extra "%s" of the dataset %s' % (user["fullname"], "quality", package["title"]) in stripped
        ), stripped

        # Delete the extra.
        del package["extras"][0]
        package = package_update(context, package)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert (
            '%s deleted the extra "%s" from the dataset %s' % (user["fullname"], "quality", package["title"])
            in stripped
        ), stripped

        # Delete the package.
        # we need to get round the delete permission
        context["ignore_auth"] = True
        package_delete(context, package)
        del context["ignore_auth"]
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert "%s deleted the dataset %s" % (user["fullname"], package["title"]) in stripped, stripped

        # Update the user's profile.
        user["about"] = ""
        user_update(context, user)
        result = self.app.get(offset, status=200)
        stripped = self.strip_tags(result)
        assert "%s updated their profile" % user["fullname"] in stripped, stripped

        # By now we've created >15 activities, but only the latest 15 should
        # appear on the page.
        result = self.app.get(offset, status=200)
        assert result.body.count('<div class="activity">') == 15

        # The user's dashboard page should load successfully and have the
        # latest 15 activities on it.
        offset = url_for(controller="user", action="dashboard")
        extra_environ = {"Authorization": str(ckan.model.User.get("billybeane").apikey)}
        result = self.app.post(offset, extra_environ=extra_environ, status=200)
        assert result.body.count('<div class="activity">') == 15
 def teardown_class(cls):
     """Clean up after the test"""
     datastore_delete(cls.context, {'resource_id': cls.resource['resource_id']})
     package_delete(cls.context, {'id': cls.dataset['id']})
     p.unload('tiledmap')
     p.unload('datastore')