def testGetRelatedToKeywordSearchParameterAllPages(self):
     """Test whether we can request related to keyword search parameter and
 retrieve complete set of resulting pages."""
     index = 0
     selector = {
         'searchParameters': [{
             'type':
             'RelatedToKeywordSearchParameter',
             'keywords': [{
                 'text': 'flowers',
                 'matchType': 'BROAD'
             }]
         }],
         'ideaType':
         'KEYWORD',
         'requestType':
         'IDEAS',
         'paging': {
             'startIndex': str(index),
             'numberResults': '100'
         }
     }
     results = []
     while True:
         page = self.__class__.service.Get(selector)[0]
         self.assertEqual(
             Utils.GetMethodCost(self.__class__.VERSION,
                                 self.__class__.service.__class__.__name__,
                                 'get', client.GetLastOperations(), True),
             client.GetLastUnits())
         if 'entries' in page:
             results.extend(page['entries'])
         if int(page['totalNumEntries']) <= index:
             break
         index += 100
         selector = {
             'searchParameters': [{
                 'type':
                 'RelatedToKeywordSearchParameter',
                 'keywords': [{
                     'text': 'flowers',
                     'matchType': 'BROAD'
                 }]
             }],
             'ideaType':
             'KEYWORD',
             'requestType':
             'IDEAS',
             'paging': {
                 'startIndex': str(index),
                 'numberResults': '100'
             }
         }
     self.assert_(isinstance(results, list))
     self.assertEqual(str(len(results)), page['totalNumEntries'])
     self.assertEqual(
         Utils.GetMethodCost(self.__class__.VERSION,
                             self.__class__.service.__class__.__name__,
                             'get', client.GetLastOperations(), True),
         client.GetLastUnits())
 def testGlobalMonthlySearchesSearchParameter(self):
     """Test whether we can request global monthly search parameter."""
     selector = {
         'searchParameters': [{
             'type': 'GlobalMonthlySearchesSearchParameter',
             'operation': {
                 'minimum': '1000',
                 'maximum': '10000'
             }
         }, {
             'type':
             'RelatedToKeywordSearchParameter',
             'keywords': [{
                 'text': 'dvd player',
                 'matchType': 'EXACT'
             }],
         }],
         'ideaType':
         'KEYWORD',
         'requestType':
         'IDEAS',
         'paging': {
             'startIndex': '0',
             'numberResults': '1'
         }
     }
     self.assert_(isinstance(self.__class__.service.Get(selector), tuple))
     self.assertEqual(
         Utils.GetMethodCost(self.__class__.VERSION,
                             self.__class__.service.__class__.__name__,
                             'get', client.GetLastOperations(), True),
         client.GetLastUnits())
 def testGetCompetitionSearchParameter(self):
     """Test whether we can request competition search parameter."""
     selector = {
         'searchParameters': [{
             'type': 'CompetitionSearchParameter',
             'levels': ['MEDIUM', 'HIGH']
         }, {
             'type':
             'RelatedToKeywordSearchParameter',
             'keywords': [{
                 'text': 'cash for clunkers',
                 'matchType': 'BROAD'
             }]
         }],
         'ideaType':
         'KEYWORD',
         'requestType':
         'IDEAS',
         'paging': {
             'startIndex': '0',
             'numberResults': '1'
         }
     }
     self.assert_(isinstance(self.__class__.service.Get(selector), tuple))
     self.assertEqual(
         Utils.GetMethodCost(self.__class__.VERSION,
                             self.__class__.service.__class__.__name__,
                             'get', client.GetLastOperations(), True),
         client.GetLastUnits())
 def testGetAdTypeSearchParameter(self):
     """Test whether we can request ad type search parameter."""
     selector = {
         'searchParameters': [{
             'type': 'AdTypeSearchParameter',
             'adTypes': ['DISPLAY']
         }, {
             'type': 'RelatedToUrlSearchParameter',
             'urls': ['http://news.google.com']
         }],
         'ideaType':
         'PLACEMENT',
         'requestType':
         'IDEAS',
         'paging': {
             'startIndex': '0',
             'numberResults': '1'
         }
     }
     self.assert_(isinstance(self.__class__.service.Get(selector), tuple))
     self.assertEqual(
         Utils.GetMethodCost(self.__class__.VERSION,
                             self.__class__.service.__class__.__name__,
                             'get', client.GetLastOperations(), True),
         client.GetLastUnits())
 def testGetBulkKeywordIdeas(self):
     """Test whether we can request bulk keyword ideas."""
     selector = {
         'searchParameters': [{
             'type':
             'RelatedToKeywordSearchParameter',
             'keywords': [{
                 'text': 'presidential vote',
                 'matchType': 'EXACT'
             }]
         }, {
             'type': 'RelatedToUrlSearchParameter',
             'urls': ['http://finance.google.com'],
             'includeSubUrls': 'false'
         }],
         'ideaType':
         'KEYWORD',
         'requestType':
         'IDEAS',
         'paging': {
             'startIndex': '0',
             'numberResults': '1'
         }
     }
     self.assert_(
         isinstance(self.__class__.service.GetBulkKeywordIdeas(selector),
                    tuple))
     self.assertEqual(
         Utils.GetMethodCost(self.__class__.VERSION,
                             self.__class__.service.__class__.__name__,
                             'get', client.GetLastOperations(), True),
         client.GetLastUnits())
 def testGetPlacementTypeSearchParameter(self):
     """Test whether we can request placement type search parameter."""
     selector = {
         'searchParameters': [{
             'type': 'PlacementTypeSearchParameter',
             'placementTypes': ['VIDEO', 'GAME']
         }, {
             'type':
             'RelatedToKeywordSearchParameter',
             'keywords': [{
                 'text': 'iron man',
                 'matchType': 'EXACT'
             }]
         }],
         'ideaType':
         'PLACEMENT',
         'requestType':
         'IDEAS',
         'paging': {
             'startIndex': '0',
             'numberResults': '1'
         }
     }
     self.assert_(isinstance(self.__class__.service.Get(selector), tuple))
     self.assertEqual(
         Utils.GetMethodCost(self.__class__.VERSION,
                             self.__class__.service.__class__.__name__,
                             'get', client.GetLastOperations(), True),
         client.GetLastUnits())
 def testGetKeywordCategoryIdSearchParameter(self):
     """Test whether we can request keyword category id search parameter."""
     selector = {
         'searchParameters': [{
             'type': 'KeywordCategoryIdSearchParameter',
             'categoryId': '5'
         }, {
             'type':
             'RelatedToKeywordSearchParameter',
             'keywords': [{
                 'text': 'rent video',
                 'matchType': 'EXACT'
             }]
         }],
         'ideaType':
         'KEYWORD',
         'requestType':
         'IDEAS',
         'paging': {
             'startIndex': '0',
             'numberResults': '1'
         }
     }
     self.assert_(isinstance(self.__class__.service.Get(selector), tuple))
     self.assertEqual(
         Utils.GetMethodCost(self.__class__.VERSION,
                             self.__class__.service.__class__.__name__,
                             'get', client.GetLastOperations(), True),
         client.GetLastUnits())
