Skip to content

Commit

Permalink
Marcos/test pr 6054 (#6581)
Browse files Browse the repository at this point in the history
* Added optional end_date configuration to source-facebook-marketing connector.

* Update airbyte-integrations/connectors/source-facebook-marketing/integration_tests/spec.json

Co-authored-by: Eugene Kulak <widowmakerreborn@gmail.com>

* add AdCreative

* correct spec json and source.py

* test default factory

* add default_factory pendulum.now

* update sherif comments

* run gradlew format

* resolve conflict

* run format

Co-authored-by: Darian Heede <darian.heede@getmercury.io>
Co-authored-by: Darian <33750174+darian-heede@users.noreply.github.com>
Co-authored-by: Eugene Kulak <widowmakerreborn@gmail.com>
  • Loading branch information
4 people committed Oct 6, 2021
1 parent a319642 commit f4ba6c0
Show file tree
Hide file tree
Showing 8 changed files with 412 additions and 1,050 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
},
"end_date": {
"title": "End Date",
"description": "The end date until which you'd like to replicate data for AdCreatives and AdInsights APIs, in the format YYYY-MM-DDT00:00:00Z. All data generated between start_date and this date will be replicated.",
"description": "The date until which you'd like to replicate data for AdCreatives and AdInsights APIs, in the format YYYY-MM-DDT00:00:00Z. All data generated between start_date and this date will be replicated. Not setting this option will result in always syncing the latest data.",
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$",
"examples": ["2017-01-25T00:00:00Z"],
"examples": ["2017-01-26T00:00:00Z"],
"type": "string",
"format": "date-time"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"start_date": "2020-09-25T00:00:00Z",
"end_date": "2021-01-01T00:00:00Z",
"account_id": "<YOUR_ACCOUNT_ID_HERE>",
"access_token": "<YOUR_TOKEN_HERE>"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#

from datetime import datetime
import pendulum
from typing import Any, List, Mapping, Tuple, Type
from typing import Any, List, Mapping, Optional, Tuple, Type

import pendulum
from airbyte_cdk.models import AuthSpecification, ConnectorSpecification, DestinationSyncMode, OAuth2Specification
from airbyte_cdk.sources import AbstractSource
from airbyte_cdk.sources.streams import Stream
Expand Down Expand Up @@ -43,14 +43,13 @@ class Config:
examples=["2017-01-25T00:00:00Z"],
)

end_date: datetime = Field(
default=pendulum.now(),
description="The date until which you'd like to replicate data for AdCreatives and AdInsights APIs, in the format YYYY-MM-DDT00:00:00Z. All data generated between start_date and this date will be replicated. Not setting this option will result in always syncing the latest data. ",
end_date: Optional[datetime] = Field(
description="The date until which you'd like to replicate data for AdCreatives and AdInsights APIs, in the format YYYY-MM-DDT00:00:00Z. All data generated between start_date and this date will be replicated. Not setting this option will result in always syncing the latest data.",
pattern="^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$",
examples=["2017-01-26T00:00:00Z"],
default_factory=pendulum.now,
)


include_deleted: bool = Field(default=False, description="Include data from deleted campaigns, ads, and adsets.")

insights_lookback_window: int = Field(
Expand Down Expand Up @@ -96,6 +95,7 @@ def streams(self, config: Mapping[str, Any]) -> List[Type[Stream]]:
"""
config: ConnectorConfig = ConnectorConfig.parse_obj(config) # FIXME: this will be not need after we fix CDK
api = API(account_id=config.account_id, access_token=config.access_token)

insights_args = dict(
api=api,
start_date=config.start_date,
Expand All @@ -107,7 +107,8 @@ def streams(self, config: Mapping[str, Any]) -> List[Type[Stream]]:
return [
Campaigns(api=api, start_date=config.start_date, end_date=config.end_date, include_deleted=config.include_deleted),
AdSets(api=api, start_date=config.start_date, end_date=config.end_date, include_deleted=config.include_deleted),
Ads(api=api, start_date=config.start_date, end_date=config.end_date, include_deleted=config.include_deleted),
Ads(api=api, start_date=config.start_date, end_date=config.end_date, include_deleted=config.include_deleted),
AdCreatives(api=api),
AdsInsights(**insights_args),
AdsInsightsAgeAndGender(**insights_args),
AdsInsightsCountry(**insights_args),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_limit_reached(self, requests_mock, api, fb_call_rate_response, account_
requests_mock.register_uri("GET", FacebookSession.GRAPH + f"/{FB_API_VERSION}/1/", [{"status_code": 200}])
requests_mock.register_uri("GET", FacebookSession.GRAPH + f"/{FB_API_VERSION}/2/", [{"status_code": 200}])

stream = Campaigns(api=api, start_date=datetime.now(), end_date=datetime.now(), include_deleted=False)
stream = Campaigns(api=api, start_date=pendulum.now(), end_date=pendulum.now(), include_deleted=False)
try:
records = list(stream.read_records(sync_mode=SyncMode.full_refresh, stream_state={}))
assert records
Expand Down

0 comments on commit f4ba6c0

Please sign in to comment.