Skip to content

Commit ac03ae6

Browse files
committed
More nested step tests
1 parent 7f411b3 commit ac03ae6

File tree

2 files changed

+45
-31
lines changed

2 files changed

+45
-31
lines changed

tests/steps/test_steps.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License
13+
import random
14+
import time
15+
1316
from reportportal_client import step
1417
from reportportal_client._local import set_current
18+
from six.moves import mock
1519

1620
NESTED_STEP_NAME = 'test nested step'
1721
PARENT_STEP_ID = '123-123-1234-123'
@@ -149,3 +153,44 @@ def test_verify_parameters_inline_logging(rp_client):
149153
assert len(rp_client._log_manager._logs_batch) == 1
150154
assert rp_client._log_manager._logs_batch[0].message \
151155
== "Parameters: param1: 1; param2: two"
156+
157+
158+
def item_id_gen(*args, **kwargs):
159+
item_id = 'post-{}-{}'.format(
160+
str(round(time.time() * 1000)),
161+
random.randint(0, 9999))
162+
result = mock.Mock()
163+
result.text = '{{"id": "{}"}}'.format(item_id)
164+
result.json = lambda: {'id': item_id}
165+
return result
166+
167+
168+
@step
169+
def parent_nested_step():
170+
nested_step()
171+
172+
173+
def test_two_level_nested_step_decorator(rp_client):
174+
rp_client.step_reporter.set_parent('STEP', PARENT_STEP_ID)
175+
rp_client.session.post.side_effect = item_id_gen
176+
parent_nested_step()
177+
178+
assert rp_client.session.post.call_count == 2
179+
assert rp_client.session.put.call_count == 2
180+
assert len(rp_client._log_manager._logs_batch) == 0
181+
182+
request_uri = rp_client.session.post.call_args_list[0][0][0]
183+
first_parent_id = request_uri[request_uri.rindex('/') + 1:]
184+
request_uri = rp_client.session.post.call_args_list[1][0][0]
185+
second_parent_id = request_uri[request_uri.rindex('/') + 1:]
186+
187+
request_uri = rp_client.session.put.call_args_list[0][0][0]
188+
first_id = request_uri[request_uri.rindex('/') + 1:]
189+
request_uri = rp_client.session.put.call_args_list[1][0][0]
190+
second_id = request_uri[request_uri.rindex('/') + 1:]
191+
192+
assert first_parent_id == PARENT_STEP_ID
193+
assert second_parent_id.startswith('post-')
194+
assert first_id.startswith('post-')
195+
assert second_id.startswith('post-')
196+
assert first_id != second_id

tests/test_nested.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)