ingestr 0.6.6__py3-none-any.whl → 0.7.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ingestr might be problematic. Click here for more details.

@@ -1,113 +0,0 @@
1
- import json
2
- import os
3
- import unittest
4
-
5
- import dlt
6
- import pytest
7
-
8
- from ingestr.src.destinations import (
9
- BigQueryDestination,
10
- DatabricksDestination,
11
- DuckDBDestination,
12
- MsSQLDestination,
13
- PostgresDestination,
14
- RedshiftDestination,
15
- SnowflakeDestination,
16
- )
17
-
18
-
19
- class BigQueryDestinationTest(unittest.TestCase):
20
- destination = BigQueryDestination()
21
- abs_path_to_credentials = os.path.abspath(
22
- os.path.join(os.path.dirname(__file__), "./testdata/fakebqcredentials.json")
23
- )
24
- actual_credentials: dict = {}
25
-
26
- def setUp(self):
27
- with open(self.abs_path_to_credentials, "r") as f:
28
- self.actual_credentials = json.load(f)
29
-
30
- def test_bq_destination_cred_path_required(self):
31
- with pytest.raises(ValueError):
32
- uri = "bigquery://my-project"
33
- self.destination.dlt_dest(uri)
34
-
35
- def test_bq_destination_simple_uri(self):
36
- uri = f"bigquery://my-project?credentials_path={self.abs_path_to_credentials}"
37
- result = self.destination.dlt_dest(uri)
38
-
39
- self.assertTrue(isinstance(result, dlt.destinations.bigquery))
40
- self.assertEqual(result.config_params["credentials"], self.actual_credentials)
41
- self.assertTrue("location" not in result.config_params)
42
-
43
- def test_bq_destination_with_location(self):
44
- uri = f"bigquery://my-project?credentials_path={self.abs_path_to_credentials}&location=EU"
45
- result = self.destination.dlt_dest(uri)
46
-
47
- self.assertTrue(isinstance(result, dlt.destinations.bigquery))
48
- self.assertEqual(result.config_params["credentials"], self.actual_credentials)
49
- self.assertEqual(result.config_params["location"], "EU")
50
-
51
- def test_bq_destination_run_params_require_two_or_three_fields(self):
52
- with pytest.raises(ValueError):
53
- self.destination.dlt_run_params("", "sometable")
54
-
55
- with pytest.raises(ValueError):
56
- self.destination.dlt_run_params("", "sometable.with.extra.fields")
57
-
58
- def test_bq_destination_run_params_parse_table_names_correctly(self):
59
- result = self.destination.dlt_run_params("", "dataset.sometable")
60
- self.assertEqual(result, {"dataset_name": "dataset", "table_name": "sometable"})
61
-
62
- result = self.destination.dlt_run_params("", "project.dataset.sometable")
63
- self.assertEqual(result, {"dataset_name": "dataset", "table_name": "sometable"})
64
-
65
-
66
- class GenericSqlDestinationFixture(object):
67
- def test_credentials_are_passed_correctly(self):
68
- uri = "some-uri"
69
- result = self.destination.dlt_dest(uri)
70
-
71
- self.assertTrue(isinstance(result, self.expected_class))
72
- self.assertEqual(result.config_params["credentials"], uri)
73
-
74
- def test_destination_run_params_require_two_fields(self):
75
- with pytest.raises(ValueError):
76
- self.destination.dlt_run_params("", "sometable")
77
-
78
- with pytest.raises(ValueError):
79
- self.destination.dlt_run_params("", "sometable.with.extra")
80
-
81
- def test_destination_run_params_parse_table_names_correctly(self):
82
- result = self.destination.dlt_run_params("", "dataset.sometable")
83
- self.assertEqual(result, {"dataset_name": "dataset", "table_name": "sometable"})
84
-
85
-
86
- class PostgresDestinationTest(unittest.TestCase, GenericSqlDestinationFixture):
87
- destination = PostgresDestination()
88
- expected_class = dlt.destinations.postgres
89
-
90
-
91
- class SnowflakeDestinationTest(unittest.TestCase, GenericSqlDestinationFixture):
92
- destination = SnowflakeDestination()
93
- expected_class = dlt.destinations.snowflake
94
-
95
-
96
- class RedshiftDestinationTest(unittest.TestCase, GenericSqlDestinationFixture):
97
- destination = RedshiftDestination()
98
- expected_class = dlt.destinations.redshift
99
-
100
-
101
- class DuckDBDestinationTest(unittest.TestCase, GenericSqlDestinationFixture):
102
- destination = DuckDBDestination()
103
- expected_class = dlt.destinations.duckdb
104
-
105
-
106
- class MsSQLDestinationTest(unittest.TestCase, GenericSqlDestinationFixture):
107
- destination = MsSQLDestination()
108
- expected_class = dlt.destinations.mssql
109
-
110
-
111
- class DatabricksDestinationTest(unittest.TestCase, GenericSqlDestinationFixture):
112
- destination = DatabricksDestination()
113
- expected_class = dlt.destinations.databricks
@@ -1,13 +0,0 @@
1
- from ingestr.src.factory import parse_scheme_from_uri
2
-
3
-
4
- def test_scheme_is_parsed_from_uri_correctly():
5
- assert parse_scheme_from_uri("bigquery://my-project") == "bigquery"
6
- assert parse_scheme_from_uri("http://localhost:8080") == "http"
7
- assert parse_scheme_from_uri("file:///tmp/myfile") == "file"
8
- assert parse_scheme_from_uri("https://example.com?query=123") == "https"
9
- assert parse_scheme_from_uri("ftp://ftp.example.com/downloads/file.zip") == "ftp"
10
- assert (
11
- parse_scheme_from_uri("redshift+psycopg2://user:pw@host") == "redshift+psycopg2"
12
- )
13
- assert parse_scheme_from_uri("mysql+pymysql://user:pw@host") == "mysql+pymysql"
@@ -1,45 +0,0 @@
1
- from dlt.common.pendulum import pendulum
2
-
3
- from .helpers import convert_datetime_fields, find_latest_timestamp_from_page
4
-
5
-
6
- def test_convert_datetime_fields():
7
- item = {
8
- "key1": "val1",
9
- "created_datetime": "2024-06-20T07:39:36.514848+00:00",
10
- "sent_datetime": "2024-06-20T07:40:20.166593+00:00",
11
- "should_send_datetime": "2024-06-20T07:39:37.514848+00:00",
12
- }
13
-
14
- actual = convert_datetime_fields(item)
15
-
16
- assert actual == {
17
- "key1": "val1",
18
- "created_datetime": pendulum.datetime(2024, 6, 20, 7, 39, 36, 514848, tz="UTC"),
19
- "sent_datetime": pendulum.datetime(2024, 6, 20, 7, 40, 20, 166593, tz="UTC"),
20
- "should_send_datetime": pendulum.datetime(
21
- 2024, 6, 20, 7, 39, 37, 514848, tz="UTC"
22
- ),
23
- "updated_datetime": pendulum.datetime(2024, 6, 20, 7, 40, 20, 166593, tz="UTC"),
24
- }
25
-
26
-
27
- def test_find_latest_timestamp_from_page():
28
- items = [
29
- {
30
- "key1": "val1",
31
- "created_datetime": "2024-06-20T07:39:36.514848+00:00",
32
- "sent_datetime": "2024-06-20T07:40:20.166593+00:00",
33
- "should_send_datetime": "2024-06-20T07:39:37.514848+00:00",
34
- },
35
- {
36
- "key1": "val2",
37
- "created_datetime": "2024-06-20T07:39:36.514848+00:00",
38
- "sent_datetime": "2024-06-20T07:40:21.123123+00:00",
39
- "should_send_datetime": "2024-06-20T07:39:37.514848+00:00",
40
- },
41
- ]
42
-
43
- actual = find_latest_timestamp_from_page(items)
44
-
45
- assert actual == pendulum.datetime(2024, 6, 20, 7, 40, 21, 123123, tz="UTC")
@@ -1,96 +0,0 @@
1
- import unittest
2
-
3
- import dlt
4
- import pytest
5
-
6
- from ingestr.src.sources import MongoDbSource, SqlSource
7
-
8
-
9
- class SqlSourceTest(unittest.TestCase):
10
- def test_sql_source_requires_two_fields_in_table(self):
11
- source = SqlSource()
12
- with pytest.raises(ValueError):
13
- uri = "bigquery://my-project"
14
- source.dlt_source(uri, "onetable")
15
-
16
- def test_table_instance_is_created(self):
17
- uri = "bigquery://my-project"
18
- table = "schema.table"
19
-
20
- # monkey patch the sql_table function
21
- def sql_table(credentials, schema, table, incremental, merge_key, backend):
22
- self.assertEqual(credentials, uri)
23
- self.assertEqual(schema, "schema")
24
- self.assertEqual(table, "table")
25
- self.assertEqual(backend, "sqlalchemy")
26
- self.assertIsNone(incremental)
27
- self.assertIsNone(merge_key)
28
- return dlt.resource()
29
-
30
- source = SqlSource(table_builder=sql_table)
31
- res = source.dlt_source(uri, table)
32
- self.assertIsNotNone(res)
33
-
34
- def test_table_instance_is_created_with_incremental(self):
35
- uri = "bigquery://my-project"
36
- table = "schema.table"
37
- incremental_key = "id"
38
-
39
- # monkey patch the sql_table function
40
- def sql_table(credentials, schema, table, incremental, merge_key, backend):
41
- self.assertEqual(credentials, uri)
42
- self.assertEqual(schema, "schema")
43
- self.assertEqual(table, "table")
44
- self.assertEqual(backend, "sqlalchemy")
45
- self.assertIsInstance(incremental, dlt.sources.incremental)
46
- self.assertEqual(incremental.cursor_path, incremental_key)
47
- self.assertIsNone(merge_key)
48
- return dlt.resource()
49
-
50
- source = SqlSource(table_builder=sql_table)
51
- res = source.dlt_source(uri, table, incremental_key=incremental_key)
52
- self.assertIsNotNone(res)
53
-
54
-
55
- class MongoDbSourceTest(unittest.TestCase):
56
- def test_sql_source_requires_two_fields_in_table(self):
57
- source = MongoDbSource()
58
- with pytest.raises(ValueError):
59
- uri = "mongodb://my-project"
60
- source.dlt_source(uri, "onetable")
61
-
62
- def test_table_instance_is_created(self):
63
- uri = "mongodb://my-project"
64
- table = "schema.table"
65
-
66
- # monkey patch the mongo function
67
- def mongo(connection_url, database, collection, incremental, parallel):
68
- self.assertEqual(connection_url, uri)
69
- self.assertEqual(database, "schema")
70
- self.assertEqual(collection, "table")
71
- self.assertIsNone(incremental)
72
- self.assertTrue(parallel)
73
- return dlt.resource()
74
-
75
- source = MongoDbSource(table_builder=mongo)
76
- res = source.dlt_source(uri, table)
77
- self.assertIsNotNone(res)
78
-
79
- def test_table_instance_is_created_with_incremental(self):
80
- uri = "mongodb://my-project"
81
- table = "schema.table"
82
- incremental_key = "id"
83
-
84
- # monkey patch the mongo function
85
- def mongo(connection_url, database, collection, incremental, parallel):
86
- self.assertEqual(connection_url, uri)
87
- self.assertEqual(database, "schema")
88
- self.assertEqual(collection, "table")
89
- self.assertIsInstance(incremental, dlt.sources.incremental)
90
- self.assertEqual(incremental.cursor_path, incremental_key)
91
- self.assertTrue(parallel)
92
- return dlt.resource()
93
-
94
- source = MongoDbSource(table_builder=mongo)
95
- res = source.dlt_source(uri, table, incremental_key=incremental_key)
96
- self.assertIsNotNone(res)