def setUp(self):
        """Prepare unittest."""
        print self.id()
        if not self.__class__.service:
            self.__class__.service = client.GetBidLandscapeService(
                self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)

        if self.__class__.ad_group_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': {
                        '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': {
                        'type': 'ManualCPCAdGroupBids',
                        'keywordMaxCpc': {
                            'amount': {
                                'microAmount': '1000000'
                            }
                        }
                    }
                }
            }]
            self.__class__.ad_group_id = \
                ad_group_service.Mutate(operations)[0]['value'][0]['id']
            ad_group_criterion_service = client.GetAdGroupCriterionService(
                self.__class__.SERVER, self.__class__.VERSION, HTTP_PROXY)
            operations = [{
                'operator': 'ADD',
                'operand': {
                    'type': 'BiddableAdGroupCriterion',
                    'adGroupId': self.__class__.ad_group_id,
                    'criterion': {
                        'type': 'Keyword',
                        'matchType': 'BROAD',
                        'text': 'mars cruise'
                    }
                }
            }]
            self.__class__.criterion_id = ad_group_criterion_service.Mutate(
                operations)[0]['value'][0]['criterion']['id']
예제 #2
0
    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']