Skip to content

Commit

Permalink
1. Added "schema_version"
Browse files Browse the repository at this point in the history
2. Fixes from review
  • Loading branch information
tomuben committed Dec 5, 2024
1 parent 652dd9e commit 3f2345b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
2 changes: 2 additions & 0 deletions exasol/slc/models/language_definition_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ class LanguageDefinitionsModel(BaseModel):
Contains information about all supported languages and the respective path of the UDF client of an Script-Languages-Container.
"""

schema_version: int

language_definitions: List[LanguageDefinition]
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"schema_version": 1,
"language_definitions": [
{
"protocol": "localzmq+protobuf",
Expand Down
47 changes: 26 additions & 21 deletions test/test_docker_api_language_def_json.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import shutil
import tarfile
import unittest
from pathlib import Path
from tempfile import TemporaryDirectory, tempdir
Expand Down Expand Up @@ -57,21 +58,13 @@ def read_file_from_docker_image(self, image_name, file_path):

# Extract the file content from the tar stream
import io
import tarfile

file_content = None

with TemporaryDirectory() as d:
tar_file_path = Path(d) / "tmp.tar"
with open(tar_file_path, "wb") as f:
for chunk in tar_stream:
f.write(chunk)
with tarfile.open(tar_file_path) as tar:
for member in tar.getmembers():
f = tar.extractfile(member)
if f:
file_content = f.read()
break
self.write_tar_file(tar_file_path, tar_stream)
file_content = self.read_tar_file_content(file_content, tar_file_path)

return file_content.decode("utf-8") if file_content else None

Expand All @@ -80,6 +73,20 @@ def read_file_from_docker_image(self, image_name, file_path):
container.stop()
container.remove()

def write_tar_file(self, tar_file_path, tar_stream):
with open(tar_file_path, "wb") as f:
for chunk in tar_stream:
f.write(chunk)

def read_tar_file_content(self, file_content, tar_file_path):
with tarfile.open(tar_file_path) as tar:
for member in tar.getmembers():
f = tar.extractfile(member)
if f:
file_content = f.read()
break
return file_content

def test_docker_build(self):
flavor_path = exaslct_utils.get_test_flavor()
image_infos = build(
Expand Down Expand Up @@ -117,6 +124,7 @@ def test_docker_build(self):
self.assertEqual(
model,
LanguageDefinitionsModel(
schema_version=1,
language_definitions=[
LanguageDefinition(
protocol="localzmq+protobuf",
Expand All @@ -127,7 +135,7 @@ def test_docker_build(self):
),
parameters=[],
)
]
],
),
)

Expand All @@ -146,16 +154,13 @@ def test_docker_build_invalid_lang_def_json(self):
with open(lang_def_json_path, "w") as f:
f.write(json.dumps(lang_def_invalid))

throwed_exception = False
try:
build(
flavor_path=(str(temp_flavor_path),),
source_docker_repository_name=self.test_environment.docker_repository_name,
target_docker_repository_name=self.test_environment.docker_repository_name,
)
except pydantic_core._pydantic_core.ValidationError as e:
throwed_exception = True
self.assertTrue(throwed_exception)
self.assertRaises(
pydantic_core._pydantic_core.ValidationError,
build,
flavor_path=(str(temp_flavor_path),),
source_docker_repository_name=self.test_environment.docker_repository_name,
target_docker_repository_name=self.test_environment.docker_repository_name,
)


if __name__ == "__main__":
Expand Down

0 comments on commit 3f2345b

Please sign in to comment.