3737PIPELINE_ID = '123456'
3838SPEC = {
3939 'id' : PIPELINE_ID ,
40- 'name' : 'test_pipeline'
40+ 'name' : 'test_pipeline' ,
41+ 'storage' : 'dbfs:/path'
4142}
42- HEADERS = 'dummy_headers'
43+ ID_ONLY_SPEC = {
44+ 'pipeline_id' : PIPELINE_ID ,
45+ }
46+ HEADERS = {'dummy_header' : 'dummy_value' }
4347
4448
4549@pytest .fixture ()
4650def pipelines_api ():
47- with mock .patch ('databricks_cli.pipelines.api.DeltaPipelinesService' ) \
48- as DeltaPipelinesServiceMock :
49- DeltaPipelinesServiceMock .return_value = mock .MagicMock ()
50- _pipelines_api = api .PipelinesApi (None )
51- yield _pipelines_api
51+ client_mock = mock .MagicMock ()
52+
53+ def server_response (* args , ** kwargs ):
54+ if args [0 ] == 'GET' :
55+ return {'pipeline_id' : PIPELINE_ID , 'state' : 'RUNNING' }
56+ client_mock .perform_query = mock .MagicMock (side_effect = server_response )
57+ _pipelines_api = api .PipelinesApi (client_mock )
58+ yield _pipelines_api
5259
5360
5461def file_exists_stub (_ , dbfs_path ):
@@ -75,7 +82,6 @@ def test_deploy(put_file_mock, dbfs_path_validate, pipelines_api, tmpdir):
7582 A test local file which has '456' written to it is not present in Dbfs and therefore must be.
7683 uploaded to dbfs.
7784 """
78- deploy_mock = pipelines_api .client .client .perform_query
7985 # set-up the test
8086 jar1 = tmpdir .join ('jar1.jar' ).strpath
8187 jar2 = tmpdir .join ('jar2.jar' ).strpath
@@ -122,39 +128,42 @@ def test_deploy(put_file_mock, dbfs_path_validate, pipelines_api, tmpdir):
122128 assert put_file_mock .call_args_list [1 ][0 ][0 ] == jar3_relpath
123129 assert put_file_mock .call_args_list [2 ][0 ][0 ] == jar4
124130 assert put_file_mock .call_args_list [3 ][0 ][0 ] == wheel1
125- deploy_mock .assert_called_with ('PUT' , '/pipelines/{}' .format (PIPELINE_ID ),
131+ client_mock = pipelines_api .client .client .perform_query
132+ client_mock .assert_called_with ('PUT' , '/pipelines/' + PIPELINE_ID ,
126133 data = expected_spec , headers = None )
127134
128135 pipelines_api .deploy (spec , HEADERS )
129- deploy_mock .assert_called_with ('PUT' , '/pipelines/{}' . format ( PIPELINE_ID ) ,
136+ client_mock .assert_called_with ('PUT' , '/pipelines/' + PIPELINE_ID ,
130137 data = expected_spec , headers = HEADERS )
138+ assert client_mock .call_count == 2
131139
132140
133141def test_delete (pipelines_api ):
134142 pipelines_api .delete (PIPELINE_ID )
135- delete_mock = pipelines_api .client .delete
136- assert delete_mock .call_count == 1
137- assert delete_mock . call_args [ 0 ][ 0 ] == PIPELINE_ID
138- assert delete_mock . call_args [ 0 ][ 1 ] is None
143+ client_mock = pipelines_api .client .client . perform_query
144+ assert client_mock .call_count == 1
145+ client_mock . assert_called_with ( 'DELETE' , '/pipelines/' + PIPELINE_ID ,
146+ data = ID_ONLY_SPEC , headers = None )
139147
140148 pipelines_api .delete (PIPELINE_ID , HEADERS )
141- assert delete_mock . call_args [ 0 ][ 0 ] == PIPELINE_ID
142- assert delete_mock . call_args [ 0 ][ 1 ] == HEADERS
149+ client_mock . assert_called_with ( 'DELETE' , '/pipelines/' + PIPELINE_ID ,
150+ data = ID_ONLY_SPEC , headers = HEADERS )
143151
144152
145153def test_get (pipelines_api ):
146- pipelines_api .get (PIPELINE_ID )
147- get_mock = pipelines_api .client .get
148- assert get_mock .call_count == 1
149- assert get_mock .call_args [0 ][0 ] == PIPELINE_ID
154+ response = pipelines_api .get (PIPELINE_ID )
155+ client_mock = pipelines_api .client .client .perform_query
156+ assert client_mock .call_count == 1
157+ client_mock .assert_called_with ('GET' , '/pipelines/' + PIPELINE_ID , data = {}, headers = None )
158+ assert (response ['pipeline_id' ] == PIPELINE_ID and response ['state' ] == 'RUNNING' )
150159
151160
152161def test_reset (pipelines_api ):
153162 pipelines_api .reset (PIPELINE_ID )
154- reset_mock = pipelines_api .client .reset
155- assert reset_mock .call_count == 1
156- assert reset_mock . call_args [ 0 ][ 0 ] == PIPELINE_ID
157- assert reset_mock . call_args [ 0 ][ 1 ] is None
163+ client_mock = pipelines_api .client .client . perform_query
164+ assert client_mock .call_count == 1
165+ client_mock . assert_called_with ( 'POST' , '/pipelines/{}/reset' . format ( PIPELINE_ID ),
166+ data = ID_ONLY_SPEC , headers = None )
158167
159168
160169def test_partition_local_remote (pipelines_api ):
0 commit comments