Exemple #8
0
 def testAddAdGroupKeyword(self):
     """Test whether we can add an ad group for keywords."""
     operations = [{
         'operator': 'ADD',
         'operand': {
             'campaignId': self.__class__.cpc_campaign_id,
             'name': 'AdGroup #%s' % Utils.GetUniqueName(),
             'status': 'ENABLED',
             'bids': {
                 'type': 'ManualCPCAdGroupBids',
                 'keywordMaxCpc': {
                     'amount': {
                         'microAmount': '1000000'
                     }
                 }
             }
         }
     }]
     ad_groups = self.__class__.service.Mutate(operations)
     self.__class__.ad_group = ad_groups[0]['value'][0]
     self.assert_(isinstance(ad_groups, tuple))
     self.assertEqual(
         Utils.GetMethodCost(self.__class__.VERSION,
                             self.__class__.service.__class__.__name__,
                             'mutate.ADD', client.GetLastOperations(),
                             True), client.GetLastUnits())
 def testGetIdeaTextMatchesSearchParameter(self):
     """Test whether we can request idea text matches."""
     selector = {
         'searchParameters': [{
             'type': 'IdeaTextMatchesSearchParameter',
             'included': ['red flowers']
         }, {
             'type':
             'RelatedToKeywordSearchParameter',
             'keywords': [{
                 'text': 'flowers',
                 'matchType': 'BROAD'
             }]
         }],
         'ideaType':
         'KEYWORD',
         'requestType':
         'IDEAS',
         'paging': {
             'startIndex': '0',
             'numberResults': '1'
         }
     }
     self.assert_(isinstance(self.__class__.service.Get(selector), tuple))
     self.assertEqual(
         Utils.GetMethodCost(self.__class__.VERSION,
                             self.__class__.service.__class__.__name__,
                             'get', client.GetLastOperations(), True),
         client.GetLastUnits())
 def testAddNetworkLanguageTargets(self):
     """Test whether we can add a network and language targets to campaign."""
     operations = [{
         'operator': 'SET',
         'operand': {
             'type': 'LanguageTargetList',
             'campaignId': self.__class__.campaign_id,
             'targets': [{
                 'type': 'LanguageTarget',
                 'languageCode': 'en'
             }]
         }
     }, {
         'operator': 'SET',
         'operand': {
             'type':
             'NetworkTargetList',
             'campaignId':
             self.__class__.campaign_id,
             'targets': [{
                 'type': 'NetworkTarget',
                 'networkCoverageType': 'GOOGLE_SEARCH'
             }, {
                 'type': 'NetworkTarget',
                 'networkCoverageType': 'CONTENT_NETWORK'
             }]
         }
     }]
     self.assert_(
         isinstance(self.__class__.service.Mutate(operations), tuple))
     self.assertEqual(
         Utils.GetMethodCost(self.__class__.VERSION,
                             self.__class__.service.__class__.__name__,
                             'mutate.SET', client.GetLastOperations(),
                             True), client.GetLastUnits())
 def testAddAdScheduleTarget(self):
     """Test whether we can add an ad schedule target to campaign."""
     operations = [{
         'operator': 'SET',
         'operand': {
             'type':
             'AdScheduleTargetList',
             'campaignId':
             self.__class__.campaign_id,
             'targets': [{
                 'type': 'AdScheduleTarget',
                 'dayOfWeek': 'MONDAY',
                 'startHour': '8',
                 'startMinute': 'ZERO',
                 'endHour': '17',
                 'endMinute': 'ZERO',
                 'bidMultiplier': '1.0',
             }]
         }
     }]
     self.assert_(
         isinstance(self.__class__.service.Mutate(operations), tuple))
     self.assertEqual(
         Utils.GetMethodCost(self.__class__.VERSION,
                             self.__class__.service.__class__.__name__,
                             'mutate.SET', client.GetLastOperations(),
                             True), client.GetLastUnits())
 def testAddCampaign(self):
   """Test whether we can add campaign."""
   operations = [{
       'operator': 'ADD',
       'operand': {
           'name': 'Campaign #%s' % Utils.GetUniqueName(),
           'status': 'PAUSED',
           'biddingStrategy': {
               'type': 'ManualCPC'
           },
           'endDate': '20110101',
           'budget': {
               'period': 'DAILY',
               'amount': {
                   'microAmount': '1000000'
               },
               'deliveryMethod': 'STANDARD'
           }
       }
   }]
   self.assert_(isinstance(self.__class__.service.Mutate(operations), tuple))
   self.assertEqual(
       Utils.GetMethodCost(self.__class__.VERSION,
                           self.__class__.service.__class__.__name__,
                           'mutate.ADD',
                           client.GetLastOperations(),
                           True),
       client.GetLastUnits())
 def testAddDemographicTarget(self):
     """Test whether we can add an age target to campaign."""
     operations = [{
         'operator': 'SET',
         'operand': {
             'type':
             'DemographicTargetList',
             'campaignId':
             self.__class__.campaign_id,
             'targets': [{
                 'type': 'AgeTarget',
                 'age': 'AGE_18_24'
             }, {
                 'type': 'GenderTarget',
                 'gender': 'FEMALE'
             }]
         }
     }]
     self.assert_(
         isinstance(self.__class__.service.Mutate(operations), tuple))
     self.assertEqual(
         Utils.GetMethodCost(self.__class__.VERSION,
                             self.__class__.service.__class__.__name__,
                             'mutate.SET', client.GetLastOperations(),
                             True), client.GetLastUnits())
