Skip to content

Commit

Permalink
🎉 Source Mixpanel: Increase unit test coverage (#11633)
Browse files Browse the repository at this point in the history
  • Loading branch information
itaseskii authored Apr 15, 2022
1 parent dbe2439 commit e4a55a4
Show file tree
Hide file tree
Showing 11 changed files with 378 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@
- name: Mixpanel
sourceDefinitionId: 12928b32-bf0a-4f1e-964f-07e12e37153a
dockerRepository: airbyte/source-mixpanel
dockerImageTag: 0.1.11
dockerImageTag: 0.1.12
documentationUrl: https://docs.airbyte.io/integrations/sources/mixpanel
icon: mixpanel.svg
sourceType: api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5004,7 +5004,7 @@
path_in_connector_config:
- "credentials"
- "client_secret"
- dockerImage: "airbyte/source-mixpanel:0.1.11"
- dockerImage: "airbyte/source-mixpanel:0.1.12"
spec:
documentationUrl: "https://docs.airbyte.io/integrations/sources/mixpanel"
connectionSpecification:
Expand Down
3 changes: 2 additions & 1 deletion airbyte-integrations/connectors/source-mixpanel/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ RUN pip install .
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.1.11

LABEL io.airbyte.version=0.1.12
LABEL io.airbyte.name=airbyte/source-mixpanel
2 changes: 2 additions & 0 deletions airbyte-integrations/connectors/source-mixpanel/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
TEST_REQUIREMENTS = [
"pytest~=6.1",
"source-acceptance-test",
"pytest-mock~=3.6",
"requests_mock~=1.8"
]

setup(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -804,9 +804,9 @@ def check_connection(self, logger: AirbyteLogger, config: Mapping[str, Any]) ->
:param logger: logger object
:return Tuple[bool, any]: (True, None) if the input config can be used to connect to the API successfully, (False, error) otherwise.
"""
auth = TokenAuthenticatorBase64(token=config["api_secret"])
funnels = FunnelsList(authenticator=auth, **config)
try:
auth = TokenAuthenticatorBase64(token=config["api_secret"])
funnels = FunnelsList(authenticator=auth, **config)
response = requests.request(
"GET",
url=funnels.url_base + funnels.path(),
Expand All @@ -827,6 +827,7 @@ def check_connection(self, logger: AirbyteLogger, config: Mapping[str, Any]) ->

return True, None


def streams(self, config: Mapping[str, Any]) -> List[Stream]:
"""
:param config: A Mapping of the user input configuration as defined in the connector spec.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
#
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
#
import pendulum
import pytest


@pytest.fixture
def config():
return {
"api_secret": "unexisting-secret",
"attribution_window": 5,
"project_timezone": "UTC",
"select_properties_by_default": True,
"start_date": pendulum.parse("2017-01-25T00:00:00Z").date(),
"end_date": pendulum.parse("2017-02-25T00:00:00Z").date(),
"region": "US",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
#
import pytest
from airbyte_cdk import AirbyteLogger
from source_mixpanel.source import FunnelsList, SourceMixpanel, TokenAuthenticatorBase64

from .utils import get_url_to_mock, setup_response

logger = AirbyteLogger()


@pytest.fixture
def check_connection_url(config):
auth = TokenAuthenticatorBase64(token=config["api_secret"])
funnel_list = FunnelsList(authenticator=auth, **config)
return get_url_to_mock(funnel_list)


@pytest.mark.parametrize("response_code,expect_success", [(200, True), (400, False)])
def test_check_connection(requests_mock, check_connection_url, config, response_code, expect_success):
requests_mock.register_uri("GET", check_connection_url, setup_response(response_code, {}))
ok, error = SourceMixpanel().check_connection(logger, config)
assert ok == expect_success and error != expect_success


def test_check_connection_bad_config():
config = {}
ok, error = SourceMixpanel().check_connection(logger, config)
assert not ok and error


def test_check_connection_incomplete(config):
config.pop("api_secret")
ok, error = SourceMixpanel().check_connection(logger, config)
assert not ok and error


def test_streams(config):
streams = SourceMixpanel().streams(config)
assert len(streams) == 7
Loading

0 comments on commit e4a55a4

Please sign in to comment.