def setUp(self):
        self.collection = kvlite.open(URI + '.kvlite_test')
        self.collection_name = 'kvlite_test'
        self.manager = MysqlCollectionManager(URI)

        if self.collection_name not in self.manager.collections():
            self.manager.create(self.collection_name)

        collection_class = self.manager.collection_class
        self.collection = collection_class(self.manager, self.collection_name)
Beispiel #2
0
    def test_incorrect_uri_wrong_collection_in_remove(self):

        URI = 'mysql://*****:*****@localhost/kvlite_test'
        collection_name = 'unknown_collection'

        manager = MysqlCollectionManager(URI)
        self.assertRaises(RuntimeError, manager.remove, (collection_name))
Beispiel #3
0
    def test_manager_get_collection(self):

        URI = 'mysql://*****:*****@localhost/test'
        collection = 'kvlite_test'

        manager = MysqlCollectionManager(URI)
        self.assertEqual(manager.collection_class.__name__, 'MysqlCollection')
    def test_parse_url_no_collection(self):

        params = MysqlCollectionManager.parse_uri('mysql://*****:*****@localhost:3307/kvlite_test')
        self.assertEqual(params['backend'], 'mysql')
        self.assertEqual(params['username'], 'kvlite_test')
        self.assertEqual(params['password'], 'eixaaghiequ6ZeiBahn0')
        self.assertEqual(params['host'], 'localhost')
        self.assertEqual(params['port'], 3307)
        self.assertEqual(params['db'], 'kvlite_test')
        self.assertEqual(params['collection'], None)
Beispiel #5
0
    def test_parse_url_no_collection(self):

        params = MysqlCollectionManager.parse_uri('mysql://*****:*****@localhost:3307/kvlite_test')
        self.assertEqual(params['backend'], 'mysql')
        self.assertEqual(params['username'], 'kvlite_test')
        self.assertEqual(params['password'], 'eixaaghiequ6ZeiBahn0')
        self.assertEqual(params['host'], 'localhost')
        self.assertEqual(params['port'], 3307)
        self.assertEqual(params['db'], 'kvlite_test')
        self.assertEqual(params['collection'], None)
    def setUp(self):
        URI = 'mysql://*****:*****@localhost/kvlite_test'

        self.collection_name = 'kvlite_test'
        self.manager = MysqlCollectionManager(URI)
        
        if self.collection_name not in self.manager.collections():
            self.manager.create(self.collection_name)
            
        collection_class = self.manager.collection_class
        self.collection = collection_class(self.manager.connection, self.collection_name)
    def setUp(self):
        self.collection = kvlite.open(URI + '.kvlite_test')
        self.collection_name = 'kvlite_test'
        self.manager = MysqlCollectionManager(URI)

        if self.collection_name not in self.manager.collections():
            self.manager.create(self.collection_name)

        collection_class = self.manager.collection_class
        self.collection = collection_class(
            self.manager, self.collection_name)
    def test_use_different_serializators_for_many(self):
        collection_name = 'diffser'

        manager = MysqlCollectionManager(URI)
        if collection_name not in manager.collections():
            manager.create(collection_name)

        collection_class = manager.collection_class
        collection = collection_class(manager, collection_name,
                                      CompressedJsonSerializer)

        collection.put(u'11', u'diffser1')
        collection.put(u'22', u'diffser2')
        collection.put(u'33', u'diffser3')
        collection.commit()
        collection.close()

        manager = MysqlCollectionManager(URI)
        collection_class = manager.collection_class
        collection = collection_class(manager, collection_name,
                                      cPickleSerializer)
        with self.assertRaises(RuntimeError):
            res = [(k, v) for k, v in collection]

        collection.put(u'11', u'diffser1')
        collection.put(u'22', u'diffser2')
        collection.put(u'open_id_aaaa', u'1111')
        collection.commit()
        collection.close()

        manager = MysqlCollectionManager(URI)
        collection_class = manager.collection_class
        collection = collection_class(manager, collection_name,
                                      CompressedJsonSerializer)

        with self.assertRaises(RuntimeError):
            res = [(k, v) for k, v in collection]
        collection.close()
    def test_use_different_serializators_for_many(self):
        collection_name = 'diffser'

        manager = MysqlCollectionManager(URI)
        if collection_name not in manager.collections():
            manager.create(collection_name)

        collection_class = manager.collection_class
        collection = collection_class(
            manager, collection_name, CompressedJsonSerializer)

        collection.put(u'11', u'diffser1')
        collection.put(u'22', u'diffser2')
        collection.put(u'33', u'diffser3')
        collection.commit()
        collection.close()

        manager = MysqlCollectionManager(URI)
        collection_class = manager.collection_class
        collection = collection_class(
            manager, collection_name, cPickleSerializer)
        with self.assertRaises(RuntimeError):
            res = [(k, v) for k, v in collection]

        collection.put(u'11', u'diffser1')
        collection.put(u'22', u'diffser2')
        collection.put(u'open_id_aaaa', u'1111')
        collection.commit()
        collection.close()

        manager = MysqlCollectionManager(URI)
        collection_class = manager.collection_class
        collection = collection_class(
            manager, collection_name, CompressedJsonSerializer)

        with self.assertRaises(RuntimeError):
            res = [(k, v) for k, v in collection]
        collection.close()
    def test_use_different_serializators_for_many(self):
        URI = 'mysql://*****:*****@localhost/kvlite_test'
        collection_name = 'diffser'

        manager = MysqlCollectionManager(URI)
        if collection_name not in manager.collections():
            manager.create(collection_name)

        collection_class = manager.collection_class
        collection = collection_class(manager.connection, collection_name, CompressedJsonSerializer)
        
        collection.put(u'11', u'diffser1')
        collection.put(u'22', u'diffser2')
        collection.put(u'33', u'diffser3')
        collection.commit()
        collection.close()

        manager = MysqlCollectionManager(URI)
        collection_class = manager.collection_class
        collection = collection_class(manager.connection, collection_name, cPickleSerializer)
        with self.assertRaises(RuntimeError):
            res = [(k,v) for k,v in collection.get()]
        
        collection.put(u'11', u'diffser1')
        collection.put(u'22', u'diffser2')
        collection.put(u'33', u'diffser3')
        collection.commit()
        collection.close()

        manager = MysqlCollectionManager(URI)
        collection_class = manager.collection_class
        collection = collection_class(manager.connection, collection_name, CompressedJsonSerializer)
        
        with self.assertRaises(RuntimeError):
            res = [(k,v) for k,v in collection.get()]
        collection.close()
    def test_manager(self):
        
        URI = 'mysql://*****:*****@localhost/kvlite_test'
        collection = 'kvlite_test'
        
        manager = MysqlCollectionManager(URI)

        if collection in manager.collections():
            manager.remove(collection)
            
        self.assertNotIn(collection, manager.collections())

        manager.create(collection)
        self.assertIn(collection, manager.collections())

        manager.remove(collection)
        self.assertNotIn(collection, manager.collections())

        manager.close()