Exemple #14
0
 def testGetGeoLocationInfo(self):
     """Test whether we can fetch geo location information for the given
 address."""
     selector = {
         'addresses': [{
             'streetAddress': '1600 Amphitheatre Parkway',
             'cityName': 'Mountain View',
             'provinceCode': 'US-CA',
             'provinceName': 'California',
             'postalCode': '94043',
             'countryCode': 'US'
         }, {
             'streetAddress': '76 Ninth Avenue',
             'cityName': 'New York',
             'provinceCode': 'US-NY',
             'provinceName': 'New York',
             'postalCode': '10011',
             'countryCode': 'US'
         }, {
             'streetAddress': '五四大街1号, Beijing东城区',
             'countryCode': 'CN'
         }]
     }
     self.assert_(isinstance(self.__class__.service.Get(selector), tuple))
     self.assertEqual(
         Utils.GetMethodCost(self.__class__.VERSION,
                             self.__class__.service.__class__.__name__,
                             'get', client.GetLastOperations(), True),
         client.GetLastUnits())
 def testAddKeywordCrossAdGroup(self):
   """Test whether we can add cross ad group keywords."""
   operations = [{
       'operator': 'ADD',
       'operand': {
           'type': 'BiddableAdGroupCriterion',
           'adGroupId': self.__class__.kw_ad_group_id,
           'criterion': {
               'type': 'Keyword',
               'matchType': 'BROAD',
               'text': 'mars cruise'
           }
       }
   },
   {
       'operator': 'ADD',
       'operand': {
           'type': 'BiddableAdGroupCriterion',
           'adGroupId': self.__class__.place_ad_group_id,
           'criterion': {
               'type': 'Placement',
               'url': 'www.example.com'
           }
       }
   }]
   self.assert_(isinstance(self.__class__.service.Mutate(operations), tuple))
   self.assertEqual(
       Utils.GetMethodCost(self.__class__.VERSION,
                           self.__class__.service.__class__.__name__,
                           'mutate.ADD',
                           client.GetLastOperations(),
                           True),
       client.GetLastUnits())
 def testEstimateCampaignList(self):
     """Test wheter we can estimate campaign list."""
     requests = [{
         'adGroupRequests': [{
             'keywordRequests': [{
                 'maxCpc': '1000000',
                 'negative': 'False',
                 'text': 'Flowers',
                 'type': 'Broad'
             }],
             'maxCpc':
             '1000000'
         }],
         'geoTargeting': {
             'cityTargets': {
                 'cities': ['New York, NY US'],
             }
         },
         'languageTargeting': ['en'],
         'networkTargeting': ['GoogleSearch', 'SearchNetwork']
     }]
     self.assert_(
         isinstance(self.__class__.service.EstimateCampaignList(requests),
                    tuple))
     self.assertEqual(
         Utils.GetMethodCost(self.__class__.VERSION,
                             self.__class__.service.__class__.__name__,
                             'estimateCampaignList',
                             client.GetLastOperations(), True),
         client.GetLastUnits())
