Exemple #1
0
    def setup_class(cls):
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")
        p.load('datastore')
        ctd.CreateTestData.create()
        cls.sysadmin_user = model.User.get('testsysadmin')
        cls.normal_user = model.User.get('annafan')
        resource = model.Package.get('annakarenina').resources[0]
        cls.data = {
            'resource_id': resource.id,
            'fields': [{'id': u'b\xfck', 'type': 'text'},
                       {'id': 'author', 'type': 'text'},
                       {'id': 'nested', 'type': 'json'},
                       {'id': 'characters', 'type': 'text[]'},
                       {'id': 'published'}],
            'primary_key': u'b\xfck',
            'records': [{u'b\xfck': 'annakarenina', 'author': 'tolstoy',
                        'published': '2005-03-01', 'nested': ['b', {'moo': 'moo'}]},
                        {u'b\xfck': 'warandpeace', 'author': 'tolstoy',
                        'nested': {'a':'b'}}
                       ]
            }
        postparams = '%s=1' % json.dumps(cls.data)
        auth = {'Authorization': str(cls.sysadmin_user.apikey)}
        res = cls.app.post('/api/action/datastore_create', params=postparams,
                           extra_environ=auth)
        res_dict = json.loads(res.body)
        assert res_dict['success'] is True

        import pylons
        engine = db._get_engine(
                None,
                {'connection_url': pylons.config['ckan.datastore.write_url']}
            )
        cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
Exemple #2
0
    def setup_class(cls):
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")
        p.load('datastore')
        ctd.CreateTestData.create()
        cls.sysadmin_user = model.User.get('testsysadmin')
        cls.normal_user = model.User.get('annafan')
        resource = model.Package.get('annakarenina').resources[0]
        cls.data = {
            'resource_id': resource.id,
            'aliases': u'b\xfck2',
            'fields': [{'id': 'book', 'type': 'text'},
                       {'id': 'author', 'type': 'text'},
                       {'id': 'rating with %', 'type': 'text'}],
            'records': [{'book': 'annakarenina', 'author': 'tolstoy',
                         'rating with %': '90%'},
                        {'book': 'warandpeace', 'author': 'tolstoy',
                         'rating with %': '42%'}]
        }

        engine = db._get_engine(
            {'connection_url': pylons.config['ckan.datastore.write_url']})
        cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
        set_url_type(
            model.Package.get('annakarenina').resources, cls.sysadmin_user)
Exemple #3
0
    def setup_class(cls):
        wsgiapp = middleware.make_app(config['global_conf'], **config)
        cls.app = paste.fixture.TestApp(wsgiapp)
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")
        p.load('datastore')
        ctd.CreateTestData.create()
        cls.sysadmin_user = model.User.get('testsysadmin')
        cls.normal_user = model.User.get('annafan')
        resource = model.Package.get('annakarenina').resources[0]
        cls.data = {
            'resource_id': resource.id,
            'aliases': 'books',
            'fields': [{'id': u'b\xfck', 'type': 'text'},
                       {'id': 'author', 'type': 'text'},
                       {'id': 'published'},
                       {'id': u'characters', u'type': u'_text'}],
            'records': [{u'b\xfck': 'annakarenina',
                        'author': 'tolstoy',
                        'published': '2005-03-01',
                        'nested': ['b', {'moo': 'moo'}],
                        u'characters': [u'Princess Anna', u'Sergius']},
                        {u'b\xfck': 'warandpeace', 'author': 'tolstoy',
                         'nested': {'a': 'b'}}]
        }
        postparams = '%s=1' % json.dumps(cls.data)
        auth = {'Authorization': str(cls.sysadmin_user.apikey)}
        res = cls.app.post('/api/action/datastore_create', params=postparams,
                           extra_environ=auth)
        res_dict = json.loads(res.body)
        assert res_dict['success'] is True

        engine = db._get_engine({
            'connection_url': config['ckan.datastore.write_url']})
        cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
Exemple #4
0
    def setup_class(cls):
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")
        p.load('datastore')
        ctd.CreateTestData.create()
        cls.sysadmin_user = model.User.get('testsysadmin')
        cls.normal_user = model.User.get('annafan')
        resource = model.Package.get('annakarenina').resources[0]
        cls.data = {
            'resource_id': resource.id,
            'aliases': 'books2',
            'fields': [{'id': 'book', 'type': 'text'},
                       {'id': 'author', 'type': 'text'}],
            'records': [{'book': 'annakarenina', 'author': 'tolstoy'},
                        {'book': 'warandpeace', 'author': 'tolstoy'}]
        }

        #model.repo.rebuild_db()
        #model.repo.clean_db()

        import pylons
        engine = db._get_engine(
                None,
                {'connection_url': pylons.config['ckan.datastore.write_url']}
            )
        cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
