Skip to content
This repository was archived by the owner on Dec 5, 2020. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 86 additions & 3 deletions tests/test_marquez_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import json
import logging.config
import unittest
import uuid
Expand Down Expand Up @@ -211,7 +211,7 @@ def test_create_job(self, mock_put):
"07f3d2dfc8186cadae9146719e70294a4c7a8ee8"

context = {
"SQL": "SELECT * FROM public.mytable;"
"sql": "SELECT * FROM public.mytable;"
}

mock_put.return_value = {
Expand Down Expand Up @@ -239,7 +239,7 @@ def test_create_job(self, mock_put):
"location": "https://github.com/my-jobs/blob/"
"07f3d2dfc8186cadae9146719e70294a4c7a8ee8",
"context": {
"SQL": "SELECT * FROM public.mytable;"
"sql": "SELECT * FROM public.mytable;"
},
"description": "My first job.",
"latestRun": None
Expand All @@ -258,6 +258,89 @@ def test_create_job(self, mock_put):
assert str(response['id']) is not None
assert str(response['location']) == location

@mock.patch("marquez_client.client.MarquezClient._put")
def test_create_job_with_run_id(self, mock_put):
run_id = str(uuid.uuid4())
job_name = "my-job"
input_dataset = [
{
"namespace": "my-namespace",
"name": "public.mytable"
}
]
output_dataset = {
"namespace": "my-namespace",
"name": "public.mytable"
}

location = "https://github.com/my-jobs/blob/" \
"07f3d2dfc8186cadae9146719e70294a4c7a8ee8"

context = {
"sql": "SELECT * FROM public.mytable;"
}

mock_put.return_value = {
"id": {
"namespace": "my-namespace",
"name": "my-job"
},
"type": "BATCH",
"name": "my-job",
"createdAt": "2020-08-12T07:30:55.321059Z",
"updatedAt": "2020-08-12T07:30:55.333230Z",
"namespace": "my-namespace",
"inputs": [
{
"namespace": "my-namespace",
"name": "public.mytable"
}
],
"outputs": [
{
"namespace": "my-namespace",
"name": "public.mytable"
}
],
"location": "https://github.com/my-jobs/blob/"
"07f3d2dfc8186cadae9146719e70294a4c7a8ee8",
"context": {
"sql": "SELECT * FROM public.mytable;"
},
"description": "My first job.",
"latestRun": {
"id": run_id,
"createdAt": "2020-10-09T19:14:07.846451Z",
"updatedAt": "2020-10-09T19:14:07.911627Z",
"nominalStartTime": None,
"nominalEndTime": None,
"state": RunState.RUNNING,
"startedAt": "2020-10-09T19:14:07.893074Z",
"endedAt": "2020-10-09T19:14:07.911627Z",
"durationMs": 18,
"args": {}
}
}

response = self.client.create_job(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A small clarification here: the job create response won't contain the run ID. The optional run ID will only be used to link a newly created job version to an existing job run, but not returned to the caller. You'd want to update your test to assert runId is part if the request.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

namespace_name=_NAMESPACE,
job_name=job_name,
job_type=JobType.BATCH,
location=location,
input_dataset=input_dataset,
output_dataset=output_dataset,
context=context,
run_id=run_id
)

mock_put.assert_called_once()
assert mock_put.call_args.kwargs.get("payload").get("runId")\
== run_id

assert str(response['inputs']) is not None
assert str(response['latestRun']['id']) == run_id
assert response['latestRun']['state'] == RunState.RUNNING

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind if we also add an assert that the mock_put was called only once?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's redundant. but if you insist. why not, sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@mock.patch("marquez_client.client.MarquezClient._post")
def test_create_job_run(self, mock_post):
run_id = str(uuid.uuid4())
Expand Down