def testCreateCreatieves(self): """Test whether we can create a list of creatives.""" creatives = [{ 'type': 'ImageCreative', 'name': 'Image Creative #%s' % Utils.GetUniqueName(), 'advertiserId': self.__class__.advertiser_id, 'destinationUrl': 'http://google.com', 'imageName': 'inline.jpg', 'imageByteArray': self.__class__.IMAGE_DATA2, 'size': { 'width': '300', 'height': '250' } }, { 'type': 'ImageCreative', 'name': 'Image Creative #%s' % Utils.GetUniqueName(), 'advertiserId': self.__class__.advertiser_id, 'destinationUrl': 'http://google.com', 'imageName': 'skyscraper.jpg', 'imageByteArray': self.__class__.IMAGE_DATA3, 'size': { 'width': '120', 'height': '600' } }] creatives = self.__class__.service.CreateCreatives(creatives) self.__class__.creative1 = creatives[0] self.__class__.creative2 = creatives[1] self.assert_(isinstance(creatives, tuple))
def main(client, activity_group_id): # Initialize appropriate service. activity_service = client.GetService('ActivityService', version='v201403') # Create a daily visits activity. daily_visits_activity = { 'name': 'Activity #%s' % Utils.GetUniqueName(), 'activityGroupId': activity_group_id, 'type': 'DAILY_VISITS' } # Create a custom activity. custom_activity = { 'name': 'Activity #%s' % Utils.GetUniqueName(), 'activityGroupId': activity_group_id, 'type': 'CUSTOM' } # Create the activities on the server. activities = activity_service.CreateActivities( [daily_visits_activity, custom_activity]) # Display results. for activity in activities: print('An activity with ID \'%s\', name \'%s\', and type \'%s\' was ' 'created.' % (activity['id'], activity['name'], activity['type']))
def main(client, advertiser_company_id): # Initialize appropriate service. activity_group_service = client.GetService('ActivityGroupService', version='v201411') # Create a short-term activity group. short_term_activity_group = { 'name': 'Short-term activity group #%s' % Utils.GetUniqueName(), 'companyIds': [advertiser_company_id], 'clicksLookback': '1', 'impressionsLookback': '1' } # Create a long-term activity group. long_term_activity_group = { 'name': 'Long-term activity group #%s' % Utils.GetUniqueName(), 'companyIds': [advertiser_company_id], 'clicksLookback': '30', 'impressionsLookback': '30' } # Create the activity groups on the server. activity_groups = activity_group_service.CreateActivityGroups( [short_term_activity_group, long_term_activity_group]) # Display results. for activity_group in activity_groups: print('Activity group with ID \'%s\' and name \'%s\' was created.' % (activity_group['id'], activity_group['name']))
def main(client, advertiser_company_id, agency_company_id): # Initialize appropriate service. contact_service = client.GetService('ContactService', version='v201408') # Create an advertiser contact. advertiser_contact = { 'name': 'Mr. Advertiser #%s' % Utils.GetUniqueName(), 'email': '*****@*****.**', 'companyId': advertiser_company_id } # Create an agency contact. agency_contact = { 'name': 'Ms. Agency #%s' % Utils.GetUniqueName(), 'email': '*****@*****.**', 'companyId': agency_company_id } # Create the contacts on the server. contacts = contact_service.CreateContacts([advertiser_contact, agency_contact]) # Display results. for contact in contacts: print ('Contact with ID \'%s\' name \'%s\' was created.' % (contact['id'], contact['name']))
def testCreateCustomTargetingValues(self): """Test whether we can create custom targeting values.""" if not self.__class__.key1 or not self.__class__.key2: self.testCreateCustomTargetingKeys() values = [{ 'customTargetingKeyId': self.__class__.key1['id'], 'displayName': 'male', 'name': Utils.GetUniqueName(40), 'matchType': 'EXACT' }, { 'customTargetingKeyId': self.__class__.key1['id'], 'displayName': 'female', 'name': Utils.GetUniqueName(40), 'matchType': 'EXACT' }] try: values = self.__class__.service.CreateCustomTargetingValues(values) self.__class__.value1 = values[0] self.assert_(isinstance(values, tuple)) except DfpApiError, e: if e.message.find( 'CustomTargetingError.VALUE_NAME_DUPLICATE') > -1: self.testDeleteCustomTargetingValues() else: raise e
def main(client): # Initialize appropriate service. custom_field_service = client.GetService('CustomFieldService', version='v201306') # Create custom field objects. custom_fields = [{ 'name': 'Customer comments #%s' % Utils.GetUniqueName(), 'entityType': 'LINE_ITEM', 'dataType': 'STRING', 'visibility': 'FULL' }, { 'name': 'Internal approval status #%s' % Utils.GetUniqueName(), 'entityType': 'LINE_ITEM', 'dataType': 'DROP_DOWN', 'visibility': 'FULL' }] # Add custom fields. custom_fields = custom_field_service.CreateCustomFields(custom_fields) # Display results. for custom_field in custom_fields: print('Custom field with ID \'%s\' and name \'%s\' was created.' % (custom_field['id'], custom_field['name']))
def testSaveCampaign(self): """Test whether we can create a campaign.""" self.testSaveLandingPage() dt = datetime.datetime.now() campaign = { 'advertiserId': self.__class__.advertiser_id, 'archived': 'false', 'name': 'Campaign #%s' % Utils.GetUniqueName(), 'defaultLandingPageId': self.__class__.landing_page_id, 'endDate': '%s-01-31T12:00:00' % (dt.year + 1), 'startDate': '%s-01-01T12:00:00' % (dt.year + 1), 'creativeOptimizationConfiguration': { 'minimumCreativeWeight': '5', 'optimizationModelId': '1', 'relativeStrength': '2' }, 'landingPageIds': [self.__class__.landing_page_id], 'lookbackWindow': { 'postClickEventLookbackWindow': '-1', 'postImpressionEventLookbackWindow': '-1', 'richMediaEventLookbackWindow': '-1' }, 'reachReportConfiguration': { 'pageLevelFrequency': 'false', 'siteLevelFrequency': 'false' } } campaign = self.__class__.service.SaveCampaign(campaign) self.__class__.campaign1 = campaign[0] self.assert_(isinstance(campaign, tuple)) self.testSaveLandingPage() campaign = { 'advertiserId': self.__class__.advertiser_id, 'archived': 'false', 'name': 'Campaign #%s' % Utils.GetUniqueName(), 'defaultLandingPageId': self.__class__.landing_page_id, 'endDate': '%s-01-31T12:00:00' % (dt.year + 1), 'startDate': '%s-01-01T12:00:00' % (dt.year + 1), 'creativeOptimizationConfiguration': { 'minimumCreativeWeight': '5', 'optimizationModelId': '1', 'relativeStrength': '2' }, 'landingPageIds': [self.__class__.landing_page_id], 'lookbackWindow': { 'postClickEventLookbackWindow': '-1', 'postImpressionEventLookbackWindow': '-1', 'richMediaEventLookbackWindow': '-1' }, 'reachReportConfiguration': { 'pageLevelFrequency': 'false', 'siteLevelFrequency': 'false' } } campaign = self.__class__.service.SaveCampaign(campaign) self.__class__.campaign2 = campaign[0] self.assert_(isinstance(campaign, tuple))
def main(client, campaign_id): # Initialize appropriate service. ad_group_service = client.GetAdGroupService(version='v201209') # Construct operations and add ad groups. operations = [ { 'operator': 'ADD', 'operand': { 'campaignId': campaign_id, 'name': 'Earth to Mars Cruises #%s' % Utils.GetUniqueName(), 'status': 'ENABLED', 'bids': { 'xsi_type': 'ManualCPCAdGroupBids', 'keywordMaxCpc': { 'amount': { 'microAmount': '1000000' } }, # Optional field. 'keywordContentMaxCpc': { 'amount': { 'microAmount': '2000000' } } } } }, { 'operator': 'ADD', 'operand': { 'campaignId': campaign_id, 'name': 'Earth to Venus Cruises #%s' % Utils.GetUniqueName(), 'status': 'ENABLED', 'bids': { 'xsi_type': 'ManualCPCAdGroupBids', 'keywordMaxCpc': { 'amount': { 'microAmount': '2000000' } }, } } } ] ad_groups = ad_group_service.Mutate(operations)[0] # Display results. for ad_group in ad_groups['value']: print('Ad group with name \'%s\' and id \'%s\' was added.' % (ad_group['name'], ad_group['id'])) print print('Usage: %s units, %s operations' % (client.GetUnits(), client.GetOperations()))
def main(client, advertiser_id): # Initialize appropriate service. creative_service = client.GetService('CreativeService', version='v201411') # Get the image data for the creative. image_data = open( os.path.join(__file__[:__file__.rfind('/')], '..', 'data', 'medium_rectangle.jpg'), 'r').read() image_data = base64.encodestring(image_data) # Create the HTML snippet used in the custom creative. html_snippet = ( '<a href=\'%s%s\'><img src=\'%s\'/></a><br>Click above for ' 'great deals!') % ('%%CLICK_URL_UNESC%%', '%%DEST_URL%%', '%%FILE:IMAGE_ASSET%%') # Create custom creative. creative = { 'type': 'CustomCreative', 'name': 'Custom Creative #%s' % Utils.GetUniqueName(), 'advertiserId': advertiser_id, 'size': { 'width': '300', 'height': '250' }, 'destinationUrl': 'http://google.com', 'customCreativeAssets': [{ 'type': 'CustomCreativeAsset', 'macroName': 'IMAGE_ASSET', 'assetByteArray': image_data, 'fileName': 'image%s.jpg' % Utils.GetUniqueName() }], 'htmlSnippet': html_snippet } # Call service to create the creative. creative = creative_service.CreateCreative(creative)[0] # Display results. if creative: print( 'Template creative with id \'%s\', name \'%s\', and type \'%s\' was ' 'created and can be previewed at %s.' % (creative['id'], creative['name'], creative['Creative_Type'], creative['previewUrl']))
def setUp(self): """Prepare unittest.""" print self.id() if not self.__class__.service: self.__class__.service = client.GetLineItemService( self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY) if self.__class__.order_id == '0': company = { 'name': 'Company #%s' % Utils.GetUniqueName(), 'type': 'ADVERTISER' } advertiser_id = client.GetCompanyService( self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY).CreateCompany(company)[0]['id'] filter_statement = {'query': 'ORDER BY name LIMIT 500'} users = client.GetUserService( self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY).GetUsersByStatement(filter_statement) trafficker_id = '0' for user in users[0]['results']: if user['roleName'] in ('Trafficker', ): trafficker_id = user['id'] break order = { 'advertiserId': advertiser_id, 'currencyCode': 'USD', 'name': 'Order #%s' % Utils.GetUniqueName(), 'traffickerId': trafficker_id } self.__class__.order_id = client.GetOrderService( self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY).CreateOrder(order)[0]['id'] if self.__class__.ad_unit_id == '0': inventory_service = client.GetInventoryService( self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY) network_service = client.GetNetworkService(self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY) root_ad_unit_id = \ network_service.GetCurrentNetwork()[0]['effectiveRootAdUnitId'] ad_unit = { 'name': 'Ad_Unit_%s' % Utils.GetUniqueName(), 'parentId': root_ad_unit_id, 'sizes': [{ 'width': '300', 'height': '250' }], 'description': 'Ad unit description.', 'targetWindow': 'BLANK' } self.__class__.ad_unit_id = inventory_service.CreateAdUnit( ad_unit)[0]['id']
def testCreateCompanies(self): """Test whether we can create a list of companies.""" companies = [{ 'name': 'Company #%s' % Utils.GetUniqueName(), 'type': 'ADVERTISER' }, { 'name': 'Company #%s' % Utils.GetUniqueName(), 'type': 'ADVERTISER' }] companies = self.__class__.service.CreateCompanies(companies) self.__class__.company1 = companies[0] self.__class__.company2 = companies[1] self.assert_(isinstance(companies, tuple))
def setUp(self): """Prepare unittest.""" print self.id() if not self.__class__.service: self.__class__.service = client.GetReportDefinitionService( self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY) if self.__class__.ad_group_id == '0': campaign_service = client.GetCampaignService( self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY) operations = [{ 'operator': 'ADD', 'operand': { 'name': 'Campaign #%s' % Utils.GetUniqueName(), 'status': 'PAUSED', 'biddingStrategy': { 'xsi_type': 'ManualCPC' }, 'budget': { 'period': 'DAILY', 'amount': { 'microAmount': '1000000' }, 'deliveryMethod': 'STANDARD' } } }] campaign_id = campaign_service.Mutate( operations)[0]['value'][0]['id'] ad_group_service = client.GetAdGroupService( self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY) operations = [{ 'operator': 'ADD', 'operand': { 'campaignId': campaign_id, 'name': 'AdGroup #%s' % Utils.GetUniqueName(), 'status': 'ENABLED', 'bids': { 'xsi_type': 'ManualCPCAdGroupBids', 'keywordMaxCpc': { 'amount': { 'microAmount': '1000000' } } } } }] ad_groups = ad_group_service.Mutate(operations)[0]['value'] self.__class__.ad_group_id = ad_groups[0]['id']
def testSavePlacementGroup(self): """Test whether we can save a placement group.""" campaign_id = self.__class__.campaign['id'] site_id = self.__class__.dfa_site_id start_date = self.__class__.campaign['startDate'] end_date = self.__class__.campaign['endDate'] placement_group = { 'name': 'PlacementGroup #%s' % Utils.GetUniqueName(), 'dfaSiteId': site_id, 'campaignId': campaign_id, 'placementGroupType': '1', 'pricingSchedule': { 'endDate': end_date, 'startDate': start_date, 'pricingType': '1', 'pricingPeriods': [{ 'rateOrCost': '1.50', 'units': '10000', 'endDate': end_date, 'startDate': start_date }] } } placement_group = self.__class__.service.SavePlacementGroup( placement_group) self.__class__.placement_group_id = placement_group[0]['id'] self.assert_(isinstance(placement_group, tuple))
def main(client, parent_id): # Initialize appropriate service. inventory_service = client.GetService('InventoryService', version='v201403') # Create ad unit size. ad_unit_size = { 'size': { 'width': '300', 'height': '250' }, 'environmentType': 'BROWSER' } # Create ad unit objects. ad_unit = { 'name': 'Ad_unit_%s' % Utils.GetUniqueName(), 'parentId': parent_id, 'description': 'Ad unit description.', 'targetWindow': 'BLANK', 'targetPlatform': 'WEB', 'adUnitSizes': [ad_unit_size] } # Add ad units. ad_units = inventory_service.CreateAdUnits([ad_unit]) # Display results. for ad_unit in ad_units: print('Ad unit with ID \'%s\' and name \'%s\' was created.' % (ad_unit['id'], ad_unit['name']))
def testSavePlacement(self): """Test whether we can save a placement.""" campaign_id = self.__class__.campaign['id'] site_id = self.__class__.dfa_site_id start_date = self.__class__.campaign['startDate'] end_date = self.__class__.campaign['endDate'] placement = { 'name': 'Placement #%s' % Utils.GetUniqueName(), 'dfaSiteId': site_id, 'campaignId': campaign_id, 'pricingSchedule': { 'endDate': end_date, 'startDate': start_date, 'pricingType': '1', 'pricingPeriods': [{ 'rateOrCost': '1.50', 'units': '10000', 'endDate': end_date, 'startDate': start_date }] }, 'placementType': '3', 'sizeId': '2495', 'tagSettings': { 'tagTypes': ['1', '2', '3', '4', '5', '9'] } } placement = self.__class__.service.SavePlacement(placement) self.__class__.placement_id = placement[0]['id'] self.assert_(isinstance(placement, tuple))
def main(client, advertiser_id, video_duration, ad_id, survey_url, click_through_url, campaign_id): # Initialize appropriate service. creative_service = client.GetCreativeService( 'https://advertisersapitest.doubleclick.net', 'v1.19') # Create the In-Stream video creative. in_stream_video_creative = { 'advertiserId': advertiser_id, 'name': 'In-Stream Video Creative #%s' % Utils.GetUniqueName(), 'videoDuration': video_duration, # In-Stream video creatives have to be created inactive. One can only be # set active after at least one media file has been added to it or the API # will return an error message. 'active': 'false', # Set the video details based on the Video Ad Serving Template (VAST) # specification. 'adId': ad_id, 'description': 'You are viewing an In-Stream Video Creative', 'surveyUrl': survey_url, 'clickThroughUrl': click_through_url } # Save the In-Stream video creative. result = creative_service.SaveCreative(in_stream_video_creative, campaign_id)[0] # Display the new creative ID. print 'In-Stream video creative with ID \'%s\' was created.' % result['Id']
def CreateTestLineItemCustomFieldOption(client, server, version, drop_down_custom_field_id): """Create a test line item drop-down custom field option. Args: client: DfpClient used for service creation. server: str the API server. version: str the API version. drop_down_custom_field_id: str the ID of the drop-down custom field Returns: The ID of the test drop-down custom field. """ custom_field_service = client.GetService('CustomFieldService', server, version) # Create custom field option. custom_field_option = { 'displayName': 'Approved #%s' % Utils.GetUniqueName(), 'customFieldId': drop_down_custom_field_id } # Add custom field options. custom_field_options = custom_field_service.CreateCustomFieldOptions( [custom_field_option]) return custom_field_options[0]['id']
def CreateTestCPMAdGroup(client, campaign_id): """Creates a CPM AdGroup to run tests with. Args: client: AdWordsClient client to obtain services from. campaign_id: int ID of a CPM Campaign. Returns: int AdGroupId """ ad_group_service = client.GetAdGroupService(SERVER, VERSION, HTTP_PROXY) operations = [{ 'operator': 'ADD', 'operand': { 'campaignId': campaign_id, 'name': 'AdGroup #%s' % Utils.GetUniqueName(), 'status': 'ENABLED', 'biddingStrategyConfiguration': { 'bids': [{ 'xsi_type': 'CpmBid', 'bid': { 'microAmount': '1000000' }, }] } } }] ad_groups = ad_group_service.Mutate(operations)[0]['value'] return ad_groups[0]['id']
def main(client, hierarchy_level_one_key_id, hierarchy_level_two_key_id): # Initialize appropriate service. content_metadata_key_hierarchy_service = client.GetService( 'ContentMetadataKeyHierarchyService', version='v201403') hierarchy_level_1 = { 'customTargetingKeyId': hierarchy_level_one_key_id, 'hierarchyLevel': '1' } hierarchy_level_2 = { 'customTargetingKeyId': hierarchy_level_two_key_id, 'hierarchyLevel': '2' } hierarchy_levels = [hierarchy_level_1, hierarchy_level_2] # Create content metadata key hierarchy object. content_metadata_key_hierarchy = { 'name': 'Content Metadata Key Hierarchy #%s' % Utils.GetUniqueName(), 'hierarchyLevels': hierarchy_levels } content_metadata_key_hierarchies = (content_metadata_key_hierarchy_service. createContentMetadataKeyHierarchies( [content_metadata_key_hierarchy])) # Display results. for content_metadata_key_hierarchy in content_metadata_key_hierarchies: print('Content metadata key hierarchy with id \'%s\' and name \'%s\'' ' was created.' % (content_metadata_key_hierarchy['id'], content_metadata_key_hierarchy['name']))
def main(client, custom_targeting_key_id, custom_targeting_value_id): # Initialize appropriate services. audience_segment_service = client.GetService('AudienceSegmentService', version='v201405') network_service = client.GetService('NetworkService', version='v201405') # Get the root ad unit ID used to target the entire network. root_ad_unit_id = ( network_service.getCurrentNetwork()[0]['effectiveRootAdUnitId']) # Create inventory targeting (pointed at root ad unit i.e. the whole network) inventory_targeting = {'targetedAdUnits': [{'adUnitId': root_ad_unit_id}]} # Create custom criteria. custom_criteria = [{ 'xsi_type': 'CustomCriteria', 'keyId': custom_targeting_key_id, 'valueIds': [custom_targeting_value_id], 'operator': 'IS' }] # Create the custom criteria set. top_custom_criteria_set = { 'logicalOperator': 'AND', 'children': custom_criteria } # Create the audience segment rule. rule = { 'inventoryRule': inventory_targeting, 'customCriteriaRule': top_custom_criteria_set } # Create an audience segment. audience_segment = [{ 'xsi_type': 'RuleBasedFirstPartyAudienceSegment', 'name': ('Sports enthusiasts audience segment %s' % Utils.GetUniqueName()), 'description': 'Sports enthusiasts between the ages of 20 and 30', 'pageViews': '6', 'recencyDays': '6', 'membershipExpirationDays': '88', 'rule': rule }] audience_segments = ( audience_segment_service.createAudienceSegments(audience_segment)) for created_audience_segment in audience_segments: print( 'An audience segment with ID \'%s\', name \'%s\', and type \'%s\' ' 'was created.' % (created_audience_segment['id'], created_audience_segment['name'], created_audience_segment['type']))
def testAddKeywordPerformanceReport(self): """Test whether we can add a keywords performance report.""" operations = [{ 'operator': 'ADD', 'operand': { 'xsi_type': 'ReportDefinition', 'reportName': ('Keywords performance report #%s' % Utils.GetUniqueName()), 'dateRangeType': 'CUSTOM_DATE', 'reportType': 'KEYWORDS_PERFORMANCE_REPORT', 'downloadFormat': 'XML', 'selector': { 'fields': [ 'AdGroupId', 'Id', 'KeywordText', 'KeywordMatchType', 'Impressions', 'Clicks', 'Cost' ], 'predicates': [{ 'field': 'AdGroupId', 'operator': 'EQUALS', 'values': [self.__class__.ad_group_id] }], 'dateRange': { 'min': '20100101', 'max': '20100131' } } } }] report_definition = self.__class__.service.Mutate(operations) self.__class__.report_definition_id = report_definition[0]['id'] self.assert_(isinstance(report_definition, tuple))
def CreateSharedBudget(client): """Creates an explicit budget to be used only to create the Campaign. Args: client: AdWordsClient the client to run the example with. Returns: dict An object representing a shared budget. """ # Initialize appropriate service. budget_service = client.GetBudgetService(version='v201406') # Create a shared budget budget = { 'name': 'Shared Interplanetary Budget #%s' % Utils.GetUniqueName(), 'period': 'DAILY', 'amount': { 'microAmount': '2000000' }, 'deliveryMethod': 'STANDARD', 'isExplicitlyShared': 'true' } # Create operation. operation = {'operator': 'ADD', 'operand': budget} response = budget_service.mutate([operation])[0] return response['value'][0]
def setUp(self): """Prepare unittest.""" print self.id() if not self.__class__.service: self.__class__.service = client.GetOrderService( self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY) if self.__class__.advertiser_id == '0': company = { 'name': 'Company #%s' % Utils.GetUniqueName(), 'type': 'ADVERTISER' } self.__class__.advertiser_id = client.GetCompanyService( self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY).CreateCompany(company)[0]['id'] if self.__class__.trafficker_id == '0': filter_statement = {'query': 'ORDER BY name LIMIT 500'} users = client.GetUserService( self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY).GetUsersByStatement(filter_statement) for user in users[0]['results']: if user['roleName'] in ('Salesperson', ): self.__class__.salesperson_id = user['id'] continue elif user['roleName'] in ('Trafficker', ): self.__class__.trafficker_id = user['id'] continue
def setUp(self): """Prepare unittest.""" print self.id() if not self.__class__.service: self.__class__.service = client.GetCampaignCriterionService( self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY) if (self.__class__.campaign_id == '0'): campaign_service = client.GetCampaignService( self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY) operations = [{ 'operator': 'ADD', 'operand': { 'name': 'Campaign #%s' % Utils.GetUniqueName(), 'status': 'PAUSED', 'biddingStrategy': { 'type': 'ManualCPC' }, 'budget': { 'period': 'DAILY', 'amount': { 'microAmount': '1000000' }, 'deliveryMethod': 'STANDARD' } } }] self.__class__.campaign_id = \ campaign_service.Mutate(operations)[0]['value'][0]['id']
def testAddAdGroupKeywordPlacement(self): """Test whether we can add an ad group for all criteria types.""" operations = [{ 'operator': 'ADD', 'operand': { 'campaignId': self.__class__.cpc_campaign_id, 'name': 'AdGroup #%s' % Utils.GetUniqueName(), 'status': 'ENABLED', 'bids': { 'type': 'ManualCPCAdGroupBids', 'keywordMaxCpc': { 'amount': { 'microAmount': '1000000' } }, 'siteMaxCpc': { 'amount': { 'microAmount': '1000000' } } } } }] self.assert_( isinstance(self.__class__.service.Mutate(operations), tuple))
def testAddLogicalUserList(self): """Test whether we can add a logical user list.""" if self.__class__.user_list is None: self.testAddRemarketingUserList() operations = [{ 'operator': 'ADD', 'operand': { 'xsi_type': 'LogicalUserList', 'name': 'Mars cruise customers #%s' % Utils.GetUniqueName(), 'description': 'A list of mars cruise customers in the last ' 'year.', 'membershipLifeSpan': '365', 'rules': [{ 'operator': 'ALL', 'ruleOperands': [{ 'xsi_type': 'RemarketingUserList', 'id': self.__class__.user_list['id'] }] }] } }] self.assert_( isinstance(self.__class__.service.Mutate(operations), tuple))
def CreateTestCampaign(client): """Creates a CPC campaign to run tests with. Args: client: AdWordsClient client to obtain services from. Returns: int CampaignId """ campaign_service = client.GetCampaignService(SERVER, VERSION, HTTP_PROXY) operations = [{ 'operator': 'ADD', 'operand': { 'name': 'Campaign #%s' % Utils.GetUniqueName(), 'status': 'PAUSED', 'biddingStrategyConfiguration': { 'biddingStrategyType': 'MANUAL_CPC', 'biddingScheme': { 'xsi_type': 'ManualCpcBiddingScheme', 'enhancedCpcEnabled': 'false' } }, 'budget': { 'budgetId': CreateTestBudget(client) }, 'settings': [{ 'xsi_type': 'KeywordMatchSetting', 'optIn': 'false' }] } }] return campaign_service.Mutate(operations)[0]['value'][0]['id']
def CreateTestRTBCampaign(client): """Creates a CPM campaign to run tests with. Args: client: AdWordsClient client to obtain services from. Returns: int CampaignId """ campaign_service = client.GetCampaignService(SERVER, VERSION, HTTP_PROXY) operations = [{ 'operator': 'ADD', 'operand': { 'name': 'Campaign #%s' % Utils.GetUniqueName(), 'status': 'PAUSED', 'biddingStrategyConfiguration': { 'biddingStrategyType': 'MANUAL_CPM', 'biddingScheme': { 'xsi_type': 'ManualCpmBiddingScheme', } }, 'advertisingChannelType': 'DISPLAY', 'budget': { 'budgetId': CreateTestBudget(client) }, 'settings': [{ 'xsi_type': 'RealTimeBiddingSetting', 'optIn': 'true' }] } }] return campaign_service.Mutate(operations)[0]['value'][0]['id']
def testUploadCreativeFiles(self): """Test whether we can upload creative files in a creative upload session.""" if self.__class__.upload_session_id == '0': self.testGenerateCreativeUploadSession() campaign_id = self.__class__.campaign['id'] advertiser_id = self.__class__.campaign['advertiserId'] upload_session_id = self.__class__.upload_session_id content = Utils.ReadFile(os.path.join('..', 'data', 'code_logo.gif')) content = base64.encodestring(content) creative_upload_request = { 'creativeUploadSessionSummary': { 'campaignId': campaign_id, 'advertiserId': advertiser_id, 'creativeUploadId': upload_session_id }, 'rawFiles': [{ 'filename': 'UploadedFile%s.gif' % Utils.GetUniqueName(), 'mimeType': 'image/gif', 'fileData': content }] } creative_upload_request = self.__class__.service.UploadCreativeFiles( creative_upload_request) self.__class__.creative_upload_session_object = creative_upload_request[0] self.assert_(isinstance(creative_upload_request, tuple))
def setUp(self): """Prepare unittest.""" print self.id() if not self.__class__.service: self.__class__.service = client.GetCustomerSyncService( self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY) if self.__class__.campaign_id == '0': campaign_service = client.GetCampaignService( self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY) operations = [{ 'operator': 'ADD', 'operand': { 'name': 'Campaign #%s' % Utils.GetUniqueName(), 'status': 'PAUSED', 'biddingStrategy': { 'type': 'ManualCPC' }, 'endDate': date(date.today().year + 1, 12, 31).strftime('%Y%m%d'), 'budget': { 'period': 'DAILY', 'amount': { 'microAmount': '2000000' }, 'deliveryMethod': 'STANDARD' } } }] self.__class__.campaign_id = campaign_service.Mutate( operations)[0]['value'][0]['id']