Skip to content

Commit

Permalink
Merge pull request #8 from krasoffski/readme
Browse files Browse the repository at this point in the history
Add more complex example usage to readme file.
  • Loading branch information
Alexander.Iljushkin authored May 14, 2017
2 parents 21bffd0 + 64c2b53 commit f4171a8
Showing 1 changed file with 87 additions and 21 deletions.
108 changes: 87 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
# ReportPortal python client
# ReportPortal python client

[![PyPI](https://img.shields.io/pypi/v/reportportal-client.svg?maxAge=2592000)](https://pypi.python.org/pypi/reportportal-client)
[![Build Status](https://travis-ci.org/reportportal/client-Python.svg?branch=master)](https://travis-ci.org/reportportal/client-Python)

Library used only for implementors of custom listeners for ReportPortal


## Allready implemented listeners:
* [Robot Framework](https://github.com/reportportal/agent-Python-RobotFramework)

- [Robot Framework](https://github.com/reportportal/agent-Python-RobotFramework)
- [PyTest Framework](https://github.com/reportportal/agent-python-pytest)


## Installation

The latest stable version is available on PyPI:

pip install reportportal-client
```
pip install reportportal-client
```


## Usage
Expand All @@ -30,38 +35,99 @@ Main classes are:
Basic usage example:

```python
import os
import subprocess
from time import time
from reportportal_client import (ReportPortalService,
from mimetypes import guess_type

from reportportal_client import (ReportPortalService,
FinishExecutionRQ,
StartLaunchRQ, StartTestItemRQ,
FinishTestItemRQ, SaveLogRQ)


def timestamp():
return str(int(time() * 1000))

endpoint = "https://urlpreportportal"
project = "ProjectName"
token = "uuid" #you can get it from profile page in ReportPortal
launch_name = "name for launch"
launch_doc = "Some text documentation for launch"

service = ReportPortalService(endpoint=endpoint,
project=project,
token=token)
endpoint = "http://10.6.40.6:8080"
project = "default"
# You can get UUID from user profile page in the Report Portal.
token = "1adf271d-505f-44a8-ad71-0afbdf8c83bd"
launch_name = "Test launch"
launch_doc = "Testing logging with attachment."

service = ReportPortalService(endpoint=endpoint, project=project, token=token)

#Start Launch
# Create start launch request.
sl_rq = StartLaunchRQ(name=launch_name,
start_time=timestamp(),
description=launch_doc)
r = service.start_launch(sl_rq)
launch_id = r.id

#Finish Launch
fl_rq = FinishExecutionRQ(end_time=timestamp(),
status="PASSED")
service.finish_launch(launch_id, fl_rq)
description=launch_doc)

# Start launch.
launch = service.start_launch(sl_rq)

# Create start test item request.
sti_rq = StartTestItemRQ(name="Test Case",
description="First Test Case",
tags=["Image", "Smoke"],
start_time=timestamp(),
launch_id=launch.id,
type="TEST")

# Start test item.
test = service.start_test_item(parent_item_id=None, start_test_item_rq=sti_rq)

# Create text log message with INFO level.
service.log(SaveLogRQ(item_id=test.id,
time=timestamp(),
message="Hello World!",
level="INFO"))

# Create log message with attached text output and WARN level.
service.attach(SaveLogRQ(item_id=test.id,
time=timestamp(),
message="Too high memory usage!",
level="WARN"),
name="free_memory.txt",
data=subprocess.check_output("free -h".split()))

# Create log message with piped binary file, INFO level and custom mimetype.
image = "/tmp/image.png"
sl_rq = SaveLogRQ(test.id, timestamp(), "Screen shot of issue.", "INFO")
with open(image, "rb") as fh:
service.attach(save_log_rq=sl_rq,
name=os.path.basename(image),
data=fh,
mime=guess_type(image)[0] or "application/octet-stream")

# Create log message with binary data and INFO level.
filebin = "/tmp/file.bin"
with open(filebin, "rb") as fd:
bindata = fd.read()
# Note here that we pass binary data instead of file handle.
service.attach(SaveLogRQ(item_id=test.id,
time=timestamp(),
message="Binary data file.",
level="INFO"),
name="file.bin",
data=bindata,
mime="application/octet-stream")

# Create finish test item request.
fti_rq = FinishTestItemRQ(end_time=timestamp(), status="PASSED")

# Finish test item.
service.finish_test_item(item_id=test.id, finish_test_item_rq=fti_rq)

# Create finish launch request.
fl_rq = FinishExecutionRQ(end_time=timestamp(), status="PASSED")
# Finish launch.
service.finish_launch(launch.id, fl_rq)
```


# Copyright Notice

Licensed under the [GPLv3](https://www.gnu.org/licenses/quick-guide-gplv3.html)
license (see the LICENSE.txt file).

0 comments on commit f4171a8

Please sign in to comment.