Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Jul 27, 2023
1 parent 781bb04 commit 22134f9
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
5 changes: 3 additions & 2 deletions singer_sdk/plugin_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import logging
import os
import sys
import time
import typing as t
from pathlib import Path, PurePath
from types import MappingProxyType
Expand All @@ -24,7 +25,7 @@
from singer_sdk.helpers._classproperty import classproperty
from singer_sdk.helpers._compat import metadata
from singer_sdk.helpers._secrets import SecretString, is_common_secret_key
from singer_sdk.helpers._util import read_json_file, utc_now
from singer_sdk.helpers._util import read_json_file
from singer_sdk.helpers.capabilities import (
FLATTENING_CONFIG,
STREAM_MAPS_CONFIG,
Expand Down Expand Up @@ -156,7 +157,7 @@ def __init__(
self.metrics_logger = metrics.get_metrics_logger()

# Initialization timestamp
self.__initialized_at = int(utc_now().timestamp())
self.__initialized_at = int(time.time() * 1000)

def setup_mapper(self) -> None:
"""Initialize the plugin mapper for this tap."""
Expand Down
Empty file added tests/core/sinks/__init__.py
Empty file.
55 changes: 55 additions & 0 deletions tests/core/sinks/test_sdc_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from __future__ import annotations

from freezegun import freeze_time

from tests.conftest import BatchSinkMock, TargetMock


def test_sdc_metadata():
with freeze_time("2023-01-01T00:00:00+00:00"):
target = TargetMock()

sink = BatchSinkMock(
target,
"users",
{"type": "object", "properties": {"id": {"type": "integer"}}},
["id"],
)

record_message = {
"type": "RECORD",
"stream": "users",
"record": {"id": 1},
"time_extracted": "2021-01-01T00:00:00+00:00",
"version": 100,
}
record = record_message["record"]

with freeze_time("2023-01-01T00:05:00+00:00"):
sink._add_sdc_metadata_to_record(record, record_message, {})

assert record == {
"id": 1,
"_sdc_extracted_at": "2021-01-01T00:00:00+00:00",
"_sdc_received_at": "2023-01-01T00:05:00+00:00",
"_sdc_batched_at": "2023-01-01T00:05:00+00:00",
"_sdc_deleted_at": None,
"_sdc_sequence": 1672531500000,
"_sdc_table_version": 100,
"_sdc_sync_started_at": 1672531200000,
}

sink._add_sdc_metadata_to_schema()
assert sink.schema == {
"type": "object",
"properties": {
"id": {"type": "integer"},
"_sdc_extracted_at": {"type": ["null", "string"], "format": "date-time"},
"_sdc_received_at": {"type": ["null", "string"], "format": "date-time"},
"_sdc_batched_at": {"type": ["null", "string"], "format": "date-time"},
"_sdc_deleted_at": {"type": ["null", "string"], "format": "date-time"},
"_sdc_sequence": {"type": ["null", "integer"]},
"_sdc_table_version": {"type": ["null", "integer"]},
"_sdc_sync_started_at": {"type": ["null", "integer"]},
},
}

0 comments on commit 22134f9

Please sign in to comment.