|
10 | 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11 | 11 | # See the License for the specific language governing permissions and
|
12 | 12 | # limitations under the License
|
| 13 | +import random |
| 14 | +import time |
| 15 | + |
13 | 16 | from reportportal_client import step
|
14 | 17 | from reportportal_client._local import set_current
|
| 18 | +from six.moves import mock |
15 | 19 |
|
16 | 20 | NESTED_STEP_NAME = 'test nested step'
|
17 | 21 | PARENT_STEP_ID = '123-123-1234-123'
|
@@ -149,3 +153,44 @@ def test_verify_parameters_inline_logging(rp_client):
|
149 | 153 | assert len(rp_client._log_manager._logs_batch) == 1
|
150 | 154 | assert rp_client._log_manager._logs_batch[0].message \
|
151 | 155 | == "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 |
0 commit comments