66import logging
77import requests
88import six
9+ import os
910from typing import TYPE_CHECKING
1011import urllib .parse as url_parse
1112
1920from azure_devtools .scenario_tests .utilities import trim_kwargs_from_test_function
2021from .config import PROXY_URL
2122from .helpers import get_test_id , is_live , is_live_and_not_recording , set_recording_id
23+ from .proxy_startup import discovered_roots
2224
2325if TYPE_CHECKING :
2426 from typing import Callable , Dict , Tuple
3436PLAYBACK_START_URL = "{}/playback/start" .format (PROXY_URL )
3537PLAYBACK_STOP_URL = "{}/playback/stop" .format (PROXY_URL )
3638
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
3759
3860def start_record_or_playback (test_id : str ) -> "Tuple[str, Dict[str, str]]" :
3961 """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]]":
4264 test variables to values. If no variable dictionary was stored when the test was recorded, b is an empty dictionary.
4365 """
4466 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
4572
4673 if is_live ():
4774 result = requests .post (
4875 RECORDING_START_URL ,
49- json = { "x-recording-file" : test_id } ,
76+ json = json_payload ,
5077 )
5178 if result .status_code != 200 :
5279 message = six .ensure_str (result ._content )
@@ -56,7 +83,7 @@ def start_record_or_playback(test_id: str) -> "Tuple[str, Dict[str, str]]":
5683 else :
5784 result = requests .post (
5885 PLAYBACK_START_URL ,
59- json = { "x-recording-file" : test_id } ,
86+ json = json_payload ,
6087 )
6188 if result .status_code != 200 :
6289 message = six .ensure_str (result ._content )
0 commit comments