Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Source Google Analytics v4: Fix validation of empty custom reports issue #5655

Merged
merged 3 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"sourceDefinitionId": "eff3616a-f9c3-11eb-9a03-0242ac130003",
"name": "Google Analytics v4",
"dockerRepository": "airbyte/source-google-analytics-v4",
"dockerImageTag": "0.1.0",
"dockerImageTag": "0.1.1",
"documentationUrl": "https://docs.airbyte.io/integrations/sources/source-google-analytics-v4",
"icon": "google-analytics.svg"
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
- sourceDefinitionId: eff3616a-f9c3-11eb-9a03-0242ac130003
name: Google Analytics v4
dockerRepository: airbyte/source-google-analytics-v4
dockerImageTag: 0.1.0
dockerImageTag: 0.1.1
documentationUrl: https://docs.airbyte.io/integrations/sources/source-google-analytics-v4
icon: google-analytics.svg
- sourceDefinitionId: e7778cfc-e97c-4458-9ecb-b4f2bba8946c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ 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.0
LABEL io.airbyte.version=0.1.1
LABEL io.airbyte.name=airbyte/source-google-analytics-v4
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
TEST_REQUIREMENTS = [
"pytest~=6.1",
"requests-mock",
"pytest-mock",
"source-acceptance-test",
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,14 @@ def streams(self, config: Mapping[str, Any]) -> List[Stream]:
authenticator = GoogleAnalyticsOauth2Authenticator(config)

config["authenticator"] = authenticator
config["ga_streams"] = json.loads(pkgutil.get_data("source_google_analytics_v4", "defaults/default_reports.json")) + json.loads(
config["custom_reports"]
)

reports = json.loads(pkgutil.get_data("source_google_analytics_v4", "defaults/default_reports.json"))

if config.get("custom_reports"):
custom_reports = json.loads(config["custom_reports"])
reports += custom_reports

config["ga_streams"] = reports

for stream in config["ga_streams"]:
config["metrics"] = stream["metrics"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@

import json
from pathlib import Path
from unittest.mock import MagicMock, patch

import pytest
from airbyte_cdk.sources.streams.http.auth import NoAuth
from source_google_analytics_v4.source import GoogleAnalyticsV4Stream, GoogleAnalyticsV4TypesList
from source_google_analytics_v4.source import GoogleAnalyticsV4Stream, GoogleAnalyticsV4TypesList, SourceGoogleAnalyticsV4


def read_file(file_name):
Expand Down Expand Up @@ -76,3 +77,24 @@ def test_lookup_metrics_dimensions_data_type(metrics_dimensions_mapping, mock_me
test = g.lookup_data_type(field_type, attribute)

assert test == expected


class GoogleAnalyticsOauth2AuthenticatorMock:
def refresh_access_token(self):
return MagicMock(), 0


@patch(
"source_google_analytics_v4.source.GoogleAnalyticsOauth2Authenticator.refresh_access_token",
new=GoogleAnalyticsOauth2AuthenticatorMock.refresh_access_token,
)
def test_check_connection(mocker, mock_metrics_dimensions_type_list_link):
test_config = json.loads(read_file("../integration_tests/sample_config.json"))
test_config["credentials_json"] = '{"client_email": "", "private_key": "", "private_key_id": ""}'

del test_config["custom_reports"]

source = SourceGoogleAnalyticsV4()
logger_mock, config_mock = MagicMock(), test_config

assert source.check_connection(logger_mock, config_mock) == (True, None)
1 change: 1 addition & 0 deletions docs/integrations/sources/google-analytics-v4.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,5 @@ Incremental sync supports only if you add `ga:date` dimension to your custom rep

| Version | Date | Pull Request | Subject |
| :------ | :-------- | :----- | :------ |
| 0.1.1 | 2021-08-25 | [5655](https://github.com/airbytehq/airbyte/pull/5655) | Corrected validation of empty custom report|
| 0.1.0 | 2021-08-10 | [5290](https://github.com/airbytehq/airbyte/pull/5290) | Initial Release|