Skip to content

Commit

Permalink
fixup! fixup! Added import job documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
juanpardo committed Oct 2, 2023
1 parent ab70719 commit 51388d6
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 5 deletions.
1 change: 1 addition & 0 deletions croud/clusters/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ def import_jobs_list(args: Namespace) -> None:
keys=["id", "cluster_id", "status", "type", "destination"],
output_fmt=get_output_format(args),
transforms={
"source": lambda field: field.get(field.get("type")),
"destination": lambda field: field.get("table"),
},
)
Expand Down
17 changes: 15 additions & 2 deletions croud/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,27 @@ def format_rows(self, rows: Union[List[JsonDict], JsonDict]) -> str:
# | bar | 2 |
# +-----+-----+

headers = list(map(str, rows[0].keys())) if len(rows) else self.keys
# all_keys = [row.keys() for row in rows]
# all_keys = list(itertools.chain(*all_keys))
# all_keys_set = set(all_keys)
# all_keys = [x for x in all_keys if x not in all_keys_set]
all_keys = list(map(str, rows[0].keys())) if len(rows) else self.keys
if all_keys:
for row in rows:
for key in list(map(str, row.keys())):
if key not in all_keys:
all_keys.append(key)

# headers = set(itertools.chain(*all_keys)) if len(rows) else self.keys
headers = all_keys if len(rows) else self.keys

if headers is None:
return ""

values = [
[
self.transforms.get(header, TableFormatPrinter._identity_transform)(
row[header]
row.get(header, "")
)
for header in headers
]
Expand Down
65 changes: 62 additions & 3 deletions tests/commands/test_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1667,13 +1667,72 @@ def test_import_job_create_from_file(mock_request):
"status": "FAILED",
"type": "url",
"url": {"url": "https://some"},
}
},
{
"cluster_id": "123",
"compression": "gzip",
"dc": {
"created": "2023-03-14T10:12:29.763000+00:00",
"modified": "2023-03-14T10:12:29.763000+00:00",
},
"destination": {"create_table": True, "table": "croud-csv-import-two"},
"format": "json",
"id": "a95e5a20-61f7-415f-b128-1e21ddf17513",
"progress": {
"bytes": 0,
"message": "Failed",
"records": 0,
},
"status": "FAILED",
"type": "s3",
"s3": {
"endpoint": "https://some",
"file_path": "a-file-path",
"bucket": "bucket-name",
"secret_id": "a95e5a20-61f7-415f-b128-1e21ddf17513",
},
},
{
"cluster_id": "123",
"compression": "gzip",
"dc": {
"created": "2023-03-14T10:12:29.763000+00:00",
"modified": "2023-03-14T10:12:29.763000+00:00",
},
"destination": {"create_table": True, "table": "croud-csv-import-two"},
"format": "json",
"id": "a95e5a20-61f7-415f-b128-1e21ddf17513",
"progress": {
"bytes": 0,
"message": "Failed",
"records": 0,
},
"status": "FAILED",
"type": "file",
"file": {
"upload_url": "https://server.test/folder/myfile.json",
"file_size": 36,
"id": "a95e5a20-61f7-415f-b128-1e21ddf17513",
"name": "my test file",
"status": "UPLOADED",
},
},
],
None,
),
)
def test_import_job_list(mock_request):
call_command("croud", "clusters", "import-jobs", "list", "--cluster-id", "123")
@pytest.mark.parametrize("output_format", ["table", "wide"])
def test_import_job_list(mock_request, output_format):
call_command(
"croud",
"clusters",
"import-jobs",
"list",
"--cluster-id",
"123",
"-o",
output_format,
)
assert_rest(
mock_request,
RequestMethod.GET,
Expand Down

0 comments on commit 51388d6

Please sign in to comment.