Exemple #17
0
 def testCreateAdParam(self):
     """Test whether we can create a new ad param."""
     operations = [{
         'operator': 'SET',
         'operand': {
             'adGroupId': self.__class__.ad_group_id,
             'criterionId': self.__class__.criterion_id,
             'insertionText': '$1,699',
             'paramIndex': '1'
         }
     }, {
         'operator': 'SET',
         'operand': {
             'adGroupId': self.__class__.ad_group_id,
             'criterionId': self.__class__.criterion_id,
             'insertionText': '139',
             'paramIndex': '2'
         }
     }]
     self.assert_(
         isinstance(self.__class__.service.Mutate(operations), tuple))
     self.assertEqual(
         Utils.GetMethodCost(self.__class__.VERSION,
                             self.__class__.service.__class__.__name__,
                             'mutate.SET', client.GetLastOperations(),
                             True), client.GetLastUnits())
     self.__class__.has_param = True
Exemple #18
0
 def testAddTextAd(self):
     """Test whether we can add a text ad."""
     operations = [{
         'operator': 'ADD',
         'operand': {
             'type': 'AdGroupAd',
             'adGroupId': self.__class__.ad_group_id,
             'ad': {
                 'type': 'TextAd',
                 'url': 'http://www.example.com',
                 'displayUrl': 'example.com',
                 'status': 'ENABLED',
                 'description1': 'Visit the Red Planet in style.',
                 'description2': 'Low-gravity fun for everyone!',
                 'headline': 'Luxury Cruise to Mars'
             }
         }
     }]
     ads = self.__class__.service.Mutate(operations)
     self.__class__.ad = ads[0]['value'][0]
     self.assert_(isinstance(ads, tuple))
     self.assertEqual(
         Utils.GetMethodCost(self.__class__.VERSION,
                             self.__class__.service.__class__.__name__,
                             'mutate.ADD', client.GetLastOperations(),
                             True), client.GetLastUnits())
 def testGetLanguageTargetSearchParameter(self):
     """Test whether we can request language target search parameter."""
     selector = {
         'searchParameters': [{
             'type':
             'LanguageTargetSearchParameter',
             'languageTargets': [{
                 'languageCode': 'zh_CN'
             }, {
                 'languageCode': 'ja'
             }]
         }, {
             'type':
             'RelatedToKeywordSearchParameter',
             'keywords': [{
                 'text': 'global economy',
                 'matchType': 'EXACT'
             }]
         }],
         'ideaType':
         'KEYWORD',
         'requestType':
         'IDEAS',
         'paging': {
             'startIndex': '0',
             'numberResults': '1'
         }
     }
     self.assert_(isinstance(self.__class__.service.Get(selector), tuple))
     self.assertEqual(
         Utils.GetMethodCost(self.__class__.VERSION,
                             self.__class__.service.__class__.__name__,
                             'get', client.GetLastOperations(), True),
         client.GetLastUnits())