Exemple #5
0
    def setup_class(cls):
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")
        p.load('datastore')
        ctd.CreateTestData.create()
        cls.sysadmin_user = model.User.get('testsysadmin')
        cls.normal_user = model.User.get('annafan')
        set_url_type(
            model.Package.get('annakarenina').resources, cls.sysadmin_user)
        resource = model.Package.get('annakarenina').resources[0]
        cls.data = {
            'resource_id': resource.id,
            'fields': [{'id': u'b\xfck', 'type': 'text'},
                       {'id': 'author', 'type': 'text'},
                       {'id': 'nested', 'type': 'json'},
                       {'id': 'characters', 'type': 'text[]'},
                       {'id': 'published'}],
            'primary_key': u'b\xfck',
            'records': [{u'b\xfck': 'annakarenina', 'author': 'tolstoy',
                        'published': '2005-03-01', 'nested': ['b', {'moo': 'moo'}]},
                        {u'b\xfck': 'warandpeace', 'author': 'tolstoy',
                        'nested': {'a':'b'}}
                       ]
            }
        postparams = '%s=1' % json.dumps(cls.data)
        auth = {'Authorization': str(cls.sysadmin_user.apikey)}
        res = cls.app.post('/api/action/datastore_create', params=postparams,
                           extra_environ=auth)
        res_dict = json.loads(res.body)
        assert res_dict['success'] is True

        engine = db._get_engine(
            {'connection_url': pylons.config['ckan.datastore.write_url']})
        cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
Exemple #6
0
    def setup_class(cls):
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")
        plugin = p.load("datastore")
        if plugin.legacy_mode:
            # make sure we undo adding the plugin
            p.unload("datastore")
            raise nose.SkipTest("SQL tests are not supported in legacy mode")
        ctd.CreateTestData.create()
        cls.sysadmin_user = model.User.get("testsysadmin")
        cls.normal_user = model.User.get("annafan")
        cls.dataset = model.Package.get("annakarenina")
        resource = cls.dataset.resources[0]
        cls.data = {
            "resource_id": resource.id,
            "aliases": "books4",
            "fields": [{"id": u"b\xfck", "type": "text"}, {"id": "author", "type": "text"}, {"id": "published"}],
            "records": [
                {
                    u"b\xfck": "annakarenina",
                    "author": "tolstoy",
                    "published": "2005-03-01",
                    "nested": ["b", {"moo": "moo"}],
                },
                {u"b\xfck": "warandpeace", "author": "tolstoy", "nested": {"a": "b"}},
            ],
        }
        postparams = "%s=1" % json.dumps(cls.data)
        auth = {"Authorization": str(cls.sysadmin_user.apikey)}
        res = cls.app.post("/api/action/datastore_create", params=postparams, extra_environ=auth)
        res_dict = json.loads(res.body)
        assert res_dict["success"] is True

        # Make an organization, because private datasets must belong to one.
        cls.organization = tests.call_action_api(
            cls.app, "organization_create", name="test_org", apikey=cls.sysadmin_user.apikey
        )

        cls.expected_records = [
            {
                u"_full_text": u"'annakarenina':1 'b':3 'moo':4 'tolstoy':2",
                u"_id": 1,
                u"author": u"tolstoy",
                u"b\xfck": u"annakarenina",
                u"nested": [u"b", {u"moo": u"moo"}],
                u"published": u"2005-03-01T00:00:00",
            },
            {
                u"_full_text": u"'b':3 'tolstoy':2 'warandpeac':1",
                u"_id": 2,
                u"author": u"tolstoy",
                u"b\xfck": u"warandpeace",
                u"nested": {u"a": u"b"},
                u"published": None,
            },
        ]
        cls.expected_join_results = [{u"first": 1, u"second": 1}, {u"first": 1, u"second": 2}]

        engine = db._get_engine({"connection_url": pylons.config["ckan.datastore.write_url"]})
        cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
