airbyte-source-microsoft-dataverse 0.1.2__py3-none-any.whl → 0.1.3__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.
@@ -0,0 +1,110 @@
1
+ Metadata-Version: 2.1
2
+ Name: airbyte-source-microsoft-dataverse
3
+ Version: 0.1.3
4
+ Summary: Source implementation for Microsoft Dataverse.
5
+ Home-page: https://airbyte.com
6
+ License: MIT
7
+ Author: Airbyte
8
+ Author-email: contact@airbyte.io
9
+ Requires-Python: >=3.9,<3.12
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Requires-Dist: airbyte-cdk (==0.80.0)
16
+ Project-URL: Documentation, https://docs.airbyte.com/integrations/sources/microsoft-dataverse
17
+ Project-URL: Repository, https://github.com/airbytehq/airbyte
18
+ Description-Content-Type: text/markdown
19
+
20
+ # Microsoft-Dataverse source connector
21
+
22
+
23
+ This is the repository for the Microsoft-Dataverse source connector, written in Python.
24
+ For information about how to use this connector within Airbyte, see [the documentation](https://docs.airbyte.com/integrations/sources/microsoft-dataverse).
25
+
26
+ ## Local development
27
+
28
+ ### Prerequisites
29
+ * Python (~=3.9)
30
+ * Poetry (~=1.7) - installation instructions [here](https://python-poetry.org/docs/#installation)
31
+
32
+
33
+ ### Installing the connector
34
+ From this connector directory, run:
35
+ ```bash
36
+ poetry install --with dev
37
+ ```
38
+
39
+
40
+ ### Create credentials
41
+ **If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.com/integrations/sources/microsoft-dataverse)
42
+ to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_microsoft_dataverse/spec.yaml` file.
43
+ Note that any directory named `secrets` is gitignored across the entire Airbyte repo, so there is no danger of accidentally checking in sensitive information.
44
+ See `sample_files/sample_config.json` for a sample config file.
45
+
46
+
47
+ ### Locally running the connector
48
+ ```
49
+ poetry run source-microsoft-dataverse spec
50
+ poetry run source-microsoft-dataverse check --config secrets/config.json
51
+ poetry run source-microsoft-dataverse discover --config secrets/config.json
52
+ poetry run source-microsoft-dataverse read --config secrets/config.json --catalog sample_files/configured_catalog.json
53
+ ```
54
+
55
+ ### Running unit tests
56
+ To run unit tests locally, from the connector directory run:
57
+ ```
58
+ poetry run pytest unit_tests
59
+ ```
60
+
61
+ ### Building the docker image
62
+ 1. Install [`airbyte-ci`](https://github.com/airbytehq/airbyte/blob/master/airbyte-ci/connectors/pipelines/README.md)
63
+ 2. Run the following command to build the docker image:
64
+ ```bash
65
+ airbyte-ci connectors --name=source-microsoft-dataverse build
66
+ ```
67
+
68
+ An image will be available on your host with the tag `airbyte/source-microsoft-dataverse:dev`.
69
+
70
+
71
+ ### Running as a docker container
72
+ Then run any of the connector commands as follows:
73
+ ```
74
+ docker run --rm airbyte/source-microsoft-dataverse:dev spec
75
+ docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-microsoft-dataverse:dev check --config /secrets/config.json
76
+ docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-microsoft-dataverse:dev discover --config /secrets/config.json
77
+ docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/source-microsoft-dataverse:dev read --config /secrets/config.json --catalog /integration_tests/configured_catalog.json
78
+ ```
79
+
80
+ ### Running our CI test suite
81
+ You can run our full test suite locally using [`airbyte-ci`](https://github.com/airbytehq/airbyte/blob/master/airbyte-ci/connectors/pipelines/README.md):
82
+ ```bash
83
+ airbyte-ci connectors --name=source-microsoft-dataverse test
84
+ ```
85
+
86
+ ### Customizing acceptance Tests
87
+ Customize `acceptance-test-config.yml` file to configure acceptance tests. See [Connector Acceptance Tests](https://docs.airbyte.com/connector-development/testing-connectors/connector-acceptance-tests-reference) for more information.
88
+ If your connector requires to create or destroy resources for use during acceptance tests create fixtures for it and place them inside integration_tests/acceptance.py.
89
+
90
+ ### Dependency Management
91
+ All of your dependencies should be managed via Poetry.
92
+ To add a new dependency, run:
93
+ ```bash
94
+ poetry add <package-name>
95
+ ```
96
+
97
+ Please commit the changes to `pyproject.toml` and `poetry.lock` files.
98
+
99
+ ## Publishing a new version of the connector
100
+ You've checked out the repo, implemented a million dollar feature, and you're ready to share your changes with the world. Now what?
101
+ 1. Make sure your changes are passing our test suite: `airbyte-ci connectors --name=source-microsoft-dataverse test`
102
+ 2. Bump the connector version (please follow [semantic versioning for connectors](https://docs.airbyte.com/contributing-to-airbyte/resources/pull-requests-handbook/#semantic-versioning-for-connectors)):
103
+ - bump the `dockerImageTag` value in in `metadata.yaml`
104
+ - bump the `version` value in `pyproject.toml`
105
+ 3. Make sure the `metadata.yaml` content is up to date.
106
+ 4. Make sure the connector documentation and its changelog is up to date (`docs/integrations/sources/microsoft-dataverse.md`).
107
+ 5. Create a Pull Request: use [our PR naming conventions](https://docs.airbyte.com/contributing-to-airbyte/resources/pull-requests-handbook/#pull-request-title-convention).
108
+ 6. Pat yourself on the back for being an awesome contributor.
109
+ 7. Someone from Airbyte will take a look at your PR and iterate with you to merge it into master.
110
+ 8. Once your PR is merged, the new version of the connector will be automatically published to Docker Hub and our connector registry.
@@ -0,0 +1,10 @@
1
+ source_microsoft_dataverse/__init__.py,sha256=xy7FvZqZBBL0_I7mMd5ex5llLWTllG3HRt836ktTD7Q,148
2
+ source_microsoft_dataverse/dataverse.py,sha256=HOQoA571fpy0Bxk4W9l3DttxX34sKkOjTWYeuwZ0uUA,2521
3
+ source_microsoft_dataverse/run.py,sha256=hPGT5kR0LB6ZdKtLmwfLHymdF4EsDaFM2EC4J5ZAr3A,267
4
+ source_microsoft_dataverse/source.py,sha256=7Z6f-FE9P2ycZlgdo5fVNYTlVKjKBiKqll3CMjp8IW4,4435
5
+ source_microsoft_dataverse/spec.yaml,sha256=GmPlzh34HTII0aUW9XUbLxUk3VPEdvQ6E4iIKz4YMiA,1147
6
+ source_microsoft_dataverse/streams.py,sha256=3PhAYr4kM2GjW4jPd-XGIwg0jqiECUyKUK9AJB9JQiw,6168
7
+ airbyte_source_microsoft_dataverse-0.1.3.dist-info/METADATA,sha256=8iwm5F0kmbsLefpyTO-zGwDWBl5vty0-7DJsQzp4QPM,5473
8
+ airbyte_source_microsoft_dataverse-0.1.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
9
+ airbyte_source_microsoft_dataverse-0.1.3.dist-info/entry_points.txt,sha256=CFEv3NkGV7JlqCcJeXMac5pLipIzJg6omte8L0pV7ns,81
10
+ airbyte_source_microsoft_dataverse-0.1.3.dist-info/RECORD,,
@@ -1,5 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.42.0)
2
+ Generator: poetry-core 1.9.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
-
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ source-microsoft-dataverse=source_microsoft_dataverse.run:run
3
+
@@ -1,99 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: airbyte-source-microsoft-dataverse
3
- Version: 0.1.2
4
- Summary: Source implementation for Microsoft Dataverse.
5
- Author: Airbyte
6
- Author-email: contact@airbyte.io
7
- Description-Content-Type: text/markdown
8
- Requires-Dist: airbyte-cdk ~=0.2
9
- Provides-Extra: tests
10
- Requires-Dist: requests-mock ~=1.9.3 ; extra == 'tests'
11
- Requires-Dist: pytest ~=6.1 ; extra == 'tests'
12
- Requires-Dist: pytest-mock ~=3.6.1 ; extra == 'tests'
13
-
14
- # Microsoft Dataverse Source
15
-
16
- This is the repository for the Microsoft Dataverse source connector, written in Python.
17
- For information about how to use this connector within Airbyte, see [the documentation](https://docs.airbyte.io/integrations/sources/microsoft-dataverse).
18
-
19
-
20
- **To iterate on this connector, make sure to complete this prerequisites section.**
21
-
22
-
23
- From this connector directory, create a virtual environment:
24
- ```
25
- python -m venv .venv
26
- ```
27
-
28
- This will generate a virtualenv for this module in `.venv/`. Make sure this venv is active in your
29
- development environment of choice. To activate it from the terminal, run:
30
- ```
31
- source .venv/bin/activate
32
- pip install -r requirements.txt
33
- pip install '.[tests]'
34
- ```
35
- If you are in an IDE, follow your IDE's instructions to activate the virtualenv.
36
-
37
- Note that while we are installing dependencies from `requirements.txt`, you should only edit `setup.py` for your dependencies. `requirements.txt` is
38
- used for editable installs (`pip install -e`) to pull in Python dependencies from the monorepo and will call `setup.py`.
39
- If this is mumbo jumbo to you, don't worry about it, just put your deps in `setup.py` but install using `pip install -r requirements.txt` and everything
40
- should work as you expect.
41
-
42
- **If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.io/integrations/sources/microsoft-dataverse)
43
- to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_microsoft_dataverse/spec.yaml` file.
44
- Note that any directory named `secrets` is gitignored across the entire Airbyte repo, so there is no danger of accidentally checking in sensitive information.
45
- See `integration_tests/sample_config.json` for a sample config file.
46
-
47
- **If you are an Airbyte core member**, copy the credentials in Lastpass under the secret name `source microsoft-dataverse test creds`
48
- and place them into `secrets/config.json`.
49
-
50
- ```
51
- python main.py spec
52
- python main.py check --config secrets/config.json
53
- python main.py discover --config secrets/config.json
54
- python main.py read --config secrets/config.json --catalog integration_tests/configured_catalog.json
55
- ```
56
-
57
-
58
-
59
- **Via [`airbyte-ci`](https://github.com/airbytehq/airbyte/blob/master/airbyte-ci/connectors/pipelines/README.md) (recommended):**
60
- ```bash
61
- airbyte-ci connectors --name=source-microsoft-dataverse build
62
- ```
63
-
64
- An image will be built with the tag `airbyte/source-microsoft-dataverse:dev`.
65
-
66
- **Via `docker build`:**
67
- ```bash
68
- docker build -t airbyte/source-microsoft-dataverse:dev .
69
- ```
70
-
71
- Then run any of the connector commands as follows:
72
- ```
73
- docker run --rm airbyte/source-microsoft-dataverse:dev spec
74
- docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-microsoft-dataverse:dev check --config /secrets/config.json
75
- docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-microsoft-dataverse:dev discover --config /secrets/config.json
76
- docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/source-microsoft-dataverse:dev read --config /secrets/config.json --catalog /integration_tests/configured_catalog.json
77
- ```
78
-
79
- You can run our full test suite locally using [`airbyte-ci`](https://github.com/airbytehq/airbyte/blob/master/airbyte-ci/connectors/pipelines/README.md):
80
- ```bash
81
- airbyte-ci connectors --name=source-microsoft-dataverse test
82
- ```
83
-
84
- Customize `acceptance-test-config.yml` file to configure tests. See [Connector Acceptance Tests](https://docs.airbyte.com/connector-development/testing-connectors/connector-acceptance-tests-reference) for more information.
85
- If your connector requires to create or destroy resources for use during acceptance tests create fixtures for it and place them inside integration_tests/acceptance.py.
86
-
87
- All of your dependencies should go in `setup.py`, NOT `requirements.txt`. The requirements file is only used to connect internal Airbyte dependencies in the monorepo for local development.
88
- We split dependencies between two groups, dependencies that are:
89
- * required for your connector to work need to go to `MAIN_REQUIREMENTS` list.
90
- * required for the testing need to go to `TEST_REQUIREMENTS` list
91
-
92
- You've checked out the repo, implemented a million dollar feature, and you're ready to share your changes with the world. Now what?
93
- 1. Make sure your changes are passing our test suite: `airbyte-ci connectors --name=source-microsoft-dataverse test`
94
- 2. Bump the connector version in `metadata.yaml`: increment the `dockerImageTag` value. Please follow [semantic versioning for connectors](https://docs.airbyte.com/contributing-to-airbyte/resources/pull-requests-handbook/#semantic-versioning-for-connectors).
95
- 3. Make sure the `metadata.yaml` content is up to date.
96
- 4. Make the connector documentation and its changelog is up to date (`docs/integrations/sources/microsoft-dataverse.md`).
97
- 5. Create a Pull Request: use [our PR naming conventions](https://docs.airbyte.com/contributing-to-airbyte/resources/pull-requests-handbook/#pull-request-title-convention).
98
- 6. Pat yourself on the back for being an awesome contributor.
99
- 7. Someone from Airbyte will take a look at your PR and iterate with you to merge it into master.
@@ -1,23 +0,0 @@
1
- integration_tests/__init__.py,sha256=4Hw-PX1-VgESLF16cDdvuYCzGJtHntThLF4qIiULWeo,61
2
- integration_tests/abnormal_state.json,sha256=F6qYeCLpsXDWSWOK-t622dDz1MP7CPXE2Y-9SkoR-hk,82
3
- integration_tests/acceptance.py,sha256=8eU9iSDbmHyufPvAouJGhPMgPAFTCP8IKIKHLm7u5TE,435
4
- integration_tests/configured_catalog.json,sha256=rcfE_cGCXXSimwPslZwhSInofVYvIeIBVi_4wENH27I,347
5
- integration_tests/invalid_config.json,sha256=SudY8kGqvqyBULe1hYP46cIs8yKkLzTBEzVi_VNLvD8,161
6
- integration_tests/sample_config.json,sha256=uDZn5UrxyI_viuPhwIsldysAIOk5p4G0VF75hbsbEbs,154
7
- integration_tests/sample_state.json,sha256=DQ4W-RqAart9346ugzSN0d8hg87VK8Pi5BTaelkB9MI,82
8
- source_microsoft_dataverse/__init__.py,sha256=xy7FvZqZBBL0_I7mMd5ex5llLWTllG3HRt836ktTD7Q,148
9
- source_microsoft_dataverse/dataverse.py,sha256=HOQoA571fpy0Bxk4W9l3DttxX34sKkOjTWYeuwZ0uUA,2521
10
- source_microsoft_dataverse/run.py,sha256=hPGT5kR0LB6ZdKtLmwfLHymdF4EsDaFM2EC4J5ZAr3A,267
11
- source_microsoft_dataverse/source.py,sha256=7Z6f-FE9P2ycZlgdo5fVNYTlVKjKBiKqll3CMjp8IW4,4435
12
- source_microsoft_dataverse/spec.yaml,sha256=GmPlzh34HTII0aUW9XUbLxUk3VPEdvQ6E4iIKz4YMiA,1147
13
- source_microsoft_dataverse/streams.py,sha256=3PhAYr4kM2GjW4jPd-XGIwg0jqiECUyKUK9AJB9JQiw,6168
14
- unit_tests/__init__.py,sha256=4Hw-PX1-VgESLF16cDdvuYCzGJtHntThLF4qIiULWeo,61
15
- unit_tests/test_dataverse.py,sha256=yD1tuGjn_WcAFOcx-1Dp7SKTPfVQs_U0ANENd1fVyNE,525
16
- unit_tests/test_incremental_streams.py,sha256=gCr6fJb_b5U_iaQNRVGL0r5l0LM8GrKsIfj_Uz0pC90,3713
17
- unit_tests/test_source.py,sha256=yrVHvsNDgj5SPCG1T86j9Xa1Mb0HnIp-gG4xRGzY9wc,5019
18
- unit_tests/test_streams.py,sha256=jb4YG5e-V4KR2OZywE02KdRE92zQNENH5Q25zOUBsCs,3716
19
- airbyte_source_microsoft_dataverse-0.1.2.dist-info/METADATA,sha256=O2CwhyE4Q7pF6Gtv5oJz84cO8d9bNWoJKek5FMQijJA,5613
20
- airbyte_source_microsoft_dataverse-0.1.2.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
21
- airbyte_source_microsoft_dataverse-0.1.2.dist-info/entry_points.txt,sha256=uHN7NStTqslpZvvIOhjbOBOlLEmAQUFa6wj1zIxiazE,82
22
- airbyte_source_microsoft_dataverse-0.1.2.dist-info/top_level.txt,sha256=beuN6fxCEh7L4-h-9GvOc9cvtPyawVZBAhkxIAhs52c,56
23
- airbyte_source_microsoft_dataverse-0.1.2.dist-info/RECORD,,
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- source-microsoft-dataverse = source_microsoft_dataverse.run:run
@@ -1,3 +0,0 @@
1
- integration_tests
2
- source_microsoft_dataverse
3
- unit_tests
@@ -1,3 +0,0 @@
1
- #
2
- # Copyright (c) 2023 Airbyte, Inc., all rights reserved.
3
- #
@@ -1,5 +0,0 @@
1
- {
2
- "<entity_name>": {
3
- "$deltatoken": "12644418993!10/06/2050 20:06:12"
4
- }
5
- }
@@ -1,16 +0,0 @@
1
- #
2
- # Copyright (c) 2023 Airbyte, Inc., all rights reserved.
3
- #
4
-
5
-
6
- import pytest
7
-
8
- pytest_plugins = ("connector_acceptance_test.plugin",)
9
-
10
-
11
- @pytest.fixture(scope="session", autouse=True)
12
- def connector_setup():
13
- """This fixture is a placeholder for external resources that acceptance test might require."""
14
- # TODO: setup test dependencies if needed. otherwise remove the TODO comments
15
- yield
16
- # TODO: clean up test dependencies
@@ -1,15 +0,0 @@
1
- {
2
- "streams": [
3
- {
4
- "stream": {
5
- "name": "<entity_name>",
6
- "json_schema": {},
7
- "supported_sync_modes": ["full_refresh", "incremental"]
8
- },
9
- "cursor_field": ["modifiedon"],
10
- "primary_key": [["<entity_primary_key>"]],
11
- "sync_mode": "incremental",
12
- "destination_sync_mode": "append"
13
- }
14
- ]
15
- }
@@ -1,7 +0,0 @@
1
- {
2
- "client_id": "<client_id>",
3
- "tenant_id": "<tenant_id>",
4
- "client_secret_value": "<invalid_client_secret>",
5
- "url": "<url>",
6
- "odata.maxpagesize": 100
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "url": "<url>",
3
- "client_id": "<client_id>",
4
- "tenant_id": "<tenant_id>",
5
- "client_secret_value": "<client_secret>",
6
- "odata_maxpagesize": 5000
7
- }
@@ -1,5 +0,0 @@
1
- {
2
- "<entity_name>": {
3
- "$deltatoken": "12644418993!10/06/2022 20:06:12"
4
- }
5
- }
unit_tests/__init__.py DELETED
@@ -1,3 +0,0 @@
1
- #
2
- # Copyright (c) 2023 Airbyte, Inc., all rights reserved.
3
- #
@@ -1,15 +0,0 @@
1
- #
2
- # Copyright (c) 2023 Airbyte, Inc., all rights reserved.
3
- #
4
-
5
- import pytest
6
- from source_microsoft_dataverse.dataverse import AirbyteType, convert_dataverse_type
7
-
8
-
9
- @pytest.mark.parametrize(
10
- "dataverse_type,expected_result",
11
- [("String", AirbyteType.String.value), ("Integer", AirbyteType.Integer.value), ("Virtual", None), ("Random", AirbyteType.String.value)],
12
- )
13
- def test_convert_dataverse_type(dataverse_type, expected_result):
14
- result = convert_dataverse_type(dataverse_type)
15
- assert result == expected_result
@@ -1,101 +0,0 @@
1
- #
2
- # Copyright (c) 2023 Airbyte, Inc., all rights reserved.
3
- #
4
-
5
- from unittest.mock import MagicMock
6
-
7
- from pytest import fixture
8
- from source_microsoft_dataverse.source import IncrementalMicrosoftDataverseStream
9
-
10
-
11
- @fixture
12
- def incremental_config():
13
- return {
14
- "url": "http://test-url",
15
- "stream_name": "test_stream",
16
- "stream_path": "test_path",
17
- "primary_key": [["test_primary_key"]],
18
- "schema": {},
19
- "odata_maxpagesize": 100,
20
- "config_cursor_field": ["test_cursor_field"],
21
- "authenticator": MagicMock(),
22
- }
23
-
24
-
25
- @fixture
26
- def incremental_response(incremental_config):
27
- return {
28
- "@odata.deltaLink": f"{incremental_config['url']}?$deltatoken=12644418993%2110%2F06%2F2022%2020%3A06%3A12",
29
- "value": [
30
- {"test_primary_key": "pk", "test_cursor_field": "test-date"},
31
- {"id": "pk2", "@odata.context": "context", "reason": "deleted"},
32
- ],
33
- }
34
-
35
-
36
- def test_primary_key(incremental_config):
37
- stream = IncrementalMicrosoftDataverseStream(**incremental_config)
38
- expected_primary_key = [["test_primary_key"]]
39
- assert stream.primary_key == expected_primary_key
40
-
41
-
42
- def test_stream_name(incremental_config):
43
- stream = IncrementalMicrosoftDataverseStream(**incremental_config)
44
- expected_stream_name = "test_stream"
45
- assert stream.name == expected_stream_name
46
-
47
-
48
- def test_stream_path(incremental_config):
49
- stream = IncrementalMicrosoftDataverseStream(**incremental_config)
50
- expected_stream_path = "test_path"
51
- assert stream.path() == expected_stream_path
52
-
53
-
54
- def test_cursor_field(incremental_config):
55
- stream = IncrementalMicrosoftDataverseStream(**incremental_config)
56
- expected_cursor_field = ["test_cursor_field"]
57
- assert stream.cursor_field == expected_cursor_field
58
-
59
-
60
- def test_supports_incremental(incremental_config, mocker):
61
- mocker.patch.object(IncrementalMicrosoftDataverseStream, "cursor_field", "dummy_field")
62
- stream = IncrementalMicrosoftDataverseStream(**incremental_config)
63
- assert stream.supports_incremental
64
-
65
-
66
- def test_source_defined_cursor(incremental_config):
67
- stream = IncrementalMicrosoftDataverseStream(**incremental_config)
68
- assert stream.source_defined_cursor
69
-
70
-
71
- def test_stream_checkpoint_interval(incremental_config):
72
- stream = IncrementalMicrosoftDataverseStream(**incremental_config)
73
- expected_checkpoint_interval = None
74
- assert stream.state_checkpoint_interval == expected_checkpoint_interval
75
-
76
-
77
- def test_parse_request(incremental_config, incremental_response, mocker):
78
- response_mock, datetime_mock = MagicMock(), MagicMock()
79
- response_mock.json.return_value = incremental_response
80
- datetime_mock.now.return_value.isoformat.return_value = "test-time"
81
- mocker.patch("source_microsoft_dataverse.streams.datetime", datetime_mock)
82
-
83
- stream = IncrementalMicrosoftDataverseStream(**incremental_config)
84
-
85
- iterable = stream.parse_response(response_mock)
86
- iterable_list = list(iterable)
87
- assert len(iterable_list) == 2
88
- assert stream.state[stream.delta_token_field] == "12644418993!10/06/2022 20:06:12"
89
- assert iterable_list[0]["_ab_cdc_updated_at"] == "test-date"
90
- assert iterable_list[1]["_ab_cdc_deleted_at"] == "test-time"
91
- assert iterable_list[1][incremental_config["primary_key"][0][0]] == "pk2"
92
- assert "id" not in iterable_list[1]
93
- assert "reason" not in iterable_list[1]
94
- assert "@odata.context" not in iterable_list[1]
95
-
96
-
97
- def test_request_headers(incremental_config):
98
- stream = IncrementalMicrosoftDataverseStream(**incremental_config)
99
- headers = stream.request_headers(stream_state={})
100
- assert "Prefer" in headers
101
- assert headers["Prefer"] == "odata.track-changes,odata.maxpagesize=100"
unit_tests/test_source.py DELETED
@@ -1,148 +0,0 @@
1
- #
2
- # Copyright (c) 2023 Airbyte, Inc., all rights reserved.
3
- #
4
-
5
- import json
6
- from unittest import mock
7
- from unittest.mock import MagicMock
8
-
9
- from airbyte_cdk.models import SyncMode
10
- from source_microsoft_dataverse.dataverse import AirbyteType
11
- from source_microsoft_dataverse.source import SourceMicrosoftDataverse
12
- from source_microsoft_dataverse.streams import IncrementalMicrosoftDataverseStream, MicrosoftDataverseStream
13
-
14
-
15
- @mock.patch("source_microsoft_dataverse.source.do_request")
16
- def test_check_connection(mock_request):
17
- mock_request.return_value.raise_for_status = lambda: ()
18
- source = SourceMicrosoftDataverse()
19
- logger_mock, config_mock = MagicMock(), MagicMock()
20
- assert source.check_connection(logger_mock, config_mock) == (True, None)
21
-
22
-
23
- @mock.patch("source_microsoft_dataverse.source.get_auth")
24
- @mock.patch("source_microsoft_dataverse.source.do_request")
25
- def test_streams_incremental(mock_get_auth, mock_request):
26
- streams = MagicMock()
27
- streams.sync_mode = SyncMode.incremental
28
- streams.stream.name = "test"
29
-
30
- catalog = MagicMock()
31
-
32
- catalog.streams = [streams]
33
-
34
- config_mock = MagicMock()
35
- source = SourceMicrosoftDataverse()
36
- source.catalogs = catalog
37
-
38
- streams = source.streams(config_mock)
39
-
40
- expected_streams_number = 1
41
- assert len(streams) == expected_streams_number
42
- assert isinstance(streams[0], IncrementalMicrosoftDataverseStream)
43
- assert streams[0].name == "test"
44
-
45
-
46
- @mock.patch("source_microsoft_dataverse.source.get_auth")
47
- @mock.patch("source_microsoft_dataverse.source.do_request")
48
- def test_streams_full_refresh(mock_get_auth, mock_request):
49
- streams = MagicMock()
50
- streams.sync_mode = SyncMode.full_refresh
51
- streams.stream.name = "test"
52
-
53
- catalog = MagicMock()
54
-
55
- catalog.streams = [streams]
56
-
57
- config_mock = MagicMock()
58
- source = SourceMicrosoftDataverse()
59
- source.catalogs = catalog
60
-
61
- streams = source.streams(config_mock)
62
-
63
- expected_streams_number = 1
64
- assert len(streams) == expected_streams_number
65
- assert isinstance(streams[0], MicrosoftDataverseStream)
66
- assert streams[0].name == "test"
67
-
68
-
69
- @mock.patch("source_microsoft_dataverse.source.do_request")
70
- def test_discover_incremental(mock_request):
71
- result_json = json.loads(
72
- """
73
- {
74
- "value": [
75
- {
76
- "LogicalName": "stream",
77
- "PrimaryIdAttribute": "primary",
78
- "ChangeTrackingEnabled": true,
79
- "CanChangeTrackingBeEnabled": {
80
- "Value": true
81
- },
82
- "Attributes": [
83
- {
84
- "LogicalName": "test",
85
- "AttributeType": "String"
86
- },
87
- {
88
- "LogicalName": "modifiedon",
89
- "AttributeType": "DateTime"
90
- }
91
- ]
92
- }
93
- ]
94
- }
95
- """
96
- )
97
-
98
- mock_request.return_value.status.return_value = 200
99
- mock_request.return_value.json.return_value = result_json
100
-
101
- source = SourceMicrosoftDataverse()
102
- logger_mock, config_mock = MagicMock(), MagicMock()
103
-
104
- catalog = source.discover(logger_mock, config_mock)
105
-
106
- assert not {"modifiedon"} ^ set(catalog.streams[0].default_cursor_field)
107
- assert not {SyncMode.full_refresh, SyncMode.incremental} ^ set(catalog.streams[0].supported_sync_modes)
108
- assert not {"primary"} ^ set(catalog.streams[0].source_defined_primary_key[0])
109
- assert catalog.streams[0].json_schema["properties"]["test"] == AirbyteType.String.value
110
-
111
-
112
- @mock.patch("source_microsoft_dataverse.source.do_request")
113
- def test_discover_full_refresh(mock_request):
114
- result_json = json.loads(
115
- """
116
- {
117
- "value": [
118
- {
119
- "LogicalName": "stream",
120
- "PrimaryIdAttribute": "primary",
121
- "ChangeTrackingEnabled": false,
122
- "CanChangeTrackingBeEnabled": {
123
- "Value": false
124
- },
125
- "Attributes": [
126
- {
127
- "LogicalName": "test",
128
- "AttributeType": "String"
129
- }
130
- ]
131
- }
132
- ]
133
- }
134
- """
135
- )
136
-
137
- mock_request.return_value.status.return_value = 200
138
- mock_request.return_value.json.return_value = result_json
139
-
140
- source = SourceMicrosoftDataverse()
141
- logger_mock, config_mock = MagicMock(), MagicMock()
142
-
143
- catalog = source.discover(logger_mock, config_mock)
144
-
145
- assert catalog.streams[0].default_cursor_field is None or len(catalog.streams[0].default_cursor_field) == 0
146
- assert not {SyncMode.full_refresh} ^ set(catalog.streams[0].supported_sync_modes)
147
- assert not {"primary"} ^ set(catalog.streams[0].source_defined_primary_key[0])
148
- assert catalog.streams[0].json_schema["properties"]["test"] == AirbyteType.String.value
@@ -1,107 +0,0 @@
1
- #
2
- # Copyright (c) 2023 Airbyte, Inc., all rights reserved.
3
- #
4
-
5
- from http import HTTPStatus
6
- from unittest.mock import MagicMock
7
-
8
- import pytest
9
- from pytest import fixture
10
- from source_microsoft_dataverse.source import MicrosoftDataverseStream
11
-
12
-
13
- @fixture
14
- def incremental_config():
15
- return {
16
- "url": "http://test-url",
17
- "stream_name": "test_stream",
18
- "stream_path": "test_path",
19
- "primary_key": [["test_primary_key"]],
20
- "schema": {},
21
- "odata_maxpagesize": 100,
22
- "authenticator": MagicMock(),
23
- }
24
-
25
-
26
- @pytest.mark.parametrize(
27
- ("inputs", "expected_params"),
28
- [
29
- ({"stream_slice": None, "stream_state": {}, "next_page_token": None}, {}),
30
- ({"stream_slice": None, "stream_state": {}, "next_page_token": {"$skiptoken": "skiptoken"}}, {"$skiptoken": "skiptoken"}),
31
- ({"stream_slice": None, "stream_state": {"$deltatoken": "delta"}, "next_page_token": None}, {"$deltatoken": "delta"}),
32
- ],
33
- )
34
- def test_request_params(inputs, expected_params, incremental_config):
35
- stream = MicrosoftDataverseStream(**incremental_config)
36
- assert stream.request_params(**inputs) == expected_params
37
-
38
-
39
- @pytest.mark.parametrize(
40
- ("response_json", "next_page_token"),
41
- [
42
- (
43
- {
44
- "@odata.nextLink": "https://url?$skiptoken=oEBwdSP6uehIAxQOWq_3Ksh_TLol6KIm3stvdc6hGhZRi1hQ7Spe__dpvm3U4zReE4CYXC2zOtaKdi7KHlUtC2CbRiBIUwOxPKLa"
45
- },
46
- {"$skiptoken": "oEBwdSP6uehIAxQOWq_3Ksh_TLol6KIm3stvdc6hGhZRi1hQ7Spe__dpvm3U4zReE4CYXC2zOtaKdi7KHlUtC2CbRiBIUwOxPKLa"},
47
- ),
48
- ({"value": []}, None),
49
- ],
50
- )
51
- def test_next_page_token(response_json, next_page_token, incremental_config):
52
- stream = MicrosoftDataverseStream(**incremental_config)
53
- response = MagicMock()
54
- response.json.return_value = response_json
55
- inputs = {"response": response}
56
- expected_token = next_page_token
57
- assert stream.next_page_token(**inputs) == expected_token
58
-
59
-
60
- def test_parse_response(incremental_config):
61
- stream = MicrosoftDataverseStream(**incremental_config)
62
- response = MagicMock()
63
- response.json.return_value = {"value": [{"test-key": "test-value"}]}
64
- inputs = {"response": response}
65
- expected_parsed_object = {"test-key": "test-value"}
66
- assert next(stream.parse_response(**inputs)) == expected_parsed_object
67
-
68
-
69
- def test_request_headers(incremental_config):
70
- stream = MicrosoftDataverseStream(**incremental_config)
71
- inputs = {"stream_slice": None, "stream_state": None, "next_page_token": None}
72
- expected_headers = {
73
- "Cache-Control": "no-cache",
74
- "OData-Version": "4.0",
75
- "Content-Type": "application/json",
76
- "Prefer": "odata.maxpagesize=100",
77
- }
78
- assert stream.request_headers(**inputs) == expected_headers
79
-
80
-
81
- def test_http_method(incremental_config):
82
- stream = MicrosoftDataverseStream(**incremental_config)
83
- expected_method = "GET"
84
- assert stream.http_method == expected_method
85
-
86
-
87
- @pytest.mark.parametrize(
88
- ("http_status", "should_retry"),
89
- [
90
- (HTTPStatus.OK, False),
91
- (HTTPStatus.BAD_REQUEST, False),
92
- (HTTPStatus.TOO_MANY_REQUESTS, True),
93
- (HTTPStatus.INTERNAL_SERVER_ERROR, True),
94
- ],
95
- )
96
- def test_should_retry(incremental_config, http_status, should_retry):
97
- response_mock = MagicMock()
98
- response_mock.status_code = http_status
99
- stream = MicrosoftDataverseStream(**incremental_config)
100
- assert stream.should_retry(response_mock) == should_retry
101
-
102
-
103
- def test_backoff_time(incremental_config):
104
- response_mock = MagicMock()
105
- stream = MicrosoftDataverseStream(**incremental_config)
106
- expected_backoff_time = None
107
- assert stream.backoff_time(response_mock) == expected_backoff_time