6
6
import logging
7
7
import requests
8
8
import six
9
+ import os
9
10
from typing import TYPE_CHECKING
10
11
import urllib .parse as url_parse
11
12
19
20
from azure_devtools .scenario_tests .utilities import trim_kwargs_from_test_function
20
21
from .config import PROXY_URL
21
22
from .helpers import get_test_id , is_live , is_live_and_not_recording , set_recording_id
23
+ from .proxy_startup import discovered_roots
22
24
23
25
if TYPE_CHECKING :
24
26
from typing import Callable , Dict , Tuple
34
36
PLAYBACK_START_URL = "{}/playback/start" .format (PROXY_URL )
35
37
PLAYBACK_STOP_URL = "{}/playback/stop" .format (PROXY_URL )
36
38
39
+ def get_recording_assets (test_id : str ) -> str :
40
+ """
41
+ Used to retrieve the assets.json given a PYTEST_CURRENT_TEST test id.
42
+ """
43
+ for root in discovered_roots :
44
+ current_dir = os .path .dirname (test_id )
45
+ while current_dir is not None and not (os .path .dirname (current_dir ) == current_dir ):
46
+ possible_assets = os .path .join (current_dir , "assets.json" )
47
+ possible_root = os .path .join (current_dir , ".git" )
48
+
49
+ # we need to check for assets.json first!
50
+ if os .path .exists (os .path .join (root , possible_assets )):
51
+ return os .path .abspath (os .path .join (root , possible_assets ))
52
+ # we need the git check to prevent ascending out of the repo
53
+ elif os .path .exists (os .path .join (root , possible_root )):
54
+ return None
55
+ else :
56
+ current_dir = os .path .dirname (current_dir )
57
+
58
+ return None
37
59
38
60
def start_record_or_playback (test_id : str ) -> "Tuple[str, Dict[str, str]]" :
39
61
"""Sends a request to begin recording or playing back the provided test.
@@ -42,11 +64,16 @@ def start_record_or_playback(test_id: str) -> "Tuple[str, Dict[str, str]]":
42
64
test variables to values. If no variable dictionary was stored when the test was recorded, b is an empty dictionary.
43
65
"""
44
66
variables = {} # this stores a dictionary of test variable values that could have been stored with a recording
67
+
68
+ json_payload = {"x-recording-file" : test_id }
69
+ assets_json = get_recording_assets (test_id )
70
+ if assets_json :
71
+ json_payload ["x-recording-assets-file" ] = assets_json
45
72
46
73
if is_live ():
47
74
result = requests .post (
48
75
RECORDING_START_URL ,
49
- json = { "x-recording-file" : test_id } ,
76
+ json = json_payload ,
50
77
)
51
78
if result .status_code != 200 :
52
79
message = six .ensure_str (result ._content )
@@ -56,7 +83,7 @@ def start_record_or_playback(test_id: str) -> "Tuple[str, Dict[str, str]]":
56
83
else :
57
84
result = requests .post (
58
85
PLAYBACK_START_URL ,
59
- json = { "x-recording-file" : test_id } ,
86
+ json = json_payload ,
60
87
)
61
88
if result .status_code != 200 :
62
89
message = six .ensure_str (result ._content )
0 commit comments