Exemplo n.º 1
0
    def test_copy_data_from(self):
        try:
            tmpdir = tempfile.mkdtemp()

            # create new database
            with testing.redis.RedisServer(base_dir=tmpdir, redis_conf={'save': '900 1'}) as redis:
                r = Redis(**redis.dsn())
                r.set('scott', '1')
                r.set('tiger', '2')

            # create another database from first one
            data_dir = os.path.join(tmpdir, 'data')
            with testing.redis.RedisServer(copy_data_from=data_dir) as redis:
                r = Redis(**redis.dsn())

                self.assertEqual('1', r.get('scott').decode('utf-8'))
                self.assertEqual('2', r.get('tiger').decode('utf-8'))
        finally:
            rmtree(tmpdir)
Exemplo n.º 2
0
    def test_with_redis(self):
        with testing.redis.RedisServer() as redis:
            self.assertIsNotNone(redis)

            # connect to redis
            r = Redis(**redis.dsn())
            self.assertIsNotNone(r)

            self.assertTrue(redis.is_alive())  # process is alive

        self.assertFalse(redis.is_alive())  # process is down
Exemplo n.º 3
0
    def test_with_redis(self):
        with testing.redis.RedisServer() as redis:
            self.assertIsNotNone(redis)

            # connect to redis
            r = Redis(**redis.dsn())
            self.assertIsNotNone(r)

            self.assertTrue(redis.is_alive())  # process is alive

        self.assertFalse(redis.is_alive())  # process is down
Exemplo n.º 4
0
    def test_basic(self):
        # start redis server
        redis = testing.redis.RedisServer()
        self.assertIsNotNone(redis)
        self.assertEqual(redis.dsn(),
                         dict(host='127.0.0.1', port=redis.redis_conf['port'], db=0))

        # connect to redis
        r = Redis(**redis.dsn())
        self.assertIsNotNone(r)

        pid = redis.server_pid
        self.assertTrue(redis.is_alive())

        # shutting down
        redis.stop()
        sleep(1)

        self.assertFalse(redis.is_alive())
        with self.assertRaises(OSError):
            os.kill(pid, 0)  # process is down
Exemplo n.º 5
0
    def test_copy_data_from(self):
        try:
            tmpdir = tempfile.mkdtemp()

            # create new database
            with testing.redis.RedisServer(base_dir=tmpdir,
                                           redis_conf={'save':
                                                       '900 1'}) as redis:
                r = Redis(**redis.dsn())
                r.set('scott', '1')
                r.set('tiger', '2')

            # create another database from first one
            data_dir = os.path.join(tmpdir, 'data')
            with testing.redis.RedisServer(copy_data_from=data_dir) as redis:
                r = Redis(**redis.dsn())

                self.assertEqual('1', r.get('scott').decode('utf-8'))
                self.assertEqual('2', r.get('tiger').decode('utf-8'))
        finally:
            rmtree(tmpdir)
Exemplo n.º 6
0
    def test_basic(self):
        # start redis server
        redis = testing.redis.RedisServer()
        self.assertIsNotNone(redis)
        self.assertEqual(
            redis.dsn(),
            dict(host='127.0.0.1', port=redis.redis_conf['port'], db=0))

        # connect to redis
        r = Redis(**redis.dsn())
        self.assertIsNotNone(r)

        pid = redis.server_pid
        self.assertTrue(redis.is_alive())

        # shutting down
        redis.stop()
        sleep(1)

        self.assertFalse(redis.is_alive())
        with self.assertRaises(OSError):
            os.kill(pid, 0)  # process is down
Exemplo n.º 7
0
    def test_RedisServerFactory_with_initialized_handler(self):
        def handler(redis):
            r = Redis(**redis.dsn())
            r.config_set('save', '900 1')
            r.set('scott', '1')
            r.set('tiger', '2')

        RedisServer = testing.redis.RedisServerFactory(cache_initialized_db=True,
                                                       on_initialized=handler)
        try:
            with RedisServer() as redis:
                r = Redis(**redis.dsn())

                self.assertEqual('1', r.get('scott').decode('utf-8'))
                self.assertEqual('2', r.get('tiger').decode('utf-8'))
        finally:
            RedisServer.clear_cache()
Exemplo n.º 8
0
    def test_RedisServerFactory_with_initialized_handler(self):
        def handler(redis):
            r = Redis(**redis.dsn())
            r.config_set('save', '900 1')
            r.set('scott', '1')
            r.set('tiger', '2')

        RedisServer = testing.redis.RedisServerFactory(
            cache_initialized_db=True, on_initialized=handler)
        try:
            with RedisServer() as redis:
                r = Redis(**redis.dsn())

                self.assertEqual('1', r.get('scott').decode('utf-8'))
                self.assertEqual('2', r.get('tiger').decode('utf-8'))
        finally:
            RedisServer.clear_cache()
Exemplo n.º 9
0
 def handler(redis):
     r = Redis(**redis.dsn())
     r.config_set('save', '900 1')
     r.set('scott', '1')
     r.set('tiger', '2')
Exemplo n.º 10
0
 def handler(redis):
     r = Redis(**redis.dsn())
     r.config_set('save', '900 1')
     r.set('scott', '1')
     r.set('tiger', '2')
Exemplo n.º 11
0
def create_test_suite():
    suite = unittest.TestSuite()
    for imp, modname, _ in pkgutil.walk_packages(__path__):
        mod = imp.find_module(modname).load_module(modname)
        for test in unittest.defaultTestLoader.loadTestsFromModule(mod):
            suite.addTests(test)
    return suite


if __name__ == "__main__":
    exit = 1
    try:
        redis = testing.redis.RedisServer()

        from gengine.base.cache import setup_redis_cache
        dsn = redis.dsn()
        setup_redis_cache(dsn["host"], dsn["port"], dsn["db"])

        from gengine.app.cache import init_caches
        init_caches()

        db.setupDB()
        testSuite = create_test_suite()
        text_runner = unittest.TextTestRunner(failfast=True).run(testSuite)
        if text_runner.wasSuccessful():
            exit = 0
    finally:
        try:
            db.unsetupDB()
        except:
            log.exception()