@@ -38,59 +38,97 @@ def test_post_live_metrics_skip_on_schema_error(caplog, monkeypatch):
3838
3939
4040def test_post_live_metrics_start_event (mocker , monkeypatch ):
41- monkeypatch .setenv (DVC_STUDIO_URL , "https://0.0.0.0" )
42- monkeypatch .setenv (DVC_STUDIO_TOKEN , "FOO_TOKEN" )
43- monkeypatch .setenv (STUDIO_REPO_URL , "FOO_REPO_URL" )
41+ repo_url = "FOO_REPO_URL"
42+ studio_url = "https://0.0.0.0"
43+ studio_token = "FOO_TOKEN"
44+ baseline_sha = "f" * 40
45+ event_type = "start"
46+ name = "fooname"
47+ client = "fooclient"
48+
49+ post_url = f"{ studio_url } /api/live"
50+ headers = {
51+ "Authorization" : f"token { studio_token } " ,
52+ "Content-type" : "application/json" ,
53+ }
54+ base_event = {
55+ "type" : "start" ,
56+ "repo_url" : "FOO_REPO_URL" ,
57+ "baseline_sha" : baseline_sha ,
58+ "name" : name ,
59+ "client" : client ,
60+ }
61+
62+ monkeypatch .setenv (DVC_STUDIO_URL , studio_url )
63+ monkeypatch .setenv (DVC_STUDIO_TOKEN , studio_token )
64+ monkeypatch .setenv (STUDIO_REPO_URL , repo_url )
4465
4566 mocked_response = mocker .MagicMock ()
4667 mocked_response .status_code = 200
4768 mocked_post = mocker .patch ("requests.post" , return_value = mocked_response )
4869
4970 assert post_live_metrics (
50- "start" ,
51- "f" * 40 ,
52- "fooname" ,
53- "fooclient" ,
71+ event_type ,
72+ baseline_sha ,
73+ name ,
74+ client ,
5475 )
5576
5677 mocked_post .assert_called_with (
57- "https://0.0.0.0/api/live" ,
58- json = {
59- "type" : "start" ,
60- "repo_url" : "FOO_REPO_URL" ,
61- "baseline_sha" : "f" * 40 ,
62- "name" : "fooname" ,
63- "client" : "fooclient" ,
64- },
65- headers = {
66- "Authorization" : "token FOO_TOKEN" ,
67- "Content-type" : "application/json" ,
68- },
78+ post_url ,
79+ json = base_event ,
80+ headers = headers ,
6981 timeout = (30 , 5 ),
7082 )
7183
7284 post_live_metrics (
73- "start" ,
74- "f" * 40 ,
75- "fooname" ,
76- "fooclient" ,
85+ event_type ,
86+ baseline_sha ,
87+ name ,
88+ client ,
7789 params = {"params.yaml" : {"foo" : "bar" }},
7890 )
7991
8092 mocked_post .assert_called_with (
81- "https://0.0.0.0/api/live" ,
93+ post_url ,
8294 json = {
83- "type" : "start" ,
84- "repo_url" : "FOO_REPO_URL" ,
85- "baseline_sha" : "f" * 40 ,
86- "name" : "fooname" ,
87- "client" : "fooclient" ,
95+ ** base_event ,
8896 "params" : {"params.yaml" : {"foo" : "bar" }},
8997 },
90- headers = {
91- "Authorization" : "token FOO_TOKEN" ,
92- "Content-type" : "application/json" ,
98+ headers = headers ,
99+ timeout = (30 , 5 ),
100+ )
101+
102+ dvc_experiment_parent_data = {
103+ "sha" : baseline_sha ,
104+ "message" : "test message" ,
105+ "title" : "test message" ,
106+ "author" : {
107+ "name" : "Monrepo user" ,
108+ "email" : "overcomplicated@iLoveMonorepos.com" ,
109+ },
110+ "date" : "2021-09-01T12:00:00+00:00" ,
111+ "branch" : "main" ,
112+ }
113+ subdir = "subdir"
114+
115+ assert post_live_metrics (
116+ "start" ,
117+ baseline_sha ,
118+ name ,
119+ client ,
120+ dvc_experiment_parent_data = dvc_experiment_parent_data ,
121+ subdir = subdir ,
122+ )
123+
124+ mocked_post .assert_called_with (
125+ post_url ,
126+ json = {
127+ ** base_event ,
128+ "dvc_experiment_parent_data" : dvc_experiment_parent_data ,
129+ "subdir" : subdir ,
93130 },
131+ headers = headers ,
94132 timeout = (30 , 5 ),
95133 )
96134
0 commit comments