99# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1010# See the License for the specific language governing permissions and
1111# limitations under the License.
12-
12+ import json
1313import logging .config
1414import unittest
1515import uuid
@@ -211,7 +211,7 @@ def test_create_job(self, mock_put):
211211 "07f3d2dfc8186cadae9146719e70294a4c7a8ee8"
212212
213213 context = {
214- "SQL " : "SELECT * FROM public.mytable;"
214+ "sql " : "SELECT * FROM public.mytable;"
215215 }
216216
217217 mock_put .return_value = {
@@ -239,7 +239,7 @@ def test_create_job(self, mock_put):
239239 "location" : "https://github.com/my-jobs/blob/"
240240 "07f3d2dfc8186cadae9146719e70294a4c7a8ee8" ,
241241 "context" : {
242- "SQL " : "SELECT * FROM public.mytable;"
242+ "sql " : "SELECT * FROM public.mytable;"
243243 },
244244 "description" : "My first job." ,
245245 "latestRun" : None
@@ -258,6 +258,89 @@ def test_create_job(self, mock_put):
258258 assert str (response ['id' ]) is not None
259259 assert str (response ['location' ]) == location
260260
261+ @mock .patch ("marquez_client.client.MarquezClient._put" )
262+ def test_create_job_with_run_id (self , mock_put ):
263+ run_id = str (uuid .uuid4 ())
264+ job_name = "my-job"
265+ input_dataset = [
266+ {
267+ "namespace" : "my-namespace" ,
268+ "name" : "public.mytable"
269+ }
270+ ]
271+ output_dataset = {
272+ "namespace" : "my-namespace" ,
273+ "name" : "public.mytable"
274+ }
275+
276+ location = "https://github.com/my-jobs/blob/" \
277+ "07f3d2dfc8186cadae9146719e70294a4c7a8ee8"
278+
279+ context = {
280+ "sql" : "SELECT * FROM public.mytable;"
281+ }
282+
283+ mock_put .return_value = {
284+ "id" : {
285+ "namespace" : "my-namespace" ,
286+ "name" : "my-job"
287+ },
288+ "type" : "BATCH" ,
289+ "name" : "my-job" ,
290+ "createdAt" : "2020-08-12T07:30:55.321059Z" ,
291+ "updatedAt" : "2020-08-12T07:30:55.333230Z" ,
292+ "namespace" : "my-namespace" ,
293+ "inputs" : [
294+ {
295+ "namespace" : "my-namespace" ,
296+ "name" : "public.mytable"
297+ }
298+ ],
299+ "outputs" : [
300+ {
301+ "namespace" : "my-namespace" ,
302+ "name" : "public.mytable"
303+ }
304+ ],
305+ "location" : "https://github.com/my-jobs/blob/"
306+ "07f3d2dfc8186cadae9146719e70294a4c7a8ee8" ,
307+ "context" : {
308+ "sql" : "SELECT * FROM public.mytable;"
309+ },
310+ "description" : "My first job." ,
311+ "latestRun" : {
312+ "id" : run_id ,
313+ "createdAt" : "2020-10-09T19:14:07.846451Z" ,
314+ "updatedAt" : "2020-10-09T19:14:07.911627Z" ,
315+ "nominalStartTime" : None ,
316+ "nominalEndTime" : None ,
317+ "state" : RunState .RUNNING ,
318+ "startedAt" : "2020-10-09T19:14:07.893074Z" ,
319+ "endedAt" : "2020-10-09T19:14:07.911627Z" ,
320+ "durationMs" : 18 ,
321+ "args" : {}
322+ }
323+ }
324+
325+ response = self .client .create_job (
326+ namespace_name = _NAMESPACE ,
327+ job_name = job_name ,
328+ job_type = JobType .BATCH ,
329+ location = location ,
330+ input_dataset = input_dataset ,
331+ output_dataset = output_dataset ,
332+ context = context ,
333+ run_id = run_id
334+ )
335+
336+ mock_put .assert_called_once ()
337+ assert mock_put .call_args .kwargs .get ("payload" ).get ("runId" )\
338+ == run_id
339+
340+ assert str (response ['inputs' ]) is not None
341+ assert str (response ['latestRun' ]['id' ]) == run_id
342+ assert response ['latestRun' ]['state' ] == RunState .RUNNING
343+
261344 @mock .patch ("marquez_client.client.MarquezClient._post" )
262345 def test_create_job_run (self , mock_post ):
263346 run_id = str (uuid .uuid4 ())
0 commit comments