Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ celerybeat.pid
# Environments
.env
.venv
.venv38
.venv39
.venv310
.venv311
env/
venv/
ENV/
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

## [Unreleased]
### Added
- OAuth 2.0 Password Grant authentication, by @HardNorth
### Changed
- Client version updated on [5.6.7](https://github.com/reportportal/client-Python/releases/tag/5.6.7), by @HardNorth
### Fixed
- Some configuration parameter names, which are different in the client, by @HardNorth
### Removed
- `RP_UUID` param support, as it was deprecated pretty while ago, by @HardNorth

## [5.6.4]
### Added
- `RP_DEBUG_MODE` configuration variable, by @HardNorth

## [5.6.3]
Expand Down
34 changes: 28 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,40 @@ The latest stable version of library is available on PyPI:
For reporting results to ReportPortal you need to pass some variables
to `robot` run:

REQUIRED:
**Required**:

These variable should be specified in either case:

```
--listener robotframework_reportportal.listener
--variable RP_API_KEY:"your_user_api_key"
--variable RP_ENDPOINT:"your_reportportal_url"
--variable RP_LAUNCH:"launch_name"
--variable RP_PROJECT:"reportportal_project_name"
```

NOT REQUIRED:
And also one type of authorization is required: API Key or OAuth 2.0 Password grant:

```
--variable RP_API_KEY:"your_user_api_key"
- You can get it in the User Profile section on the UI.
```
Or:
```
--variable RP_OAUTH_URI:"https://reportportal.example.com/uat/sso/oauth/token"
- OAuth 2.0 token endpoint URL for password grant authentication. **Required** if API key is not used.
--variable RP_OAUTH_USERNAME:"my_username"
- OAuth 2.0 username for password grant authentication. **Required** if OAuth 2.0 is used.
--variable RP_OAUTH_PASSWORD:"my_password"
- OAuth 2.0 password for password grant authentication. **Required** if OAuth 2.0 is used.
--variable RP_OAUTH_CLIENT_ID:"client_id"
- OAuth 2.0 client identifier. **Required** if OAuth 2.0 is used.
--variable RP_OAUTH_CLIENT_SECRET:"client_id_secret"
- OAuth 2.0 client secret. **Optional** for OAuth 2.0 authentication.
--variable RP_OAUTH_SCOPE:"offline_access"
- OAuth 2.0 access token scope. **Optional** for OAuth 2.0 authentication.
```

**Optional**:

```
--variable RP_CLIENT_TYPE:"SYNC"
Expand All @@ -71,9 +94,8 @@ NOT REQUIRED:
- Default value is "10.0", response read timeout for ReportPortal connection.
--variable RP_LOG_BATCH_SIZE:"10"
- Default value is "20", affects size of async batch log requests
--variable RP_LOG_BATCH_PAYLOAD_SIZE:"10240000"
- Default value is "65000000", maximum payload size of async batch log
requests
--variable RP_LOG_BATCH_PAYLOAD_LIMIT:"10240000"
- Default value is "65000000", maximum payload size of async batch log requests
--variable RP_RERUN:"True"
- Default is "False". Enables rerun mode for the last launch.
--variable RP_RERUN_OF:"xxxxx-xxxx-xxxx-lauch-uuid"
Expand Down
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
pytest
pytest-cov
robotframework-datadriver
black
isort
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Basic dependencies
python-dateutil~=2.9.0.post0
reportportal-client~=5.6.0
reportportal-client~=5.6.7
robotframework
10 changes: 9 additions & 1 deletion robotframework_reportportal/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import os
import re
import uuid
import warnings
from functools import wraps
from mimetypes import guess_type
from typing import Any, Dict, List, Optional, Union
Expand Down Expand Up @@ -299,7 +300,14 @@ def service(self) -> RobotService:
"""Initialize instance of the RobotService."""
if self.variables.enabled and not self._service:
self._service = RobotService()
self._service.init_service(self.variables)
try:
self._service.init_service(self.variables)
except ValueError as e:
# Log warning instead of raising error, since Robot Framework catches all errors
warnings.warn(e.args[0], UserWarning, stacklevel=2)
self.variables.enabled = False
self._service = None
raise e
return self._service

@property
Expand Down
13 changes: 8 additions & 5 deletions robotframework_reportportal/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ def init_service(self, variables: Variables) -> None:
"""
if self.rp is None:
self.debug = variables.debug_mode
logger.debug(
f"ReportPortal - Init service: endpoint={variables.endpoint}, "
f"project={variables.project}, api_key={variables.api_key}"
)
logger.debug(f"ReportPortal - Init service: endpoint={variables.endpoint}, project={variables.project}")

self.rp = create_client(
client_type=variables.client_type,
Expand All @@ -92,11 +89,17 @@ def init_service(self, variables: Variables) -> None:
retries=5,
verify_ssl=variables.verify_ssl,
max_pool_size=variables.pool_size,
log_batch_payload_size=variables.log_batch_payload_size,
log_batch_payload_limit=variables.log_batch_payload_limit,
launch_uuid=variables.launch_id,
launch_uuid_print=variables.launch_uuid_print,
print_output=variables.launch_uuid_print_output,
http_timeout=variables.http_timeout,
oauth_uri=variables.oauth_uri,
oauth_username=variables.oauth_username,
oauth_password=variables.oauth_password,
oauth_client_id=variables.oauth_client_id,
oauth_client_secret=variables.oauth_client_secret,
oauth_scope=variables.oauth_scope,
)

def terminate_service(self) -> None:
Expand Down
64 changes: 41 additions & 23 deletions robotframework_reportportal/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,18 @@ class Variables:
_pabot_pool_id: Optional[int]
_pabot_used: Optional[str]
project: Optional[str]

# API key auth parameter
api_key: Optional[str]

# OAuth 2.0 parameters
oauth_uri: Optional[str]
oauth_username: Optional[str]
oauth_password: Optional[str]
oauth_client_id: Optional[str]
oauth_client_secret: Optional[str]
oauth_scope: Optional[str]

attach_log: bool
attach_report: bool
attach_xunit: bool
Expand All @@ -62,7 +73,7 @@ class Variables:
rerun_of: Optional[str]
test_attributes: List[str]
skipped_issue: bool
log_batch_payload_size: int
log_batch_payload_limit: int
launch_uuid_print: bool
launch_uuid_print_output: Optional[OutputType]
client_type: ClientType
Expand Down Expand Up @@ -92,9 +103,25 @@ def __init__(self) -> None:
self.rerun_of = get_variable("RP_RERUN_OF", default=None)
self.skipped_issue = to_bool(get_variable("RP_SKIPPED_ISSUE", default="True"))
self.test_attributes = get_variable("RP_TEST_ATTRIBUTES", default="").split()
self.log_batch_payload_size = int(
get_variable("RP_LOG_BATCH_PAYLOAD_SIZE", default=str(MAX_LOG_BATCH_PAYLOAD_SIZE))
)

batch_payload_size_limit = get_variable("RP_LOG_BATCH_PAYLOAD_LIMIT", default=None)
batch_payload_size = get_variable("RP_LOG_BATCH_PAYLOAD_SIZE", default=None)
if batch_payload_size:
warn(
"Parameter `RP_LOG_BATCH_PAYLOAD_SIZE` is deprecated since 5.6.5 "
"and will be subject for removing in the next major version. Use `RP_LOG_BATCH_PAYLOAD_LIMIT` argument"
" instead.",
DeprecationWarning,
2,
)
if not batch_payload_size_limit:
batch_payload_size_limit = batch_payload_size

if batch_payload_size_limit:
self.log_batch_payload_limit = int(batch_payload_size_limit)
else:
self.log_batch_payload_limit = MAX_LOG_BATCH_PAYLOAD_SIZE

self.launch_uuid_print = to_bool(get_variable("RP_LAUNCH_UUID_PRINT", default="False"))
output_type = get_variable("RP_LAUNCH_UUID_PRINT_OUTPUT")
self.launch_uuid_print_output = OutputType[output_type.upper()] if output_type else None
Expand All @@ -116,29 +143,20 @@ def __init__(self) -> None:
self.remove_keywords = to_bool(get_variable("RP_REMOVE_KEYWORDS", default="False"))
self.flatten_keywords = to_bool(get_variable("RP_FLATTEN_KEYWORDS", default="False"))

# API key auth parameter
self.api_key = get_variable("RP_API_KEY")
if not self.api_key:
token = get_variable("RP_UUID")
if token:
warn(
message="Argument `RP_UUID` is deprecated since version 5.3.3 and will be subject for "
"removing in the next major version. Use `RP_API_KEY` argument instead.",
category=DeprecationWarning,
stacklevel=2,
)
self.api_key = token
else:
warn(
message="Argument `RP_API_KEY` is `None` or empty string, that's not supposed to happen "
"because ReportPortal is usually requires an authorization key. Please check your"
" configuration.",
category=RuntimeWarning,
stacklevel=2,
)

# OAuth 2.0 parameters
self.oauth_uri = get_variable("RP_OAUTH_URI")
self.oauth_username = get_variable("RP_OAUTH_USERNAME")
self.oauth_password = get_variable("RP_OAUTH_PASSWORD")
self.oauth_client_id = get_variable("RP_OAUTH_CLIENT_ID")
self.oauth_client_secret = get_variable("RP_OAUTH_CLIENT_SECRET")
self.oauth_scope = get_variable("RP_OAUTH_SCOPE")

self.debug_mode = to_bool(get_variable("RP_DEBUG_MODE", default="False"))

cond = (self.endpoint, self.launch_name, self.project, self.api_key)
cond = (self.endpoint, self.launch_name, self.project)
self.enabled = all(cond)
if not self.enabled:
warn(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from setuptools import setup

__version__ = "5.6.4"
__version__ = "5.6.5"


def read_file(fname):
Expand Down
1 change: 0 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@
"""

REPORT_PORTAL_SERVICE = "reportportal_client.RPClient"
REQUESTS_SERVICE = "reportportal_client.client.requests.Session"
Loading
Loading