Skip to content

Commit

Permalink
Source Dixa: add to connector index (#4701)
Browse files Browse the repository at this point in the history
  • Loading branch information
sherifnada authored Jul 12, 2021
1 parent dbbab8f commit 8f2ab09
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sourceDefinitionId": "0b5c867e-1b12-4d02-ab74-97b2184ff6d7",
"name": "Dixa",
"dockerRepository": "airbyte/source-dixa",
"dockerImageTag": "0.1.0",
"documentationUrl": "https://docs.airbyte.io/integrations/sources/dixa"
}
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,8 @@
dockerRepository: airbyte/source-paypal-transaction
dockerImageTag: 0.1.0
documentationUrl: https://docs.airbyte.io/integrations/sources/paypal-transaction
- sourceDefinitionId: 0b5c867e-1b12-4d02-ab74-97b2184ff6d7
name: Dixa
dockerRepository: airbyte/source-dixa
dockerImageTag: 0.1.0
documentationUrl: https://docs.airbyte.io/integrations/sources/dixa
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ def ms_timestamp_to_datetime(milliseconds: int) -> datetime:
"""
Converts a millisecond-precision timestamp to a datetime object.
"""
return datetime.fromtimestamp(
ConversationExport._validate_ms_timestamp(milliseconds) / 1000, tz=timezone.utc
)
return datetime.fromtimestamp(ConversationExport._validate_ms_timestamp(milliseconds) / 1000, tz=timezone.utc)

@staticmethod
def datetime_to_ms_timestamp(dt: datetime) -> int:
Expand Down
63 changes: 15 additions & 48 deletions airbyte-integrations/connectors/source-dixa/unit_tests/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#

from datetime import datetime, timezone

import pytest
Expand All @@ -28,9 +30,7 @@

@pytest.fixture
def conversation_export():
return ConversationExport(
start_date=datetime(year=2021, month=7, day=1, hour=12, tzinfo=timezone.utc), batch_size=1, logger=None
)
return ConversationExport(start_date=datetime(year=2021, month=7, day=1, hour=12, tzinfo=timezone.utc), batch_size=1, logger=None)


def test_validate_ms_timestamp_with_valid_input():
Expand All @@ -49,28 +49,14 @@ def test_validate_ms_timestamp_with_invalid_input_length():

def test_ms_timestamp_to_datetime():
assert ConversationExport.ms_timestamp_to_datetime(1625312980123) == datetime(
year=2021,
month=7,
day=3,
hour=11,
minute=49,
second=40,
microsecond=123000,
tzinfo=timezone.utc
year=2021, month=7, day=3, hour=11, minute=49, second=40, microsecond=123000, tzinfo=timezone.utc
)


def test_datetime_to_ms_timestamp():
assert (
ConversationExport.datetime_to_ms_timestamp(datetime(
year=2021,
month=7,
day=3,
hour=11,
minute=49,
second=40,
microsecond=123000,
tzinfo=timezone.utc)
ConversationExport.datetime_to_ms_timestamp(
datetime(year=2021, month=7, day=3, hour=11, minute=49, second=40, microsecond=123000, tzinfo=timezone.utc)
)
== 1625312980123
)
Expand All @@ -83,14 +69,8 @@ def test_add_days_to_ms_timestamp():
def test_stream_slices_without_state(conversation_export):
conversation_export.end_timestamp = 1625270400001 # 2021-07-03 00:00:00 + 1 ms
expected_slices = [
{
'updated_after': 1625140800000, # 2021-07-01 12:00:00
'updated_before': 1625227200000 # 2021-07-02 12:00:00
},
{
'updated_after': 1625227200000,
'updated_before': 1625270400001
}
{"updated_after": 1625140800000, "updated_before": 1625227200000}, # 2021-07-01 12:00:00 # 2021-07-02 12:00:00
{"updated_after": 1625227200000, "updated_before": 1625270400001},
]
actual_slices = conversation_export.stream_slices()
assert actual_slices == expected_slices
Expand All @@ -101,12 +81,7 @@ def test_stream_slices_without_state_large_batch():
start_date=datetime(year=2021, month=7, day=1, hour=12, tzinfo=timezone.utc), batch_size=31, logger=None
)
conversation_export.end_timestamp = 1625270400001 # 2021-07-03 00:00:00 + 1 ms
expected_slices = [
{
'updated_after': 1625140800000, # 2021-07-01 12:00:00
'updated_before': 1625270400001
}
]
expected_slices = [{"updated_after": 1625140800000, "updated_before": 1625270400001}] # 2021-07-01 12:00:00
actual_slices = conversation_export.stream_slices()
assert actual_slices == expected_slices

Expand All @@ -123,26 +98,18 @@ def test_stream_slices_with_start_timestamp_larger_than_state():
Test that if start_timestamp is larger than state, then start at start_timestamp.
"""
conversation_export = ConversationExport(
start_date=datetime(year=2021, month=12, day=1, tzinfo=timezone.utc), batch_size=31,
logger=None
start_date=datetime(year=2021, month=12, day=1, tzinfo=timezone.utc), batch_size=31, logger=None
)
conversation_export.end_timestamp = 1638360000001 # 2021-12-01 12:00:00 + 1 ms
expected_slices = [
{
'updated_after': 1638316800000, # 2021-07-01 12:00:00
'updated_before': 1638360000001
}
]
actual_slices = conversation_export.stream_slices(
stream_state={'updated_at': 1625220000000} # # 2021-07-02 12:00:00
)
expected_slices = [{"updated_after": 1638316800000, "updated_before": 1638360000001}] # 2021-07-01 12:00:00
actual_slices = conversation_export.stream_slices(stream_state={"updated_at": 1625220000000}) # # 2021-07-02 12:00:00
assert actual_slices == expected_slices


def test_get_updated_state_without_state(conversation_export):
assert conversation_export.get_updated_state(
current_stream_state=None, latest_record={'updated_at': 1625263200000}
) == {'updated_at': 1625140800000}
assert conversation_export.get_updated_state(current_stream_state=None, latest_record={"updated_at": 1625263200000}) == {
"updated_at": 1625140800000
}


def test_get_updated_state_with_bigger_state(conversation_export):
Expand Down

0 comments on commit 8f2ab09

Please sign in to comment.