class KvliteMysqlTests(unittest.TestCase):

    def setUp(self):
        URI = 'mysql://*****:*****@localhost/kvlite_test'

        self.collection_name = 'kvlite_test'
        self.manager = MysqlCollectionManager(URI)
        
        if self.collection_name not in self.manager.collections():
            self.manager.create(self.collection_name)
            
        collection_class = self.manager.collection_class
        self.collection = collection_class(self.manager.connection, self.collection_name)

    def tearDown(self):
        
        if self.collection_name in self.manager.collections():
            self.manager.remove(self.collection_name)
        self.collection.close()
    
    def test_mysql_get_uuid(self):
        
        uuids = [self.collection.get_uuid() for i in range(1000)]
        self.assertEqual(len(set(uuids)), 1000)

    def test_put_get_delete_count_one(self):
        
        k = self.collection.get_uuid()
        v = 'test_put_one'
        self.collection.put(k, v)
        self.assertEqual(self.collection.get(k), (k,v))
        self.assertEqual(self.collection.count, 1)
        self.collection.delete(k)
        self.assertEqual(self.collection.count, 0)
        self.collection.commit()

    def test_put_get_delete_count_many(self):
        
        ks = list()
        for i in xrange(100):
            k = self.collection.get_uuid()
            v = 'test_{}'.format(i)
            self.collection.put(k, v)
            ks.append(k)
        
        kvs = [kv[0] for kv in self.collection.get()]
        self.assertEqual(len(kvs), 100)

        kvs = [kv for kv in self.collection.keys()]
        self.assertEqual(len(kvs), 100)

        self.assertEqual(self.collection.count, 100)
        for k in ks:
            self.collection.delete(k)
        self.assertEqual(self.collection.count, 0)
        self.collection.commit()

    def test_long_key(self):
        
        self.assertRaises(RuntimeError, self.collection.get, '1'*41)
        self.assertRaises(RuntimeError, self.collection.put, '1'*41, 'long_key')
        self.assertRaises(RuntimeError, self.collection.delete, '1'*41)
    
    def test_absent_key(self):
        
        self.assertEqual(self.collection.get(u'a1b2c3'), (None,None))
    
    def test_incorrect_key(self):

        self.assertRaises(RuntimeError, self.collection.get, '12345')
        
    def test_use_different_serializators_for_many(self):
        URI = 'mysql://*****:*****@localhost/kvlite_test'
        collection_name = 'diffser'

        manager = MysqlCollectionManager(URI)
        if collection_name not in manager.collections():
            manager.create(collection_name)

        collection_class = manager.collection_class
        collection = collection_class(manager.connection, collection_name, CompressedJsonSerializer)
        
        collection.put(u'11', u'diffser1')
        collection.put(u'22', u'diffser2')
        collection.put(u'33', u'diffser3')
        collection.commit()
        collection.close()

        manager = MysqlCollectionManager(URI)
        collection_class = manager.collection_class
        collection = collection_class(manager.connection, collection_name, cPickleSerializer)
        with self.assertRaises(RuntimeError):
            res = [(k,v) for k,v in collection.get()]
        
        collection.put(u'11', u'diffser1')
        collection.put(u'22', u'diffser2')
        collection.put(u'33', u'diffser3')
        collection.commit()
        collection.close()

        manager = MysqlCollectionManager(URI)
        collection_class = manager.collection_class
        collection = collection_class(manager.connection, collection_name, CompressedJsonSerializer)
        
        with self.assertRaises(RuntimeError):
            res = [(k,v) for k,v in collection.get()]
        collection.close()