Exemple #20
0
 def testAddImageAd(self):
     """Test whether we can add an image ad."""
     operations = [{
         'operator': 'ADD',
         'operand': {
             'type': 'AdGroupAd',
             'adGroupId': self.__class__.ad_group_id,
             'ad': {
                 'type': 'ImageAd',
                 'image': {
                     'dimensions': [{
                         'key': 'FULL',
                         'value': {
                             'width': '300',
                             'height': '250'
                         }
                     }],
                     'name':
                     'image.jpg',
                     'data':
                     self.__class__.IMAGE_DATA
                 },
                 'name': 'Test image',
                 'url': 'http://www.example.com',
                 'displayUrl': 'www.example.com'
             }
         }
     }]
     self.assert_(
         isinstance(self.__class__.service.Mutate(operations), tuple))
     self.assertEqual(
         Utils.GetMethodCost(self.__class__.VERSION,
                             self.__class__.service.__class__.__name__,
                             'mutate.ADD', client.GetLastOperations(),
                             True), client.GetLastUnits())
 def testUpdateCriterionKeywordBids(self):
   """Test whether we can update a keyword's bids."""
   if self.__class__.kw == None:
     self.testAddCriterionKeyword()
   operations = [{
       'operator': 'SET',
       'operand': {
           'type': 'BiddableAdGroupCriterion',
           'adGroupId': self.__class__.kw['adGroupId'],
           'criterion': {
             'id': self.__class__.kw['criterion']['id'],
           },
           'bids': {
               'type': 'ManualCPCAdGroupCriterionBids',
               'maxCpc': {
                   'amount': {
                       'microAmount': '500000'
                   }
               }
           }
       }
   }]
   self.assert_(isinstance(self.__class__.service.Mutate(operations), tuple))
   self.assertEqual(
       Utils.GetMethodCost(self.__class__.VERSION,
                           self.__class__.service.__class__.__name__,
                           'mutate.SET',
                           client.GetLastOperations(),
                           True),
       client.GetLastUnits())
 def testAddAdExtensionOverride(self):
   """Test whether we can add ad extension override to a given campaign."""
   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.assert_(isinstance(self.__class__.service.Mutate(operations), tuple))
   self.assertEqual(
       Utils.GetMethodCost(self.__class__.VERSION,
                           self.__class__.service.__class__.__name__,
                           'mutate.ADD',
                           client.GetLastOperations(),
                           True),
       client.GetLastUnits())
 def testUpdateCampaign(self):
   """Test whether we can update an existing campaign."""
   if self.__class__.campaign1 == None:
     self.testAddCampaigns()
   operations = [{
       'operator': 'SET',
       'operand': {
           'id': self.__class__.campaign1['id'],
           'status': self.__class__.campaign1['status'],
           'budget': {
               'period': 'DAILY',
               'amount': {
                   'microAmount': '3000000'
               },
               'deliveryMethod': 'STANDARD'
           }
       }
   }]
   self.assert_(isinstance(self.__class__.service.Mutate(operations), tuple))
   self.assertEqual(
       Utils.GetMethodCost(self.__class__.VERSION,
                           self.__class__.service.__class__.__name__,
                           'mutate.SET',
                           client.GetLastOperations(),
                           True),
       client.GetLastUnits())
 def testGetAllJobs(self):
     """Test whether we can fetch all existing report jobs."""
     self.assert_(isinstance(self.__class__.service.GetAllJobs(), tuple))
     self.assertEqual(
         Utils.GetMethodCost(self.__class__.VERSION,
                             self.__class__.service.__class__.__name__,
                             'getAllJobs', client.GetLastOperations(),
                             True), client.GetLastUnits())
 def testGetMccAlerts(self):
     """Test whether we can retrieve MCC alerts."""
     self.assert_(isinstance(self.__class__.service.GetMccAlerts(), tuple))
     self.assertEqual(
         Utils.GetMethodCost(self.__class__.VERSION,
                             self.__class__.service.__class__.__name__,
                             'getMccAlerts', client.GetLastOperations(),
                             True), client.GetLastUnits())
