示例#1
0
    def test_get(self):
        init_time = self.init_time
        stop_time = self.stop_time
        start_time = self.start_time
        new_init_time = self.new_init_time

        with self.assertRaises(gDIO.KeyError):
            get()

        init(init_time)

        now_time = datetime.datetime(2011, 1, 1, 0, 0, 0, 0)
        with self.assertRaises(gDIO.CalcSpaceError):
            get(now_time)

        now_time = datetime.datetime(2012, 1, 1, 1, 0, 0, 0)
        expr_seconds = _new()._delta_to_sec(now_time - init_time)
        seconds = get(now_time)
        self.assertEqual(seconds, expr_seconds)

        stop(stop_time)
        now_time = datetime.datetime(2013, 1, 1, 0, 0, 0, 0)
        expr_seconds = _new()._delta_to_sec(stop_time - init_time)
        seconds = get(now_time)
        self.assertEqual(seconds, expr_seconds)

        start(start_time)
        expr_seconds = _new()._delta_to_sec(now_time - new_init_time)
        seconds = get(now_time)
        self.assertEqual(seconds, expr_seconds)
示例#2
0
    def test_to_sec(self):
        init_time = self.init_time
        dt = datetime.datetime(2012, 1, 1, 1, 0, 0, 0)
        expr_sec = _new()._delta_to_sec(dt - init_time)

        init(init_time)
        sec = to_sec(dt)
        self.assertEqual(sec, expr_sec)
示例#3
0
    def test_peer(self):
        init_time = self.init_time
        dt = datetime.datetime(2012, 1, 1, 1, 0, 0, 0)

        init(init_time)
        sec = to_sec(dt)
        expr_dt = to_dt(sec)
        self.assertEqual(dt, expr_dt)
示例#4
0
    def test_to_dt(self):
        init_time = self.init_time
        sec = 3600
        expr_dt = init_time + datetime.timedelta(hours=1)

        init(init_time)
        dt = to_dt(sec)
        self.assertEqual(dt, expr_dt)
示例#5
0
    def handle(self, *args, **options):

        # DEBUG環境のみ許可
        if settings.DEBUG:
            pass
        elif settings.OPENSOCIAL_DEBUG:
            pass
        elif settings.OPENSOCIAL_SANDBOX:
            pass
        else:
            raise CommandError('Cannot execute in production servers.')

        # Redisを初期化
        hr()
        print('---- redis flush start.')
        for redis_name, redis_setting in settings.REDIS_DATABASES.items():
            redis_flush(redis_name, redis_setting)

        print('---- redis flush done.')

        # syncdbでsouth管理以外のテーブル作成
        hr()
        print('---- syncdb command start.')
        # defaultを最初にやらないとcontent_typeエラーがでる
        syncdb('default')
        for database_name in settings.DATABASES.keys():
            if database_name == 'default':
                continue
            syncdb(database_name)

        print('---- syncdb command done.')

        # south管理のテーブル作成
        hr()
        execute('./manage.py migrate_db --settings={SETTINGS}'.format(
            SETTINGS=settings.SETTINGS_MODULE),
                nowait=True)

        # 初期データ読み込み
        gdio.init()
        hr()
        print('---- load_db command start.')
        execute('./manage.py load_db all --settings={SETTINGS}'.format(
            SETTINGS=settings.SETTINGS_MODULE),
                nowait=True)
        print('---- load_db command done.')

        hr()
        print('---- clean_memcached command start.')
        execute('./manage.py clean_memcached --settings={SETTINGS}'.format(
            SETTINGS=settings.SETTINGS_MODULE),
                nowait=True)
        print('---- clean_memcached command done.')
        hr()
示例#6
0
文件: init_db.py 项目: subc/anchovy
    def handle(self, *args, **options):

        # DEBUG環境のみ許可
        if settings.DEBUG:
            pass
        elif settings.OPENSOCIAL_DEBUG:
            pass
        elif settings.OPENSOCIAL_SANDBOX:
            pass
        else:
            raise CommandError('Cannot execute in production servers.')

        # Redisを初期化
        hr()
        print('---- redis flush start.')
        for redis_name, redis_setting in settings.REDIS_DATABASES.items():
            redis_flush(redis_name, redis_setting)

        print('---- redis flush done.')

        # syncdbでsouth管理以外のテーブル作成
        hr()
        print('---- syncdb command start.')
        # defaultを最初にやらないとcontent_typeエラーがでる
        syncdb('default')
        for database_name in settings.DATABASES.keys():
            if database_name == 'default':
                continue
            syncdb(database_name)

        print('---- syncdb command done.')

        # south管理のテーブル作成
        hr()
        execute('./manage.py migrate_db --settings={SETTINGS}'.format(
            SETTINGS=settings.SETTINGS_MODULE), nowait=True)

        # 初期データ読み込み
        gdio.init()
        hr()
        print('---- load_db command start.')
        execute('./manage.py load_db all --settings={SETTINGS}'.format(
            SETTINGS=settings.SETTINGS_MODULE), nowait=True)
        print('---- load_db command done.')

        hr()
        print('---- clean_memcached command start.')
        execute('./manage.py clean_memcached --settings={SETTINGS}'.format(
            SETTINGS=settings.SETTINGS_MODULE), nowait=True)
        print('---- clean_memcached command done.')
        hr()
示例#7
0
    def test_start(self):
        dio = self.dio
        init_time = self.init_time
        stop_time = self.stop_time
        start_time = self.start_time
        new_init_time = self.new_init_time

        with self.assertRaises(gDIO.KeyError):
            start()

        init(init_time)

        with self.assertRaises(gDIO.KeyError):
            start()

        stop(stop_time)
        start(start_time)
        self.assertIsNone(dio._r.get(dio._stop_key()))
        self._assertTime(dio._init_key(), new_init_time)
示例#8
0
    def test_init(self):
        dio = self.dio
        init_time = self.init_time

        init(init_time)
        self._assertTime(dio._init_key(), init_time)