当前位置: 首页>>代码示例>>Python>>正文


Python DummyRequest.db_ro_session方法代码示例

本文整理汇总了Python中pyramid.testing.DummyRequest.db_ro_session方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest.db_ro_session方法的具体用法?Python DummyRequest.db_ro_session怎么用?Python DummyRequest.db_ro_session使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyramid.testing.DummyRequest的用法示例。


在下文中一共展示了DummyRequest.db_ro_session方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_leaders

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import db_ro_session [as 别名]
    def test_leaders(self):
        session = self.session
        today = util.utcnow().date()
        yesterday = today - timedelta(days=1)
        for i in range(7, 1, -1):
            user = User(nickname=u'%s' % i)
            session.add(user)
            session.flush()
            score1 = Score(key=ScoreKey.location,
                           userid=user.id, time=today, value=i)
            session.add(score1)
            score2 = Score(key=ScoreKey.location,
                           userid=user.id, time=yesterday, value=i + 1)
            session.add(score2)
        session.commit()
        request = DummyRequest()
        request.db_ro_session = self.session
        request.registry.redis_client = self.redis_client
        inst = self._make_view(request)
        result = inst.leaders_view()
        self.assertEqual(
            result['leaders1'],
            [{'anchor': u'7', 'nickname': u'7', 'num': 15, 'pos': 1},
             {'anchor': u'6', 'nickname': u'6', 'num': 13, 'pos': 2}])
        self.assertEqual(
            result['leaders2'],
            [{'anchor': u'5', 'nickname': u'5', 'num': 11, 'pos': 3}])

        # call the view again, without a working db session, so
        # we can be sure to use the cached result
        inst = self._make_view(request)
        request.db_ro_session = None
        second_result = inst.leaders_view()
        self.assertEqual(second_result, result)
开发者ID:voolitels,项目名称:ichnaea,代码行数:36,代码来源:test_views.py

示例2: test_leaders_weekly

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import db_ro_session [as 别名]
    def test_leaders_weekly(self):
        session = self.session
        today = util.utcnow().date()
        for i in range(3):
            user = User(nickname=u'%s' % i)
            session.add(user)
            session.flush()
            score1 = Score(key=ScoreKey.new_cell,
                           userid=user.id, time=today, value=i)
            session.add(score1)
            score2 = Score(key=ScoreKey.new_wifi,
                           userid=user.id, time=today, value=i)
            session.add(score2)
        session.commit()
        request = DummyRequest()
        request.db_ro_session = self.session
        request.registry.redis_client = self.redis_client
        inst = self._make_view(request)
        result = inst.leaders_weekly_view()
        for score_name in ('new_cell', 'new_wifi'):
            self.assertEqual(
                result['scores'][score_name]['leaders1'],
                [{'nickname': u'2', 'num': 2, 'pos': 1},
                 {'nickname': u'1', 'num': 1, 'pos': 2}])
            self.assertEqual(
                result['scores'][score_name]['leaders2'],
                [{'nickname': u'0', 'num': 0, 'pos': 3}])

        # call the view again, without a working db session, so
        # we can be sure to use the cached result
        inst = self._make_view(request)
        request.db_ro_session = None
        second_result = inst.leaders_weekly_view()
        self.assertEqual(second_result, result)
开发者ID:voolitels,项目名称:ichnaea,代码行数:36,代码来源:test_views.py

示例3: test_stats_regions

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import db_ro_session [as 别名]
    def test_stats_regions(self):
        request = DummyRequest()
        request.db_ro_session = self.session
        request.registry.redis_client = self.redis_client
        inst = self._make_view(request)
        result = inst.stats_regions_view()
        self.assertEqual(result['page_title'], 'Region Statistics')

        # call the view again, without a working db session, so
        # we can be sure to use the cached result
        inst = self._make_view(request)
        request.db_ro_session = None
        second_result = inst.stats_regions_view()
        self.assertEqual(second_result, result)
开发者ID:voolitels,项目名称:ichnaea,代码行数:16,代码来源:test_views.py

示例4: test_stats

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import db_ro_session [as 别名]
    def test_stats(self):
        day = util.utcnow().date() - timedelta(1)
        stats = [
            Stat(key=StatKey.blue, time=day, value=2200000),
            Stat(key=StatKey.cell, time=day, value=2000000),
            Stat(key=StatKey.wifi, time=day, value=2000000),
            Stat(key=StatKey.unique_blue, time=day, value=1500000),
            Stat(key=StatKey.unique_cell, time=day, value=1000000),
            Stat(key=StatKey.unique_cell_ocid, time=day, value=1500000),
            Stat(key=StatKey.unique_wifi, time=day, value=2000000),
        ]
        self.session.add_all(stats)
        self.session.commit()
        request = DummyRequest()
        request.db_ro_session = self.session
        request.registry.redis_client = self.redis_client
        inst = self._make_view(request)
        result = inst.stats_view()
        self.assertEqual(result['page_title'], 'Statistics')
        self.assertEqual(
            result['metrics1'], [
                {'name': 'Bluetooth Networks', 'value': '1.50'},
                {'name': 'Bluetooth Observations', 'value': '2.20'},
                {'name': 'Wifi Networks', 'value': '2.00'},
                {'name': 'Wifi Observations', 'value': '2.00'},
            ])
        self.assertEqual(
            result['metrics2'], [
                {'name': 'MLS Cells', 'value': '1.00'},
                {'name': 'MLS Cell Observations', 'value': '2.00'},
                {'name': 'OpenCellID Cells', 'value': '1.50'},
            ])

        # call the view again, without a working db session, so
        # we can be sure to use the cached result
        inst = self._make_view(request)
        request.db_ro_session = None
        second_result = inst.stats_view()
        self.assertEqual(second_result, result)
开发者ID:amolk4games,项目名称:ichnaea,代码行数:41,代码来源:test_views.py


注:本文中的pyramid.testing.DummyRequest.db_ro_session方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。