From 3f2345bf6c8660a0ef4976538236e7b37ed25da0 Mon Sep 17 00:00:00 2001 From: Thomas Ubensee <34603111+tomuben@users.noreply.github.com> Date: Thu, 5 Dec 2024 10:32:47 -0300 Subject: [PATCH] 1. Added "schema_version" 2. Fixes from review --- .../slc/models/language_definition_model.py | 2 + .../language_definitions.json | 1 + test/test_docker_api_language_def_json.py | 47 ++++++++++--------- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/exasol/slc/models/language_definition_model.py b/exasol/slc/models/language_definition_model.py index c9e6f22..ac5af38 100644 --- a/exasol/slc/models/language_definition_model.py +++ b/exasol/slc/models/language_definition_model.py @@ -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] diff --git a/test/resources/flavors/real-test-flavor/real_flavor_base/language_definitions.json b/test/resources/flavors/real-test-flavor/real_flavor_base/language_definitions.json index debc490..b2f9b07 100644 --- a/test/resources/flavors/real-test-flavor/real_flavor_base/language_definitions.json +++ b/test/resources/flavors/real-test-flavor/real_flavor_base/language_definitions.json @@ -1,4 +1,5 @@ { + "schema_version": 1, "language_definitions": [ { "protocol": "localzmq+protobuf", diff --git a/test/test_docker_api_language_def_json.py b/test/test_docker_api_language_def_json.py index 700031b..567e2f4 100644 --- a/test/test_docker_api_language_def_json.py +++ b/test/test_docker_api_language_def_json.py @@ -1,5 +1,6 @@ import json import shutil +import tarfile import unittest from pathlib import Path from tempfile import TemporaryDirectory, tempdir @@ -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 @@ -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( @@ -117,6 +124,7 @@ def test_docker_build(self): self.assertEqual( model, LanguageDefinitionsModel( + schema_version=1, language_definitions=[ LanguageDefinition( protocol="localzmq+protobuf", @@ -127,7 +135,7 @@ def test_docker_build(self): ), parameters=[], ) - ] + ], ), ) @@ -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__":