示例#1
0
    def artifactsForTestRunGrid(self):
        testRun = self.testRun

        grid = [["Artifact", "Size"]]

        if testRun.test.testDefinitionSummary.type == "Build":
            for artifact in testRun.test.testDefinitionSummary.artifacts:
                full_name = testRun.test.testDefinitionSummary.name + ("/" + artifact if artifact else "")

                build_key = self.renderer.artifactStorage.sanitizeName(full_name) + ".tar.gz"

                if self.renderer.artifactStorage.build_exists(testRun.test.hash, build_key):
                    grid.append([
                        HtmlGeneration.link(full_name + ".tar.gz", self.renderer.buildDownloadUrl(testRun.test.hash, build_key)),
                        HtmlGeneration.bytesToHumanSize(self.renderer.artifactStorage.build_size(testRun.test.hash, build_key))
                        ])

        for artifactName, sizeInBytes in self.renderer.artifactStorage.testResultKeysForWithSizes(testRun.test.hash, testRun._identity):
            name = self.renderer.artifactStorage.unsanitizeName(artifactName)
            
            if not name.startswith(ArtifactStorage.TEST_LOG_NAME_PREFIX):
                grid.append([
                    HtmlGeneration.link(
                        name,
                        self.renderer.testResultDownloadUrl(testRun._identity, artifactName)
                        ),
                    HtmlGeneration.bytesToHumanSize(sizeInBytes)
                    ])

        if not grid:
            return card("No Test Artifacts produced")

        return HtmlGeneration.grid(grid)
    def renderPageBody(self):
        if self.options.get("context", "") == "dropdown-menu":
            items = []
            for testRun in self.relevantTestRuns():
                for path, sz in self.renderer.artifactStorage.testResultKeysAndSizesForIndividualTest(
                        testRun.test.hash, testRun._identity,
                        self.individualTestName):
                    contents = os.path.basename(
                        path) + " (" + HtmlGeneration.bytesToHumanSize(
                            sz) + ")"
                    if sz:
                        items.append(
                            '<a class="dropdown-item" href="{link}" title="{title}">{contents}</a>'
                            .format(link=self.renderer.testResultDownloadUrl(
                                testRun._identity, path),
                                    title=os.path.basename(path),
                                    contents=contents))
                    else:
                        items.append(
                            '<span class="dropdown-item disabled text-muted">{contents}</span>'
                            .format(contents=contents))
            return "".join(items)
        else:
            grid = [["Test Run", "Failure", "File", "Size"]]

            for testRun in [
                    t for t in self.relevantTestRuns()
                    if not t.canceled and t.endTimestamp
            ]:
                try:
                    index = testRun.testNames.test_names.index(
                        self.individualTestName)
                    passFail = True if testRun.testFailures[index] else False
                except:
                    passFail = None

                if passFail is not None:
                    pathsAndSizes = self.renderer.artifactStorage.testResultKeysAndSizesForIndividualTest(
                        testRun.test.hash, testRun._identity,
                        self.individualTestName)

                    for path, sz in pathsAndSizes:
                        grid.append([
                            self.contextFor(testRun).renderLink(False, False),
                            "OK" if passFail is True else
                            "FAIL" if passFail is False else "",
                            HtmlGeneration.link(
                                os.path.basename(path),
                                self.renderer.testResultDownloadUrl(
                                    testRun._identity, path)),
                            HtmlGeneration.bytesToHumanSize(sz)
                        ])

                    if not pathsAndSizes:
                        grid.append([
                            self.contextFor(testRun).renderLink(False, False),
                            "FAIL" if passFail is True else
                            "OK" if passFail is False else "",
                            '<span class="text-muted">%s</span>' %
                            "No artifacts", ""
                        ])

            return HtmlGeneration.grid(grid, dataTables=True)