From 2bbe8e4e751157a58b64a2cf6537c7eb575ac937 Mon Sep 17 00:00:00 2001 From: Derek Visch Date: Tue, 20 Dec 2022 15:47:08 -0500 Subject: [PATCH] Record before schema should throw an exception --- target_postgres/target.py | 11 +++++++++++ target_postgres/tests/test_standard_target.py | 12 ++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/target_postgres/target.py b/target_postgres/target.py index cac68534..a3c4a9e9 100644 --- a/target_postgres/target.py +++ b/target_postgres/target.py @@ -130,3 +130,14 @@ def max_parallelism(self) -> int: """ # https://github.com/MeltanoLabs/target-postgres/issues/3 return 1 + + def _process_record_message(self, message_dict: dict) -> None: + """Process a RECORD message. + + Args: + message_dict: TODO + """ + stream_name = message_dict["stream"] + if self.mapper.stream_maps.get(stream_name) is None: + raise Exception(f"Schema message has not been sent for {stream_name}") + super()._process_record_message(message_dict) diff --git a/target_postgres/tests/test_standard_target.py b/target_postgres/tests/test_standard_target.py index b9c3ddc9..17b9a477 100644 --- a/target_postgres/tests/test_standard_target.py +++ b/target_postgres/tests/test_standard_target.py @@ -81,10 +81,14 @@ def test_aapl_to_postgres(postgres_config): sync_end_to_end(tap, target) -# TODO this test should throw an exception def test_record_before_schema(postgres_target): - file_name = "record_before_schema.singer" - singer_file_to_target(file_name, postgres_target) + with pytest.raises(Exception) as e: + file_name = "record_before_schema.singer" + singer_file_to_target(file_name, postgres_target) + + assert ( + str(e.value) == "Schema message has not been sent for test_record_before_schema" + ) # TODO this test should throw an exception @@ -107,7 +111,7 @@ def test_record_missing_required_property(postgres_target): # TODO test that data is correctly set # see target-sqllit/tests/test_target_sqllite.py -def test_record_missing_required_property(postgres_target): +def test_camelcase(postgres_target): file_name = "camelcase.singer" singer_file_to_target(file_name, postgres_target)