Exemple #7
0
    def setup_class(cls):
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")
        p.load('datastore')
        ctd.CreateTestData.create()
        cls.sysadmin_user = model.User.get('testsysadmin')
        cls.normal_user = model.User.get('annafan')
        resource = model.Package.get('annakarenina').resources[0]
        cls.data = {
            'resource_id':
            resource.id,
            'aliases':
            'books',
            'fields': [{
                'id': u'b\xfck',
                'type': 'text'
            }, {
                'id': 'author',
                'type': 'text'
            }, {
                'id': 'published'
            }, {
                'id': u'characters',
                u'type': u'_text'
            }],
            'records': [{
                u'b\xfck': 'annakarenina',
                'author': 'tolstoy',
                'published': '2005-03-01',
                'nested': ['b', {
                    'moo': 'moo'
                }],
                u'characters': [u'Princess Anna', u'Sergius']
            }, {
                u'b\xfck': 'warandpeace',
                'author': 'tolstoy',
                'nested': {
                    'a': 'b'
                }
            }]
        }
        postparams = '%s=1' % json.dumps(cls.data)
        auth = {'Authorization': str(cls.sysadmin_user.apikey)}
        res = cls.app.post('/api/action/datastore_create',
                           params=postparams,
                           extra_environ=auth)
        res_dict = json.loads(res.body)
        assert res_dict['success'] is True

        import pylons
        engine = db._get_engine(
            None,
            {'connection_url': pylons.config['ckan.datastore.write_url']})
        cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))

        cls._original_config = config.copy()
        config['ckan.plugins'] = 'datastore'
        wsgiapp = middleware.make_app(config['global_conf'], **config)
        cls.app = paste.fixture.TestApp(wsgiapp)
Exemple #8
0
 def setup_class(cls):
     if not tests.is_datastore_supported():
         raise nose.SkipTest("Datastore not supported")
     plugin = p.load('datastore')
     if plugin.legacy_mode:
         # make sure we undo adding the plugin
         p.unload('datastore')
         raise nose.SkipTest("Info is not supported in legacy mode")
Exemple #9
0
 def test_pg_version_check(self):
     if not tests.is_datastore_supported():
         raise nose.SkipTest("Datastore not supported")
     engine = db._get_engine(None,
         {'connection_url': pylons.config['sqlalchemy.url']})
     connection = engine.connect()
     assert db._pg_version_is_at_least(connection, '8.0')
     assert not db._pg_version_is_at_least(connection, '10.0')
Exemple #10
0
 def test_pg_version_check(self):
     if not tests.is_datastore_supported():
         raise nose.SkipTest("Datastore not supported")
     engine = db._get_engine(
         None, {'connection_url': pylons.config['sqlalchemy.url']})
     connection = engine.connect()
     assert db._pg_version_is_at_least(connection, '8.0')
     assert not db._pg_version_is_at_least(connection, '10.0')
Exemple #11
0
    def setup_class(cls):
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")
        plugin = p.load('datastore')
        if plugin.legacy_mode:
            # make sure we undo adding the plugin
            p.unload('datastore')
            raise nose.SkipTest("SQL tests are not supported in legacy mode")
        ctd.CreateTestData.create()
        cls.sysadmin_user = model.User.get('testsysadmin')
        cls.normal_user = model.User.get('annafan')
        cls.dataset = model.Package.get('annakarenina')
        resource = cls.dataset.resources[0]
        cls.data = {
            'resource_id': resource.id,
            'force': True,
            'aliases': 'books4',
            'fields': [{'id': u'b\xfck', 'type': 'text'},
                       {'id': 'author', 'type': 'text'},
                       {'id': 'published'}],
            'records': [{u'b\xfck': 'annakarenina',
                        'author': 'tolstoy',
                        'published': '2005-03-01',
                        'nested': ['b', {'moo': 'moo'}]},
                        {u'b\xfck': 'warandpeace',
                        'author': 'tolstoy',
                        'nested': {'a': 'b'}}]
        }
        postparams = '%s=1' % json.dumps(cls.data)
        auth = {'Authorization': str(cls.sysadmin_user.apikey)}
        res = cls.app.post('/api/action/datastore_create', params=postparams,
                           extra_environ=auth)
        res_dict = json.loads(res.body)
        assert res_dict['success'] is True

        # Make an organization, because private datasets must belong to one.
        cls.organization = tests.call_action_api(
            cls.app, 'organization_create',
            name='test_org',
            apikey=cls.sysadmin_user.apikey)

        cls.expected_records = [{u'_full_text': u"'annakarenina':1 'b':3 'moo':4 'tolstoy':2",
                                 u'_id': 1,
                                 u'author': u'tolstoy',
                                 u'b\xfck': u'annakarenina',
                                 u'nested': [u'b', {u'moo': u'moo'}],
                                 u'published': u'2005-03-01T00:00:00'},
                                {u'_full_text': u"'b':3 'tolstoy':2 'warandpeac':1",
                                 u'_id': 2,
                                 u'author': u'tolstoy',
                                 u'b\xfck': u'warandpeace',
                                 u'nested': {u'a': u'b'},
                                 u'published': None}]
        cls.expected_join_results = [{u'first': 1, u'second': 1}, {u'first': 1, u'second': 2}]

        engine = db._get_engine(
            {'connection_url': pylons.config['ckan.datastore.write_url']})
        cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
