Skip to content

Commit 359d846

Browse files
btkcodedevmarcosmarxmsajarin
authored
✨Source MailGun: Migrate Python CDK to Low-code CDK (#29122)
Co-authored-by: Marcos Marx <marcosmarxm@users.noreply.github.com> Co-authored-by: Sajarin <sajarindider@gmail.com>
1 parent cc43bd7 commit 359d846

28 files changed

+248
-819
lines changed

airbyte-integrations/connectors/source-mailgun/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ COPY source_mailgun ./source_mailgun
3434
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
3535
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]
3636

37-
LABEL io.airbyte.version=0.1.1
37+
LABEL io.airbyte.version=0.2.0
3838
LABEL io.airbyte.name=airbyte/source-mailgun

airbyte-integrations/connectors/source-mailgun/README.md

Lines changed: 8 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,10 @@
11
# Mailgun Source
22

3-
This is the repository for the Mailgun source connector, written in Python.
4-
For information about how to use this connector within Airbyte, see [the documentation](https://docs.airbyte.io/integrations/sources/mailgun).
3+
This is the repository for the Mailgun configuration based source connector.
4+
For information about how to use this connector within Airbyte, see [the documentation](https://docs.airbyte.com/integrations/sources/mailgun).
55

66
## Local development
77

8-
### Prerequisites
9-
**To iterate on this connector, make sure to complete this prerequisites section.**
10-
11-
#### Minimum Python version required `= 3.7.0`
12-
13-
#### Build & Activate Virtual Environment and install dependencies
14-
From this connector directory, create a virtual environment:
15-
```
16-
python -m venv .venv
17-
```
18-
19-
This will generate a virtualenv for this module in `.venv/`. Make sure this venv is active in your
20-
development environment of choice. To activate it from the terminal, run:
21-
```
22-
source .venv/bin/activate
23-
pip install -r requirements.txt
24-
pip install '.[tests]'
25-
```
26-
If you are in an IDE, follow your IDE's instructions to activate the virtualenv.
27-
28-
Note that while we are installing dependencies from `requirements.txt`, you should only edit `setup.py` for your dependencies. `requirements.txt` is
29-
used for editable installs (`pip install -e`) to pull in Python dependencies from the monorepo and will call `setup.py`.
30-
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
31-
should work as you expect.
32-
338
#### Building via Gradle
349
You can also build the connector in Gradle. This is typically used in CI and not needed for your development workflow.
3510

@@ -39,22 +14,14 @@ To build using Gradle, from the Airbyte repository root, run:
3914
```
4015

4116
#### Create credentials
42-
**If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.io/integrations/sources/mailgun)
43-
to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_mailgun/spec.json` file.
17+
**If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.com/integrations/sources/mailgun)
18+
to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_mailgun/spec.yaml` file.
4419
Note that any directory named `secrets` is gitignored across the entire Airbyte repo, so there is no danger of accidentally checking in sensitive information.
4520
See `integration_tests/sample_config.json` for a sample config file.
4621

4722
**If you are an Airbyte core member**, copy the credentials in Lastpass under the secret name `source mailgun test creds`
4823
and place them into `secrets/config.json`.
4924

50-
### Locally running the connector
51-
```
52-
python main.py spec
53-
python main.py check --config secrets/config.json
54-
python main.py discover --config secrets/config.json
55-
python main.py read --config secrets/config.json --catalog integration_tests/configured_catalog.json
56-
```
57-
5825
### Locally running the connector docker image
5926

6027
#### Build
@@ -79,32 +46,15 @@ docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-mailgun:dev discover -
7946
docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/source-mailgun:dev read --config /secrets/config.json --catalog /integration_tests/configured_catalog.json
8047
```
8148
## Testing
82-
Make sure to familiarize yourself with [pytest test discovery](https://docs.pytest.org/en/latest/goodpractices.html#test-discovery) to know how your test files and methods should be named.
83-
First install test dependencies into your virtual environment:
84-
```
85-
pip install .[tests]
86-
```
87-
### Unit Tests
88-
To run unit tests locally, from the connector directory run:
89-
```
90-
python -m pytest unit_tests
91-
```
9249

93-
### Integration Tests
94-
There are two types of integration tests: Acceptance Tests (Airbyte's test suite for all source connectors) and custom integration tests (which are specific to this connector).
95-
#### Custom Integration tests
96-
Place custom tests inside `integration_tests/` folder, then, from the connector root, run
97-
```
98-
python -m pytest integration_tests
99-
```
10050
#### Acceptance Tests
101-
Customize `acceptance-test-config.yml` file to configure tests. See [Connector Acceptance Tests](https://docs.airbyte.io/connector-development/testing-connectors/connector-acceptance-tests-reference) for more information.
51+
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.
10252
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.
103-
To run your integration tests with acceptance tests, from the connector root, run
53+
54+
To run your integration tests with Docker, run:
10455
```
105-
python -m pytest integration_tests -p integration_tests.acceptance
56+
./acceptance-test-docker.sh
10657
```
107-
To run your integration tests with docker
10858

10959
### Using gradle to run tests
11060
All commands should be run from airbyte project root.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#
2+
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
3+
#
Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,41 @@
1-
# See [Connector Acceptance Tests](https://docs.airbyte.com/connector-development/testing-connectors/connector-acceptance-tests-reference)
2-
# for more information about how to configure these tests
31
connector_image: airbyte/source-mailgun:dev
4-
tests:
2+
acceptance_tests:
53
spec:
6-
- spec_path: "source_mailgun/spec.json"
4+
tests:
5+
- spec_path: "source_mailgun/spec.yaml"
6+
backward_compatibility_tests_config:
7+
disable_for_version: 0.1.1
78
connection:
8-
- config_path: "secrets/config.json"
9-
status: "succeed"
10-
- config_path: "integration_tests/invalid_config.json"
11-
status: "failed"
9+
tests:
10+
- config_path: "secrets/config.json"
11+
status: "succeed"
12+
- config_path: "integration_tests/invalid_config.json"
13+
status: "failed"
1214
discovery:
13-
- config_path: "secrets/config.json"
15+
tests:
16+
- config_path: "secrets/config.json"
17+
backward_compatibility_tests_config:
18+
disable_for_version: 0.1.1
1419
basic_read:
15-
- config_path: "secrets/config.json"
16-
configured_catalog_path: "integration_tests/configured_catalog.json"
17-
empty_streams: []
18-
incremental:
19-
- config_path: "secrets/config.json"
20-
configured_catalog_path: "integration_tests/configured_catalog.json"
21-
future_state_path: "integration_tests/abnormal_state.json"
20+
tests:
21+
- config_path: "secrets/config.json"
22+
configured_catalog_path: "integration_tests/configured_catalog.json"
23+
empty_streams:
24+
- name: events
25+
bypass_reason: "Sandbox account can't seed this stream"
26+
# expect_records:
27+
# path: "integration_tests/expected_records.jsonl"
28+
# extra_fields: no
29+
# exact_order: no
30+
# extra_records: yes
31+
incremental:
32+
bypass_reason: "This connector does not implement incremental sync"
33+
# tests:
34+
# - config_path: "secrets/config.json"
35+
# configured_catalog_path: "integration_tests/configured_catalog.json"
36+
# future_state:
37+
# future_state_path: "integration_tests/abnormal_state.json"
2238
full_refresh:
23-
- config_path: "secrets/config.json"
24-
configured_catalog_path: "integration_tests/configured_catalog.json"
39+
tests:
40+
- config_path: "secrets/config.json"
41+
configured_catalog_path: "integration_tests/configured_catalog.json"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
#!/usr/bin/env sh
2+
23
source "$(git rev-parse --show-toplevel)/airbyte-integrations/bases/connector-acceptance-test/acceptance-test-docker.sh"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#
2-
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
2+
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
33
#

airbyte-integrations/connectors/source-mailgun/integration_tests/acceptance.py

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,12 @@
22
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
33
#
44

5-
import datetime
6-
import json
7-
import os.path
8-
from typing import Any, Dict, Iterable
95

106
import pytest
117

12-
from .fill_data import DataFiller
13-
148
pytest_plugins = ("connector_acceptance_test.plugin",)
159

1610

17-
class Config:
18-
19-
messages_per_sender: int = 5
20-
min_update_interval: int = datetime.timedelta(2).total_seconds() # 2 days
21-
22-
recipients: Iterable[str] = [
23-
"integration-test@airbyte.io",
24-
]
25-
senders: Iterable[str] = [
26-
"Ann",
27-
"Bob",
28-
"Carl",
29-
]
30-
31-
test_data_file_path: str = os.path.join(os.path.dirname(__file__), "test_data.json")
32-
33-
@classmethod
34-
def get_test_data(cls) -> Dict[str, Any]:
35-
with open(cls.test_data_file_path) as tdf:
36-
return json.load(tdf)
37-
38-
@classmethod
39-
def update_timestamp(cls, timestamp: float):
40-
test_data = cls.get_test_data()
41-
test_data.update({"last_update_timestamp": timestamp})
42-
with open(cls.test_data_file_path, "w") as tdf:
43-
json.dump(test_data, tdf)
44-
45-
4611
@pytest.fixture(scope="session", autouse=True)
4712
def connector_setup():
48-
"""
49-
Fill the sandbox with fresh data by sending simple text-only messages.
50-
"""
51-
config = Config
52-
now = datetime.datetime.now().timestamp()
53-
if config.get_test_data()["last_update_timestamp"] + config.min_update_interval <= now:
54-
data_filler: DataFiller = DataFiller(
55-
from_emails=config.senders, to=config.recipients, number_of_messages=config.messages_per_sender
56-
)
57-
data_filler.fill()
58-
config.update_timestamp(now)
59-
6013
yield

airbyte-integrations/connectors/source-mailgun/integration_tests/fill_data.py

Lines changed: 0 additions & 91 deletions
This file was deleted.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
{
2-
"private_key": "test-api-key"
2+
"private_key": "xxx17ec8cf955c450b20d02454d04xxxxxxx34xxxxxxx9dxxx",
3+
"domain_region": "us",
4+
"start_date": "2023-08-01T00:00:00Z"
35
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"todo-stream-name": {
3+
"todo-field-name": "value"
4+
}
5+
}

0 commit comments

Comments
 (0)