Beispiel #13
0
    def test_manager(self):
        
        URI = 'mysql://*****:*****@localhost/test'
        collection = 'kvlite_test'
        
        manager = MysqlCollectionManager(URI)

        if collection in manager.collections():
            manager.remove(collection)
            
        self.assertNotIn(collection, manager.collections())

        manager.create(collection)
        self.assertIn(collection, manager.collections())

        manager.remove(collection)
        self.assertNotIn(collection, manager.collections())

        manager.close()
class KvliteMysqlTests(unittest.TestCase):
    def setUp(self):
        self.collection = kvlite.open(URI + '.kvlite_test')
        self.collection_name = 'kvlite_test'
        self.manager = MysqlCollectionManager(URI)

        if self.collection_name not in self.manager.collections():
            self.manager.create(self.collection_name)

        collection_class = self.manager.collection_class
        self.collection = collection_class(self.manager, self.collection_name)

    def tearDown(self):

        if self.collection_name in self.manager.collections():
            self.manager.remove(self.collection_name)
        self.collection.close()

    def test_mysql_get_uuid(self):

        uuids = [self.collection.get_uuid() for i in range(1000)]
        self.assertEqual(len(set(uuids)), 1000)

    def test_put_get_delete_count_one(self):

        k = self.collection.get_uuid()
        v = 'test_put_one'
        self.collection.put(k, v)
        self.assertEqual(self.collection.get(k), v)
        self.assertEqual(self.collection.count, 1)
        self.collection.delete(k)
        self.assertEqual(self.collection.count, 0)
        self.collection.commit()

    def test_put_get_delete_count_many(self):

        ks = list()
        for i in xrange(100):
            k = self.collection.get_uuid()
            v = 'test_{}'.format(i)
            self.collection.put(k, v)
            ks.append(k)

        kvs = [kv[0] for kv in self.collection]
        self.assertEqual(len(kvs), 100)

        kvs = [kv for kv in self.collection.keys()]
        self.assertEqual(len(kvs), 100)

        self.assertEqual(self.collection.count, 100)
        for k in ks:
            self.collection.delete(k)
        self.assertEqual(self.collection.count, 0)
        self.collection.commit()

    def test_long_key(self):

        self.assertRaises(RuntimeError, self.collection.get, '1' * 256)
        self.assertRaises(RuntimeError, self.collection.put, '1' * 256,
                          'long_key')
        self.assertRaises(RuntimeError, self.collection.delete, '1' * 256)

    def test_absent_key(self):

        self.assertEqual(self.collection.get(u'a1b2c3'), None)

    def test_use_different_serializators_for_many(self):
        collection_name = 'diffser'

        manager = MysqlCollectionManager(URI)
        if collection_name not in manager.collections():
            manager.create(collection_name)

        collection_class = manager.collection_class
        collection = collection_class(manager, collection_name,
                                      CompressedJsonSerializer)

        collection.put(u'11', u'diffser1')
        collection.put(u'22', u'diffser2')
        collection.put(u'33', u'diffser3')
        collection.commit()
        collection.close()

        manager = MysqlCollectionManager(URI)
        collection_class = manager.collection_class
        collection = collection_class(manager, collection_name,
                                      cPickleSerializer)
        with self.assertRaises(RuntimeError):
            res = [(k, v) for k, v in collection]

        collection.put(u'11', u'diffser1')
        collection.put(u'22', u'diffser2')
        collection.put(u'open_id_aaaa', u'1111')
        collection.commit()
        collection.close()

        manager = MysqlCollectionManager(URI)
        collection_class = manager.collection_class
        collection = collection_class(manager, collection_name,
                                      CompressedJsonSerializer)

        with self.assertRaises(RuntimeError):
            res = [(k, v) for k, v in collection]
        collection.close()