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


Python Test.cacheKey方法代码示例

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


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

示例1: get

# 需要导入模块: from models import Test [as 别名]
# 或者: from models.Test import cacheKey [as 别名]
    def get(self):
        self.response.headers['Content-Type'] = 'application/json; charset=utf-8'

        try:
            testId = int(self.request.get('id', 0))
            branchId = int(self.request.get('branchid', 0))
            platformId = int(self.request.get('platformid', 0))
        except TypeError:
            # FIXME: Output an error here
            testId = 0
            branchId = 0
            platformId = 0

        # FIXME: Just fetch builds specified by "days"
        # days = self.request.get('days', 365)

        cacheKey = Test.cacheKey(testId, branchId, platformId)
        cache = memcache.get(cacheKey)
        if cache:
            self.response.out.write(cache)
            return

        builds = Build.all()
        builds.filter('branch =', modelFromNumericId(branchId, Branch))
        builds.filter('platform =', modelFromNumericId(platformId, Platform))

        test = modelFromNumericId(testId, Test)
        testName = test.name if test else None
        test_runs = []
        averages = {}
        values = []
        timestamps = []

        for build in builds:
            results = TestResult.all()
            results.filter('name =', testName)
            results.filter('build =', build)
            for result in results:
                builderId = build.builder.key().id()
                posixTimestamp = mktime(build.timestamp.timetuple())
                test_runs.append([result.key().id(),
                    [build.key().id(), build.buildNumber, build.revision],
                    posixTimestamp, result.value, 0, [], builderId])
                # FIXME: Calculate the average; in practice, we wouldn't have more than one value for a given revision
                averages[build.revision] = result.value
                values.append(result.value)
                timestamps.append(posixTimestamp)

        result = json.dumps({
            'test_runs': test_runs,
            'averages': averages,
            'min': min(values) if values else None,
            'max': max(values) if values else None,
            'date_range': [min(timestamps), max(timestamps)] if timestamps else None,
            'stat': 'ok'})
        self.response.out.write(result)
        memcache.add(cacheKey, result)
开发者ID:,项目名称:,代码行数:59,代码来源:

示例2: post

# 需要导入模块: from models import Test [as 别名]
# 或者: from models.Test import cacheKey [as 别名]
    def post(self):
        self.response.headers['Content-Type'] = 'text/plain; charset=utf-8'

        headers = "\n".join([key + ': ' + value for key, value in self.request.headers.items()])

        # Do as best as we can to remove the password
        request_body_without_password = re.sub(r'"password"\s*:\s*".+?",', '', self.request.body)
        log = ReportLog(timestamp=datetime.now(), headers=headers, payload=request_body_without_password)
        log.put()

        try:
            self._body = json.loads(self.request.body)
        except ValueError:
            return self._output('Failed to parse the payload as a json. Report key: %d' % log.key().id())

        builder = self._modelByKeyNameInBodyOrError(Builder, 'builder-name')
        branch = self._modelByKeyNameInBodyOrError(Branch, 'branch')
        platform = self._modelByKeyNameInBodyOrError(Platform, 'platform')
        buildNumber = self._integerInBody('build-number')
        revision = self._integerInBody('revision')
        timestamp = self._timestampInBody()

        failed = False
        if builder and not (self.bypassAuthentication() or builder.authenticate(self._body.get('password', ''))):
            self._output('Authentication failed')
            failed = True

        if not self._resultsAreValid():
            self._output("The payload doesn't contain results or results are malformed")
            failed = True

        if not (builder and branch and platform and buildNumber and revision and timestamp) or failed:
            return

        build = self._createBuildIfPossible(builder, buildNumber, branch, platform, revision, timestamp)
        if not build:
            return

        for testName, result in self._body['results'].iteritems():
            test = self._addTestIfNeeded(testName, branch, platform)
            memcache.delete(Test.cacheKey(test.id, branch.id, platform.id))
            if isinstance(result, dict):
                TestResult(name=testName, build=build, value=float(result.get('avg', 0)), valueMedian=float(result.get('median', 0)),
                    valueStdev=float(result.get('stdev', 0)), valueMin=float(result.get('min', 0)), valueMax=float(result.get('max', 0))).put()
            else:
                TestResult(name=testName, build=build, value=float(result)).put()

        log = ReportLog.get(log.key())
        log.delete()

        # We need to update dashboard and manifest because they are affected by the existance of test results
        memcache.delete('dashboard')
        memcache.delete('manifest')

        return self._output('OK')
开发者ID:,项目名称:,代码行数:57,代码来源:


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