def setUp(self): """Prepare unittest.""" print self.id() if not self.__class__.service: self.__class__.service = client.GetAdParamService( self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY) if (self.__class__.ad_group_id == '0' or self.__class__.text_ad_id == '0' or self.__class__.criterion_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' }, 'endDate': date(date.today().year + 1, 12, 31).strftime('%Y%m%d'), 'budget': { 'period': 'DAILY', 'amount': { 'microAmount': '2000000' }, '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' } } } } }] self.__class__.ad_group_id = ad_group_service.Mutate( operations)[0]['value'][0]['id'] ad_group_ad_service = client.GetAdGroupAdService( self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY) operations = [{ 'operator': 'ADD', 'operand': { 'xsi_type': 'AdGroupAd', 'adGroupId': self.__class__.ad_group_id, 'ad': { 'xsi_type': 'TextAd', 'url': 'http://www.example.com', 'displayUrl': 'example.com', 'description1': 'Good deals, only {param2:} left', 'description2': 'Low prices under {param1:}!', 'headline': 'MacBook Pro Sale' }, 'status': 'ENABLED' } }] self.__class__.text_ad_id = ad_group_ad_service.Mutate( operations)[0]['value'][0]['ad']['id'] ad_group_criterion_service = client.GetAdGroupCriterionService( self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY) operations = [{ 'operator': 'ADD', 'operand': { 'xsi_type': 'BiddableAdGroupCriterion', 'adGroupId': self.__class__.ad_group_id, 'criterion': { 'xsi_type': 'Keyword', 'matchType': 'BROAD', 'text': 'macbook pro' } } }] self.__class__.criterion_id = ad_group_criterion_service.Mutate( operations)[0]['value'][0]['criterion']['id']
def setUp(self): """Prepare unittest.""" print self.id() if not self.__class__.service: self.__class__.service = client.GetAdExtensionOverrideService( 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'] ad_group_service = client.GetAdGroupService( self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY) operations = [{ 'operator': 'ADD', 'operand': { 'campaignId': self.__class__.campaign_id, 'name': 'AdGroup #%s' % Utils.GetUniqueName(), 'status': 'ENABLED', 'bids': { 'type': 'ManualCPCAdGroupBids', 'keywordMaxCpc': { 'amount': { 'microAmount': '1000000' } } } } }] ad_group_id = ad_group_service.Mutate( operations)[0]['value'][0]['id'] ad_service = client.GetAdGroupAdService(self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY) operations = [{ 'operator': 'ADD', 'operand': { 'type': 'AdGroupAd', 'adGroupId': ad_group_id, 'ad': { 'type': 'TextAd', 'url': 'http://www.example.com', 'displayUrl': 'example.com', 'description1': 'Visit the Red Planet in style.', 'description2': 'Low-gravity fun for everyone!', 'headline': 'Luxury Cruise to Mars' }, 'status': 'ENABLED' } }] self.__class__.ad_id = ad_service.Mutate( operations)[0]['value'][0]['ad']['id'] if not self.__class__.geo_location: geo_location_service = client.GetGeoLocationService( self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY) selector = {'addresses': [self.__class__.address]} self.__class__.geo_location = geo_location_service.Get(selector)[0] if self.__class__.ad_extension_id == '0': campaign_ad_extension_service = client.GetCampaignAdExtensionService( self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY) operations = [{ 'operator': 'ADD', 'operand': { 'type': 'CampaignAdExtension', 'campaignId': self.__class__.campaign_id, 'adExtension': { 'type': 'LocationExtension', 'address': self.__class__.geo_location['address'], 'geoPoint': self.__class__.geo_location['geoPoint'], 'encodedLocation': self.__class__.geo_location['encodedLocation'], 'source': 'ADWORDS_FRONTEND' } } }] self.__class__.ad_extension_id = campaign_ad_extension_service.Mutate( operations)[0]['value'][0]['adExtension']['id']