Exemple #26
0
 def testGetTotalUsageUnitsPerMonth(self):
     """Test whether we can get total usage units per month."""
     selector = {'apiUsageType': 'TOTAL_USAGE_API_UNITS_PER_MONTH'}
     self.assert_(isinstance(self.__class__.service.Get(selector), tuple))
     self.assertEqual(
         Utils.GetMethodCost(self.__class__.VERSION,
                             self.__class__.service.__class__.__name__,
                             'get', client.GetLastOperations(), True),
         client.GetLastUnits())
Exemple #27
0
 def testGetAllAdsFromCampaign(self):
     """Test whether we can fetch all ads from given campaign."""
     selector = {'campaignIds': [self.__class__.campaign_id]}
     self.assert_(isinstance(self.__class__.service.Get(selector), tuple))
     self.assertEqual(
         Utils.GetMethodCost(self.__class__.VERSION,
                             self.__class__.service.__class__.__name__,
                             'get', client.GetLastOperations(), True),
         client.GetLastUnits())
 def testGetAccountInfo(self):
     """Test whether we can fetch information for account."""
     self.assert_(isinstance(self.__class__.service.GetAccountInfo(),
                             tuple))
     self.assertEqual(
         Utils.GetMethodCost(self.__class__.VERSION,
                             self.__class__.service.__class__.__name__,
                             'getAccountInfo', client.GetLastOperations(),
                             True), client.GetLastUnits())
Exemple #29
0
 def testGetAllAdParamsForAdGroup(self):
     """Test whether we can fetch all existing ad params in a given ad group."""
     selector = {'adGroupIds': [self.__class__.ad_group_id]}
     self.assert_(isinstance(self.__class__.service.Get(selector), tuple))
     self.assertEqual(
         Utils.GetMethodCost(self.__class__.VERSION,
                             self.__class__.service.__class__.__name__,
                             'get', client.GetLastOperations(), True),
         client.GetLastUnits())
 def testDeleteReport(self):
     """Test whether we can delete an existing report."""
     self.assertEqual(
         self.__class__.service.DeleteReport(
             self.__class__.FAILED_REPORT_JOB_ID), None)
     self.assertEqual(
         Utils.GetMethodCost(self.__class__.VERSION,
                             self.__class__.service.__class__.__name__,
                             'deleteReport', client.GetLastOperations(),
                             True), client.GetLastUnits())