Skip to content

Commit af9093a

Browse files
committed
Fix for #180
1 parent e720dc2 commit af9093a

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Changelog
2+
3+
## [Unreleased]
4+
### Fixed
5+
- Issue [#180](https://github.com/reportportal/client-Python/issues/180):
6+
logger crash on attachments, by @HardNorth
7+
8+
## [5.2.0]
9+
### Changed
10+
- Client fixes, by @HardNorth

reportportal_client/core/rp_file.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""This module contains classes representing RP file object."""
22

3+
import uuid
4+
35

46
class RPFile(object):
57
"""Class representation for a file that will be attached to the log."""
@@ -20,7 +22,7 @@ def __init__(self,
2022
"""
2123
self.content = content or data
2224
self.content_type = content_type or mime
23-
self.name = name
25+
self.name = name if name and name.strip() else str(uuid.uuid4())
2426

2527
@property
2628
def payload(self):

reportportal_client/core/rp_requests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def __init__(self, log_reqs):
440440

441441
def __get_file(self, rp_file):
442442
"""Form a tuple for the single file."""
443-
return ('file', (rp_file.name or uuid.uuid4(),
443+
return ('file', (rp_file.name,
444444
rp_file.content,
445445
rp_file.content_type or self.default_content))
446446

tests/logs/test_rp_file.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright (c) 2022 https://reportportal.io .
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# https://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License
13+
14+
import pytest
15+
16+
from core.rp_file import RPFile
17+
18+
19+
@pytest.mark.parametrize(
20+
['name'],
21+
[
22+
[''],
23+
[None],
24+
[' ']
25+
]
26+
)
27+
def test_rp_file_name_should_not_be_empty(name):
28+
file = RPFile(name, '{"test": true}', 'application/json')
29+
30+
payload = file.payload
31+
assert payload['name']
32+
assert len(payload['name']) > 10
33+

0 commit comments

Comments
 (0)