Exemple #12
0
    def setup_class(cls):
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")
        p.load('datastore')
        ctd.CreateTestData.create()
        cls.sysadmin_user = model.User.get('testsysadmin')
        cls.normal_user = model.User.get('annafan')
        cls.dataset = model.Package.get('annakarenina')
        cls.resource = cls.dataset.resources[0]
        cls.data = {
            'resource_id': cls.resource.id,
            'force': True,
            'aliases': 'books3',
            'fields': [{'id': u'b\xfck', 'type': 'text'},
                       {'id': 'author', 'type': 'text'},
                       {'id': 'published'},
                       {'id': u'characters', u'type': u'_text'},
                       {'id': 'rating with %'}],
            'records': [{u'b\xfck': 'annakarenina', 'author': 'tolstoy',
                        'published': '2005-03-01', 'nested': ['b', {'moo': 'moo'}],
                        u'characters': [u'Princess Anna', u'Sergius'],
                        'rating with %': '60%'},
                        {u'b\xfck': 'warandpeace', 'author': 'tolstoy',
                        'nested': {'a': 'b'}, 'rating with %': '99%'}
                       ]
        }
        postparams = '%s=1' % json.dumps(cls.data)
        auth = {'Authorization': str(cls.sysadmin_user.apikey)}
        res = cls.app.post('/api/action/datastore_create', params=postparams,
                           extra_environ=auth)
        res_dict = json.loads(res.body)
        assert res_dict['success'] is True

        # Make an organization, because private datasets must belong to one.
        cls.organization = tests.call_action_api(
            cls.app, 'organization_create',
            name='test_org',
            apikey=cls.sysadmin_user.apikey)

        cls.expected_records = [{u'published': u'2005-03-01T00:00:00',
                                 u'_id': 1,
                                 u'nested': [u'b', {u'moo': u'moo'}],
                                 u'b\xfck': u'annakarenina',
                                 u'author': u'tolstoy',
                                 u'characters': [u'Princess Anna', u'Sergius'],
                                 u'rating with %': u'60%'},
                                {u'published': None,
                                 u'_id': 2,
                                 u'nested': {u'a': u'b'},
                                 u'b\xfck': u'warandpeace',
                                 u'author': u'tolstoy',
                                 u'characters': None,
                                 u'rating with %': u'99%'}]

        engine = db._get_engine(
                {'connection_url': pylons.config['ckan.datastore.write_url']}
            )
        cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
Exemple #13
0
 def setup_class(cls):
     if not tests.is_datastore_supported():
         raise nose.SkipTest("Datastore not supported")
     p.load('datastore')
     ctd.CreateTestData.create()
     cls.sysadmin_user = model.User.get('testsysadmin')
     cls.normal_user = model.User.get('annafan')
     engine = db._get_engine(
         {'connection_url': pylons.config['ckan.datastore.write_url']})
     cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
Exemple #14
0
 def setup_class(cls):
     if not tests.is_datastore_supported():
         raise nose.SkipTest("Datastore not supported")
     p.load('datastore')
     ctd.CreateTestData.create()
     cls.sysadmin_user = model.User.get('testsysadmin')
     cls.normal_user = model.User.get('annafan')
     engine = db._get_engine(
         {'connection_url': pylons.config['ckan.datastore.write_url']})
     cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
    def setup_class(cls):
        if not is_datastore_supported():
            raise nose.SkipTest('Datastore not supported')
        if not p.plugin_loaded('datastore'):
            p.load('datastore')
        if not p.plugin_loaded('datapusher'):
            p.load('datapusher')
        if not p.plugin_loaded('recline_grid_view'):
            p.load('recline_grid_view')

        helpers.reset_db()
Exemple #16
0
    def setup_class(cls):
        if not is_datastore_supported():
            raise nose.SkipTest('Datastore not supported')
        if not p.plugin_loaded('datastore'):
            p.load('datastore')
        if not p.plugin_loaded('datapusher'):
            p.load('datapusher')
        if not p.plugin_loaded('recline_grid_view'):
            p.load('recline_grid_view')

        helpers.reset_db()
