-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
151 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/usr/bin/env python | ||
|
||
import argparse | ||
import io | ||
import os | ||
import sys | ||
import zipfile | ||
|
||
from lxml import etree | ||
import requests | ||
|
||
aparser = argparse.ArgumentParser(description="Upload junit to reportportal") | ||
aparser.add_argument( | ||
"--reportportal", help="URL of reportportal. default: REPORTPORTAL env", default=os.environ.get("REPORTPORTAL") | ||
) | ||
aparser.add_argument( | ||
"--project", | ||
help="reportportal project where to import. default: RP_PROJECT env", | ||
default=os.environ.get("RP_PROJECT"), | ||
) | ||
aparser.add_argument( | ||
"--launch-name", | ||
help="Desired launch name in reportportal. default: RP_LAUNCH_NAME env", | ||
default=os.environ.get("RP_LAUNCH_NAME", os.environ.get("RP_LAUNCH")), | ||
) | ||
aparser.add_argument("--token-variable", help="env variable with auth token. default: RP_TOKEN", default="RP_TOKEN") | ||
aparser.add_argument("junitfile", nargs="+", help="junit file to import") | ||
args = aparser.parse_args() | ||
|
||
if not args.reportportal: | ||
sys.exit("You must define reportportal URL") | ||
if not args.token_variable: | ||
sys.exit("You must define correct token-variable") | ||
|
||
polish = etree.XSLT(etree.parse("./xslt/polish-junit.xsl")) | ||
|
||
stream = io.BytesIO() | ||
|
||
xml = None | ||
with zipfile.ZipFile(stream, mode="w", compression=zipfile.ZIP_DEFLATED) as azip: | ||
for junitfile in args.junitfile: | ||
if zipfile.is_zipfile(junitfile): | ||
with zipfile.ZipFile(junitfile) as inzip: | ||
for file in [i for i in zipfile.Path(inzip, at="archive/").iterdir() if i.name.startswith("junit-")]: | ||
with file.open() as junit: | ||
xml = etree.parse(junit) | ||
content = etree.tostring(polish(xml)) | ||
azip.writestr(file.name, content) | ||
else: | ||
xml = etree.parse(junitfile) | ||
content = etree.tostring(polish(xml)) | ||
azip.writestr(os.path.basename(junitfile), content) | ||
|
||
if not args.launch_name: | ||
try: | ||
args.launch_name = xml.xpath("//property[@name = 'polarion-testrun-title']/@value")[0] | ||
assert args.launch_name | ||
except Exception: | ||
sys.exit("You must define reportportal launch") | ||
|
||
if not args.project: | ||
try: | ||
args.project = xml.xpath("//property[@name = 'project']/@value")[0] | ||
assert args.project | ||
except Exception: | ||
sys.exit("You must define reportportal project") | ||
|
||
token = os.environ[args.token_variable] | ||
reportportal = args.reportportal.rstrip("/") | ||
|
||
auth = {"Authorization": f"Bearer {token}"} | ||
launch_import = f"{reportportal}/api/v1/{args.project}/launch/import" | ||
|
||
print( | ||
requests.post( | ||
launch_import, | ||
files={"file": (f"{args.launch_name}.zip", stream.getbuffer(), "application/zip")}, | ||
headers=auth, | ||
).text | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env python | ||
|
||
import sys | ||
from lxml import etree | ||
|
||
xslt = etree.XSLT(etree.parse(sys.argv[1])) | ||
print(xslt(etree.parse(sys.stdin))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<xsl:stylesheet | ||
version="1.0" | ||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | ||
|
||
<!-- https://source.redhat.com/groups/public/polarion/polarion_wiki/polarion_results_xunit_importer --> | ||
<!-- https://mojo.redhat.com/docs/DOC-1073077 --> | ||
|
||
<xsl:param name="rmfails"/> | ||
<xsl:param name="rmlogs" select="true()"/> | ||
<xsl:param name="polarionProperties"/> | ||
|
||
<xsl:template match="node()|@*"> | ||
<!-- this copies all objects that do not match other template --> | ||
<xsl:copy> | ||
<xsl:apply-templates select="node()|@*"/> | ||
</xsl:copy> | ||
</xsl:template> | ||
|
||
<xsl:template match="/testsuites"> | ||
<xsl:copy> | ||
<xsl:if test="$polarionProperties"> | ||
<xsl:copy-of select="./testsuite/properties"/> | ||
</xsl:if> | ||
<xsl:apply-templates select="node()|@*"/> | ||
</xsl:copy> | ||
</xsl:template> | ||
|
||
<xsl:template match="testcase[skipped]"/> | ||
<xsl:template match="testsuite/@skipped"> | ||
<xsl:attribute name="skipped">0</xsl:attribute> | ||
</xsl:template> | ||
|
||
<xsl:template match="testcase[failure or error]"> | ||
<xsl:if test="not($rmfails)"> | ||
<xsl:copy> | ||
<xsl:apply-templates select="node()|@*"/> | ||
</xsl:copy> | ||
</xsl:if> | ||
</xsl:template> | ||
|
||
<xsl:template match='testcase[not(failure or error)]/*[starts-with(name(), "system-")]/text()'> | ||
<xsl:if test="not($rmlogs)"> | ||
<xsl:copy> | ||
<xsl:apply-templates select="node()|@*"/> | ||
</xsl:copy> | ||
</xsl:if> | ||
</xsl:template> | ||
</xsl:stylesheet> |