예제 #1
0
    def test_shard(self):
        # Use a configuration with sharding enabled.
        config = get_test_configurator(__file__, 'tests-shard.ini')
        storage = load_and_register("storage", config)

        # Make sure it's using the expected table name.
        table = storage.dbconnector.get_bso_table(_USER['uid']).name
        self.assertEqual(table, 'bso1')

        # The table should initially be empty.
        COUNT_ITEMS = 'select count(*) from bso1 /* queryName=COUNT_ITEMS */'
        with storage.dbconnector.connect() as c:
            res = c.execute(COUNT_ITEMS)
            self.assertEqual(res.fetchall()[0][0], 0)

        # Do a few things on the DB
        id1 = 'ec1b7457-003a-45a9-bf1c-c34e37225ad7'
        id2 = '339f52e1-deed-497c-837a-1ab25a655e37'
        storage.set_item(_USER, 'xxx_col1', id1, {'payload': _PLD})
        storage.set_item(_USER, 'xxx_col1', id2, {'payload': _PLD * 89})
        self.assertEquals(
            len(storage.get_items(_USER, 'xxx_col1')["items"]), 2)

        # Now make sure we did that in the right table
        with storage.dbconnector.connect() as c:
            res = c.execute(COUNT_ITEMS)
            self.assertEqual(res.fetchall()[0][0], 2)
예제 #2
0
    def test_shard(self):
        # Use a configuration with sharding enabled.
        config = get_test_configurator(__file__, 'tests-shard.ini')
        storage = load_and_register("storage", config)

        # Make sure it's using the expected table name.
        table = storage.dbconnector.get_bso_table(_UID).name
        self.assertEqual(table, 'bso1')

        # The table should initially be empty.
        COUNT_ITEMS = 'select count(*) from bso1 /* queryName=COUNT_ITEMS */'
        with storage.dbconnector.connect() as c:
            res = c.execute(COUNT_ITEMS)
            self.assertEqual(res.fetchall()[0][0], 0)

        # Do a few things on the DB
        id1 = 'ec1b7457-003a-45a9-bf1c-c34e37225ad7'
        id2 = '339f52e1-deed-497c-837a-1ab25a655e37'
        storage.set_item(_UID, 'col1', id1, {'payload': _PLD})
        storage.set_item(_UID, 'col1', id2, {'payload': _PLD * 89})
        self.assertEquals(len(storage.get_items(_UID, 'col1')["items"]), 2)

        # Now make sure we did that in the right table
        with storage.dbconnector.connect() as c:
            res = c.execute(COUNT_ITEMS)
            self.assertEqual(res.fetchall()[0][0], 2)
예제 #3
0
 def test_nopool_is_disabled_when_using_memory_database(self):
     config = get_test_configurator(__file__, "tests-nopool.ini")
     # Using no_pool=True will give you a NullPool when using file db.
     storage = load_and_register("storage-file", config)
     self.assertEqual(storage.dbconnector.engine.pool.__class__.__name__, "NullPool")
     # Using no_pool=True will give you an error when using :memory: db.
     self.assertRaises(ValueError, load_and_register, "storage-memory", config)
예제 #4
0
 def test_nopool_is_disabled_when_using_memory_database(self):
     config = get_test_configurator(__file__, 'tests-nopool.ini')
     # Using no_pool=True will give you a NullPool when using file db.
     storage = load_and_register("storage-file", config)
     self.assertEqual(storage.dbconnector.engine.pool.__class__.__name__,
                      'NullPool')
     # Using no_pool=True will give you an error when using :memory: db.
     self.assertRaises(ValueError,
                       load_and_register, "storage-memory", config)
예제 #5
0
    def test_no_create(self):
        # Storage with no create_tables option; it should default to false.
        # This should fail because the table is absent
        config = get_test_configurator(__file__, 'tests-nocreate.ini')
        storage = load_and_register("storage", config)
        bsos = [{"id": "TEST", "payload": _PLD}]
        self.assertRaises(BackendError, storage.set_items, _USER, "test", bsos)

        # Storage with create_tables explicitly set to false.
        # This should fail because the table is absent
        config = get_test_configurator(__file__, 'tests-dontcreate.ini')
        storage = load_and_register("storage", config)
        self.assertRaises(BackendError, storage.set_items, _USER, "test", bsos)

        # Storage with create_tables explicit set to true.
        # This should succeed because the table gets created.
        config = get_test_configurator(__file__, 'tests-docreate.ini')
        storage = load_and_register("storage", config)
        storage.set_items(_USER, "test", bsos)
예제 #6
0
    def test_no_create(self):
        # Storage with no create_tables option; it should default to false.
        # This should fail because the table is absent
        config = get_test_configurator(__file__, 'tests-nocreate.ini')
        storage = load_and_register("storage", config)
        bsos = [{"id": "TEST", "payload": _PLD}]
        self.assertRaises(BackendError, storage.set_items, _UID, "test", bsos)

        # Storage with create_tables explicitly set to false.
        # This should fail because the table is absent
        config = get_test_configurator(__file__, 'tests-dontcreate.ini')
        storage = load_and_register("storage", config)
        self.assertRaises(BackendError, storage.set_items, _UID, "test", bsos)

        # Storage with create_tables explicit set to true.
        # This should succeed because the table gets created.
        config = get_test_configurator(__file__, 'tests-docreate.ini')
        storage = load_and_register("storage", config)
        storage.set_items(_UID, "test", bsos)