Exemple #17
0
    def setup_class(cls):

        wsgiapp = middleware.make_app(config['global_conf'], **config)
        cls.app = paste.fixture.TestApp(wsgiapp)
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")
        p.load('datastore')
        ctd.CreateTestData.create()
        cls.sysadmin_user = model.User.get('testsysadmin')
        cls.normal_user = model.User.get('annafan')
        engine = db._get_engine(
            {'connection_url': pylons.config['ckan.datastore.write_url']})
        cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
Exemple #18
0
    def setup_class(cls):

        wsgiapp = middleware.make_app(config["global_conf"], **config)
        cls.app = paste.fixture.TestApp(wsgiapp)
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")
        p.load("datastore")
        ctd.CreateTestData.create()
        cls.sysadmin_user = model.User.get("testsysadmin")
        cls.normal_user = model.User.get("annafan")
        engine = db._get_engine({"connection_url": pylons.config["ckan.datastore.write_url"]})
        cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
        set_url_type(model.Package.get("annakarenina").resources, cls.sysadmin_user)
Exemple #19
0
    def setup_class(cls):

        wsgiapp = middleware.make_app(config['global_conf'], **config)
        cls.app = paste.fixture.TestApp(wsgiapp)
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")
        p.load('datastore')
        ctd.CreateTestData.create()
        cls.sysadmin_user = model.User.get('testsysadmin')
        cls.normal_user = model.User.get('annafan')
        engine = db._get_engine(
            {'connection_url': pylons.config['ckan.datastore.write_url']})
        cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
Exemple #20
0
    def setup_class(cls):
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")
        plugin = p.load('datastore')
        if plugin.legacy_mode:
            raise nose.SkipTest("SQL tests are not supported in legacy mode")
        ctd.CreateTestData.create()
        cls.sysadmin_user = model.User.get('testsysadmin')
        cls.normal_user = model.User.get('annafan')
        resource = model.Package.get('annakarenina').resources[0]
        cls.data = {
            'resource_id': resource.id,
            'aliases': 'books4',
            'fields': [{'id': u'b\xfck', 'type': 'text'},
                       {'id': 'author', 'type': 'text'},
                       {'id': 'published'}],
            'records': [{u'b\xfck': 'annakarenina',
                        'author': 'tolstoy',
                        'published': '2005-03-01',
                        'nested': ['b', {'moo': 'moo'}]},
                        {u'b\xfck': 'warandpeace',
                        'author': 'tolstoy',
                        'nested': {'a':'b'}}
                       ]
        }
        postparams = '%s=1' % json.dumps(cls.data)
        auth = {'Authorization': str(cls.sysadmin_user.apikey)}
        res = cls.app.post('/api/action/datastore_create', params=postparams,
                           extra_environ=auth)
        res_dict = json.loads(res.body)
        assert res_dict['success'] is True

        cls.expected_records = [{u'_full_text': u"'annakarenina':1 'b':3 'moo':4 'tolstoy':2",
                                  u'_id': 1,
                                  u'author': u'tolstoy',
                                  u'b\xfck': u'annakarenina',
                                  u'nested': [u'b', {u'moo': u'moo'}],
                                  u'published': u'2005-03-01T00:00:00'},
                                 {u'_full_text': u"'b':3 'tolstoy':2 'warandpeac':1",
                                  u'_id': 2,
                                  u'author': u'tolstoy',
                                  u'b\xfck': u'warandpeace',
                                  u'nested': {u'a': u'b'},
                                  u'published': None}]
        cls.expected_join_results = [{u'first': 1, u'second': 1}, {u'first': 1, u'second': 2}]
