Ejemplo n.º 1
0
    def test_backend_functionality(self, get_engine):
        engine = get_engine()
        execute = engine.execute
        fetchall = execute().fetchall
        execute.reset_mock()

        DatastoreExampleSqliteBackend.resource_fields = Mock(
            return_value={u'meta': {}, u'schema': {
                u'a': u'text'
            }}
        )
        records = [
            {u'a': u'x'}, {u'a': u'y'}, {u'a': u'z'},
        ]
        DatastoreBackend.set_active_backend(config)
        res = factories.Resource(url_type=u'datastore')
        helpers.call_action(
            u'datastore_create', resource_id=res['id'],
            fields=[
                {u'id': u'a'}
            ], records=records
        )
        # check, create and 3 inserts
        assert_equal(5, execute.call_count)
        insert_query = u'INSERT INTO "{0}"(a) VALUES(?)'.format(res['id'])
        execute.assert_has_calls(
            [
                call(u' CREATE TABLE IF NOT EXISTS "{0}"(a text);'.format(
                    res['id']
                )),
                call(insert_query, ['x']),
                call(insert_query, ['y']),
                call(insert_query, ['z'])
            ])

        execute.reset_mock()
        fetchall.return_value = records
        helpers.call_action(
            u'datastore_search', resource_id=res['id'])
        execute.assert_called_with(
            u'SELECT * FROM "{0}" LIMIT 10'.format(res['id'])
        )

        execute.reset_mock()
        helpers.call_action(
            u'datastore_delete', resource_id=res['id'])
        # check delete
        execute.assert_called_with(
            u'DROP TABLE IF EXISTS "{0}"'.format(res['id'])
        )

        execute.reset_mock()
        helpers.call_action(
            u'datastore_info', id=res['id'])
        # check
        c = u'''
            select name from sqlite_master
            where type = "table" and name = "{0}"'''.format(res['id'])
        execute.assert_called_with(c)
Ejemplo n.º 2
0
    def update_config(self, config):
        DatastoreBackend.register_backends()
        DatastoreBackend.set_active_backend(config)

        templates_base = config.get('ckan.base_templates_folder')

        p.toolkit.add_template_directory(config, templates_base)
        self.backend = DatastoreBackend.get_active_backend()
Ejemplo n.º 3
0
 def test_sqlite_engine(self):
     DatastoreBackend.set_active_backend(config)
     assert_is_instance(
         DatastoreBackend.get_active_backend(),
         DatastoreExampleSqliteBackend)
Ejemplo n.º 4
0
 def test_sqlite_engine(self):
     DatastoreBackend.set_active_backend(config)
     assert isinstance(
         DatastoreBackend.get_active_backend(),
         DatastoreExampleSqliteBackend,
     )
Ejemplo n.º 5
0
    def test_backend_functionality(self, get_engine):
        engine = get_engine()
        execute = engine.execute
        fetchall = execute().fetchall
        execute.reset_mock()

        DatastoreExampleSqliteBackend.resource_fields = Mock(return_value={
            u'meta': {},
            u'schema': {
                u'a': u'text'
            }
        })
        records = [
            {
                u'a': u'x'
            },
            {
                u'a': u'y'
            },
            {
                u'a': u'z'
            },
        ]
        DatastoreBackend.set_active_backend(config)
        res = factories.Resource(url_type=u'datastore')
        helpers.call_action(u'datastore_create',
                            resource_id=res['id'],
                            fields=[{
                                u'id': u'a'
                            }],
                            records=records)
        # check, create and 3 inserts
        assert_equal(5, execute.call_count)
        insert_query = u'INSERT INTO "{0}"(a) VALUES(?)'.format(res['id'])
        execute.assert_has_calls([
            call(u' CREATE TABLE IF NOT EXISTS "{0}"(a text);'.format(
                res['id'])),
            call(insert_query, ['x']),
            call(insert_query, ['y']),
            call(insert_query, ['z'])
        ])

        execute.reset_mock()
        fetchall.return_value = records
        helpers.call_action(u'datastore_search', resource_id=res['id'])
        execute.assert_called_with(u'SELECT * FROM "{0}" LIMIT 10'.format(
            res['id']))

        execute.reset_mock()
        helpers.call_action(u'datastore_delete', resource_id=res['id'])
        # check delete
        execute.assert_called_with(u'DROP TABLE IF EXISTS "{0}"'.format(
            res['id']))

        execute.reset_mock()
        helpers.call_action(u'datastore_info', id=res['id'])
        # check
        c = u'''
            select name from sqlite_master
            where type = "table" and name = "{0}"'''.format(res['id'])
        execute.assert_called_with(c)
 def test_bigquery_engine(self):
     DatastoreBackend.set_active_backend(config)
     assert_is_instance(DatastoreBackend.get_active_backend(),
                        DatastoreBigQueryBackend)
Ejemplo n.º 7
0
    def test_backend_functionality(self, get_engine):
        engine = get_engine()
        execute = engine.execute
        fetchall = execute().fetchall
        execute.reset_mock()

        DatastoreExampleSqliteBackend.resource_fields = Mock(return_value={
            u"meta": {},
            u"schema": {
                u"a": u"text"
            }
        })
        records = [
            {
                u"a": u"x"
            },
            {
                u"a": u"y"
            },
            {
                u"a": u"z"
            },
        ]
        DatastoreBackend.set_active_backend(config)
        res = factories.Resource(url_type=u"datastore")
        helpers.call_action(
            u"datastore_create",
            resource_id=res["id"],
            fields=[{
                u"id": u"a"
            }],
            records=records,
        )
        # check, create and 3 inserts
        assert 4 == execute.call_count
        insert_query = u'INSERT INTO "{0}"(a) VALUES(?)'.format(res["id"])
        execute.assert_has_calls([
            call(u' CREATE TABLE IF NOT EXISTS "{0}"(a text);'.format(
                res["id"])),
            call(insert_query, ["x"]),
            call(insert_query, ["y"]),
            call(insert_query, ["z"]),
        ])

        execute.reset_mock()
        fetchall.return_value = records
        helpers.call_action(u"datastore_search", resource_id=res["id"])
        execute.assert_called_with(u'SELECT * FROM "{0}" LIMIT 100'.format(
            res["id"]))

        execute.reset_mock()
        helpers.call_action(u"datastore_delete", resource_id=res["id"])
        # check delete
        execute.assert_called_with(u'DROP TABLE IF EXISTS "{0}"'.format(
            res["id"]))

        execute.reset_mock()
        helpers.call_action(u"datastore_info", id=res["id"])
        # check
        c = u'''
            select name from sqlite_master
            where type = "table" and name = "{0}"'''.format(res["id"])
        execute.assert_called_with(c)