Exemple #21
0
    def setup_class(cls):
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")
        plugin = p.load('datastore')
        if plugin.legacy_mode:
            raise nose.SkipTest("SQL tests are not supported in legacy mode")
        ctd.CreateTestData.create()
        cls.sysadmin_user = model.User.get('testsysadmin')
        cls.normal_user = model.User.get('annafan')
        resource = model.Package.get('annakarenina').resources[0]
        cls.data = {
            'resource_id': resource.id,
            'aliases': 'books4',
            'fields': [{'id': u'b\xfck', 'type': 'text'},
                       {'id': 'author', 'type': 'text'},
                       {'id': 'published'}],
            'records': [{u'b\xfck': 'annakarenina',
                        'author': 'tolstoy',
                        'published': '2005-03-01',
                        'nested': ['b', {'moo': 'moo'}]},
                        {u'b\xfck': 'warandpeace',
                        'author': 'tolstoy',
                        'nested': {'a':'b'}}
                       ]
        }
        postparams = '%s=1' % json.dumps(cls.data)
        auth = {'Authorization': str(cls.sysadmin_user.apikey)}
        res = cls.app.post('/api/action/datastore_create', params=postparams,
                           extra_environ=auth)
        res_dict = json.loads(res.body)
        assert res_dict['success'] is True

        cls.expected_records = [{u'_full_text': u"'annakarenina':1 'b':3 'moo':4 'tolstoy':2",
                                  u'_id': 1,
                                  u'author': u'tolstoy',
                                  u'b\xfck': u'annakarenina',
                                  u'nested': [u'b', {u'moo': u'moo'}],
                                  u'published': u'2005-03-01T00:00:00'},
                                 {u'_full_text': u"'b':3 'tolstoy':2 'warandpeac':1",
                                  u'_id': 2,
                                  u'author': u'tolstoy',
                                  u'b\xfck': u'warandpeace',
                                  u'nested': {u'a': u'b'},
                                  u'published': None}]
        cls.expected_join_results = [{u'first': 1, u'second': 1}, {u'first': 1, u'second': 2}]
    def setup_class(cls):
        """Prepare the test"""
        # We need datastore for these tests.
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")

        # Setup a test app
        wsgiapp = middleware.make_app(config['global_conf'], **config)
        cls.app = paste.fixture.TestApp(wsgiapp)
        ctd.CreateTestData.create()
        cls.context = {'model': ckan.model,
                       'session': ckan.model.Session,
                       'user': ckan.model.User.get('testsysadmin').name}
        cls.engine = create_engine(config['ckan.datastore.write_url'])

        # Load plugins
        p.load('tiledmap')
        p.load('datastore')
Exemple #23
0
    def setup_class(cls):
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")
        p.load("datastore")
        ctd.CreateTestData.create()
        cls.sysadmin_user = model.User.get("testsysadmin")
        cls.normal_user = model.User.get("annafan")
        resource = model.Package.get("annakarenina").resources[0]
        cls.data = {
            "resource_id": resource.id,
            "aliases": "books2",
            "fields": [{"id": "book", "type": "text"}, {"id": "author", "type": "text"}],
            "records": [{"book": "annakarenina", "author": "tolstoy"}, {"book": "warandpeace", "author": "tolstoy"}],
        }

        # model.repo.rebuild_db()
        # model.repo.clean_db()

        import pylons

        engine = db._get_engine(None, {"connection_url": pylons.config["ckan.datastore.write_url"]})
        cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
Exemple #24
0
 def setup_class(cls):
     if not tests.is_datastore_supported():
         raise nose.SkipTest("Datastore not supported")
     p.load('datastore')
     ctd.CreateTestData.create()
     cls.sysadmin_user = model.User.get('testsysadmin')
     cls.normal_user = model.User.get('annafan')
     resource = model.Package.get('annakarenina').resources[0]
     cls.data = dict(
         resource_id=resource.id,
         force=True,
         fields=[
           {'id': 'id'},
           {'id': 'date', 'type':'date'},
           {'id': 'x'},
           {'id': 'y'},
           {'id': 'z'},
           {'id': 'country'},
           {'id': 'title'},
           {'id': 'lat'},
           {'id': 'lon'}
         ],
         records=[
           {'id': 0, 'date': '2011-01-01', 'x': 1, 'y': 2, 'z': 3, 'country': 'DE', 'title': 'first', 'lat':52.56, 'lon':13.40},
           {'id': 1, 'date': '2011-02-02', 'x': 2, 'y': 4, 'z': 24, 'country': 'UK', 'title': 'second', 'lat':54.97, 'lon':-1.60},
           {'id': 2, 'date': '2011-03-03', 'x': 3, 'y': 6, 'z': 9, 'country': 'US', 'title': 'third', 'lat':40.00, 'lon':-75.5},
           {'id': 3, 'date': '2011-04-04', 'x': 4, 'y': 8, 'z': 6, 'country': 'UK', 'title': 'fourth', 'lat':57.27, 'lon':-6.20},
           {'id': 4, 'date': '2011-05-04', 'x': 5, 'y': 10, 'z': 15, 'country': 'UK', 'title': 'fifth', 'lat':51.58, 'lon':0},
           {'id': 5, 'date': '2011-06-02', 'x': 6, 'y': 12, 'z': 18, 'country': 'DE', 'title': 'sixth', 'lat':51.04, 'lon':7.9}
         ]
     )
     postparams = '%s=1' % json.dumps(cls.data)
     auth = {'Authorization': str(cls.normal_user.apikey)}
     res = cls.app.post('/api/action/datastore_create', params=postparams,
                        extra_environ=auth)
     res_dict = json.loads(res.body)
     assert res_dict['success'] is True
Exemple #25
0
 def setup_class(cls):
     if not tests.is_datastore_supported():
         raise nose.SkipTest("Datastore not supported")
     p.load("datastore")
     ctd.CreateTestData.create()
     cls.sysadmin_user = model.User.get("testsysadmin")
     cls.normal_user = model.User.get("annafan")
     resource = model.Package.get("annakarenina").resources[0]
     cls.data = dict(
         resource_id=resource.id,
         fields=[
             {"id": "id"},
             {"id": "date", "type": "date"},
             {"id": "x"},
             {"id": "y"},
             {"id": "z"},
             {"id": "country"},
             {"id": "title"},
             {"id": "lat"},
             {"id": "lon"},
         ],
         records=[
             {
                 "id": 0,
                 "date": "2011-01-01",
                 "x": 1,
                 "y": 2,
                 "z": 3,
                 "country": "DE",
                 "title": "first",
                 "lat": 52.56,
                 "lon": 13.40,
             },
             {
                 "id": 1,
                 "date": "2011-02-02",
                 "x": 2,
                 "y": 4,
                 "z": 24,
                 "country": "UK",
                 "title": "second",
                 "lat": 54.97,
                 "lon": -1.60,
             },
             {
                 "id": 2,
                 "date": "2011-03-03",
                 "x": 3,
                 "y": 6,
                 "z": 9,
                 "country": "US",
                 "title": "third",
                 "lat": 40.00,
                 "lon": -75.5,
             },
             {
                 "id": 3,
                 "date": "2011-04-04",
                 "x": 4,
                 "y": 8,
                 "z": 6,
                 "country": "UK",
                 "title": "fourth",
                 "lat": 57.27,
                 "lon": -6.20,
             },
             {
                 "id": 4,
                 "date": "2011-05-04",
                 "x": 5,
                 "y": 10,
                 "z": 15,
                 "country": "UK",
                 "title": "fifth",
                 "lat": 51.58,
                 "lon": 0,
             },
             {
                 "id": 5,
                 "date": "2011-06-02",
                 "x": 6,
                 "y": 12,
                 "z": 18,
                 "country": "DE",
                 "title": "sixth",
                 "lat": 51.04,
                 "lon": 7.9,
             },
         ],
     )
     postparams = "%s=1" % json.dumps(cls.data)
     auth = {"Authorization": str(cls.normal_user.apikey)}
     res = cls.app.post("/api/action/datastore_create", params=postparams, extra_environ=auth)
     res_dict = json.loads(res.body)
     assert res_dict["success"] is True
Exemple #26
0
    def setup_class(cls):
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")
        p.load("datastore")
        ctd.CreateTestData.create()
        cls.sysadmin_user = model.User.get("testsysadmin")
        cls.normal_user = model.User.get("annafan")
        cls.dataset = model.Package.get("annakarenina")
        cls.resource = cls.dataset.resources[0]
        cls.data = {
            "resource_id": cls.resource.id,
            "aliases": "books3",
            "fields": [
                {"id": u"b\xfck", "type": "text"},
                {"id": "author", "type": "text"},
                {"id": "published"},
                {"id": u"characters", u"type": u"_text"},
                {"id": "rating with %"},
            ],
            "records": [
                {
                    u"b\xfck": "annakarenina",
                    "author": "tolstoy",
                    "published": "2005-03-01",
                    "nested": ["b", {"moo": "moo"}],
                    u"characters": [u"Princess Anna", u"Sergius"],
                    "rating with %": "60%",
                },
                {u"b\xfck": "warandpeace", "author": "tolstoy", "nested": {"a": "b"}, "rating with %": "99%"},
            ],
        }
        postparams = "%s=1" % json.dumps(cls.data)
        auth = {"Authorization": str(cls.sysadmin_user.apikey)}
        res = cls.app.post("/api/action/datastore_create", params=postparams, extra_environ=auth)
        res_dict = json.loads(res.body)
        assert res_dict["success"] is True

        # Make an organization, because private datasets must belong to one.
        cls.organization = tests.call_action_api(
            cls.app, "organization_create", name="test_org", apikey=cls.sysadmin_user.apikey
        )

        cls.expected_records = [
            {
                u"published": u"2005-03-01T00:00:00",
                u"_id": 1,
                u"nested": [u"b", {u"moo": u"moo"}],
                u"b\xfck": u"annakarenina",
                u"author": u"tolstoy",
                u"characters": [u"Princess Anna", u"Sergius"],
                u"rating with %": u"60%",
            },
            {
                u"published": None,
                u"_id": 2,
                u"nested": {u"a": u"b"},
                u"b\xfck": u"warandpeace",
                u"author": u"tolstoy",
                u"characters": None,
                u"rating with %": u"99%",
            },
        ]

        engine = db._get_engine({"connection_url": pylons.config["ckan.datastore.write_url"]})
        cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
    def setup_class(cls, mock_flash):
        """Prepare the test"""
        # We need datastore for these tests.
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")

        # Setup a test app
        wsgiapp = middleware.make_app(config['global_conf'], **config)
        cls.app = paste.fixture.TestApp(wsgiapp)
        ctd.CreateTestData.create()
        cls.context = {'model': ckan.model,
                       'session': ckan.model.Session,
                       'user': ckan.model.User.get('testsysadmin').name}

        # Load plugins
        p.load('tiledmap')
        p.load('datastore')

        # Set windshaft host/port as these settings do not have a default.
        # TODO: Test that calls fail if not set
        tm_config.update({
            'tiledmap.windshaft.host': '127.0.0.1',
            'tiledmap.windshaft.port': '4000'
        })

        # Copy tiledmap settings
        cls.config = dict(tm_config.items())

        # Setup a dummy datastore.
        cls.dataset = package_create(cls.context, {'name': 'map-test-dataset'})
        cls.resource = datastore_create(cls.context, {
            'resource': {
                'package_id': cls.dataset['id']
            },
            'fields': [
                {'id': 'id', 'type': 'integer'},
                {'id': 'latitude', 'type': 'numeric'},
                {'id': 'longitude', 'type': 'numeric'},
                {'id': 'some_field_1', 'type': 'text'},
                {'id': 'some_field_2', 'type': 'text'}
            ],
            'primary_key': 'id'
        })

        # Add some data. We add 4 records such that:
        # - The first three records have 'some_field_1' set to 'hello' ;
        # - The third record does not have a geom ;
        # - The fourth record has a geom, but 'some_field_1' is set to something elese.
        datastore_upsert(cls.context, {
            'resource_id': cls.resource['resource_id'],
            'method': 'upsert',
            'records': [{
                'id': '1',
                'latitude': -15,
                'longitude': -11,
                'some_field_1': 'hello',
                'some_field_2': 'world'
            }, {
                'id': 2,
                'latitude': 48,
                'longitude': 23,
                'some_field_1': 'hello',
                'some_field_2': 'again'
            }, {
                'id': 3,
                'latitude': None,
                'longitude': None,
                'some_field_1': 'hello',
                'some_field_2': 'hello'
            }, {
                'id': 4,
                'latitude': 80,
                'longitude': 80,
                'some_field_1': 'all your bases',
                'some_field_2': 'are belong to us'
            }]
        })

        # Create a tiledmap resource view. This process itself is fully tested in test_view_create.py.
        # This will also generate the geometry column - that part of the process is fully tested in test_actions
        data_dict = {
            'description': u'',
            'title': u'test',
            'resource_id': cls.resource['resource_id'],
            'plot_marker_color': u'#EE0000',
            'enable_plot_map': u'True',
            'overlapping_records_view': u'',
            'longitude_field': u'longitude',
            'heat_intensity': u'0.1',
            'view_type': u'tiledmap',
            'utf_grid_title': u'_id',
            'plot_marker_line_color': u'#FFFFFF',
            'latitude_field': u'latitude',
            'enable_utf_grid': u'True',
            'utf_grid_fields' : ['some_field_1', 'some_field_2'],
            'grid_base_color': u'#F02323',
            'enable_heat_map': u'True',
            'enable_grid_map': u'True'
        }

        resource_view_create = p.toolkit.get_action('resource_view_create')
        cls.resource_view = resource_view_create(cls.context, data_dict)

        # Create a resource that does not have spatial fields
        cls.non_spatial_resource = datastore_create(cls.context, {
            'resource': {
                'package_id': cls.dataset['id']
            },
            'fields': [
                {'id': 'id', 'type': 'integer'},
                {'id': 'some_field', 'type': 'text'}
            ],
            'primary_key': 'id'
        })