Beispiel #1
0
    def test_t025_wad_Campaign_sync_with_nonexisting_budget(self):

        print('wad_Campaign test t025')

        client = adwords.AdWordsClient.LoadFromStorage()

        # sync with django db
        Campaign.sync(client)

        campaign0 = Campaign(campaignname='t025_campaign0')
        campaign0.save()
        campaign1 = Campaign(campaignname='t025_campaign1')
        campaign1.save()
        campaign2 = Campaign(campaignname='t025_campaign2')
        campaign2.save()

        allcampaigns = Campaign.listcampaigns(client)

        for campaign in allcampaigns:
            if campaign['id'] == campaign0.campaignid:
                self.assertEqual(campaign['name'], campaign0.campaignname)

            if campaign['id'] == campaign1.campaignid:
                self.assertEqual(campaign['name'], campaign1.campaignname)

            if campaign['id'] == campaign2.campaignid:
                self.assertEqual(campaign['name'], campaign2.campaignname)

        campaign0.delete()
        campaign1.delete()
        campaign2.delete()

        removedbudgets = Budget.removenorefbudgets(client)

        self.assertEqual(len(removedbudgets), 3)
Beispiel #2
0
    def test_t023_wad_Campaign_sync_with_existing_budget(self):

        print('wad_Campaign test t023')

        client = adwords.AdWordsClient.LoadFromStorage()

        # sync with django db
        Campaign.sync(client)

        budget0 = Budget(budgetname='t023_budget0', budgetamount=10000000)
        budget0.save()
        budget1 = Budget(budgetname='t023_budget1', budgetamount=20000000)
        budget1.save()
        budget2 = Budget(budgetname='t023_budget2', budgetamount=30000000)
        budget2.save()

        campaign0 = Campaign(campaignname='t023_campaign0',
                             campaignbudget=budget0)
        campaign0.save()
        campaign1 = Campaign(campaignname='t023_campaign1',
                             campaignbudget=budget1)
        campaign1.save()
        campaign2 = Campaign(campaignname='t023_campaign2',
                             campaignbudget=budget2)
        campaign2.save()

        allcampaigns = Campaign.listcampaigns(client)

        for campaign in allcampaigns:
            if campaign['budget']['budgetId'] == budget0.budgetid:
                self.assertEqual(campaign['budget']['amount']['microAmount'],
                                 budget0.budgetamount)

            if campaign['budget']['budgetId'] == budget1.budgetid:
                self.assertEqual(campaign['budget']['amount']['microAmount'],
                                 budget1.budgetamount)

            if campaign['budget']['budgetId'] == budget2.budgetid:
                self.assertEqual(campaign['budget']['amount']['microAmount'],
                                 budget2.budgetamount)

        campaign0.delete()
        campaign1.delete()
        campaign2.delete()

        removedbudgets = Budget.removenorefbudgets(client)
        self.assertEqual(len(removedbudgets), 3)
Beispiel #3
0
    def test_t026_wad_Campaign_modify_sync(self):

        print('wad_Campaign test t026')

        client = adwords.AdWordsClient.LoadFromStorage()
        service = Campaign.serviceobj(client)

        # modify name

        campaign0 = Campaign(campaignname='t026_campaign0')
        campaign0.save()

        mdict = Campaign.modifydict(
            campaign0.campaignid,
            't026_campaign0_renamed',
            campaign0.campaignstatus,
            campaign0.campaignbudget,
            campaign0.campaigntargetgooglesearch,
            campaign0.campaigntargetsearchnetwork,
            campaign0.campaigntargetcontentnetwork,
        )

        service.mutate([mdict])

        campaign0 = Campaign.objects.get(campaignid=campaign0.campaignid)
        self.assertEqual(campaign0.campaignname, 't026_campaign0')

        Campaign.sync(client)

        campaign0 = Campaign.objects.get(campaignid=campaign0.campaignid)
        self.assertEqual(campaign0.campaignname, 't026_campaign0_renamed')

        # modify status

        campaign1 = Campaign(campaignname='t026_campaign1')
        campaign1.save()

        statusnew = Campaign.objects.get(
            campaignid=campaign1.campaignid).campaignstatus

        if campaign1.campaignstatus == Campaign.STATE_ENABLED:
            statusnew = Campaign.STATE_PAUSED
        else:
            statusnew = Campaign.STATE_ENABLED

        mdict = Campaign.modifydict(campaign1.campaignid,
                                    campaign1.campaignname, statusnew,
                                    campaign1.campaignbudget,
                                    campaign1.campaigntargetgooglesearch,
                                    campaign1.campaigntargetsearchnetwork,
                                    campaign1.campaigntargetcontentnetwork)

        service.mutate([mdict])

        if statusnew == Campaign.STATE_ENABLED:
            statusnew = Campaign.STATE_PAUSED
        else:
            statusnew = Campaign.STATE_ENABLED

        campaign1 = Campaign.objects.get(campaignid=campaign1.campaignid)
        self.assertEqual(campaign1.campaignstatus, statusnew)

        Campaign.sync(client)

        if statusnew == Campaign.STATE_ENABLED:
            statusnew = Campaign.STATE_PAUSED
        else:
            statusnew = Campaign.STATE_ENABLED

        campaign1 = Campaign.objects.get(campaignid=campaign1.campaignid)
        self.assertEqual(campaign1.campaignstatus, statusnew)

        # modify budget

        campaign2 = Campaign(campaignname='t026_campaign2')
        campaign2.save()

        oldbudget = Campaign.objects.get(
            campaignid=campaign2.campaignid).campaignbudget

        newbudget = Budget(client, 'test_t026_budget2', 6000000000)
        newbudget.save()

        mdict = Campaign.modifydict(campaign2.campaignid,
                                    campaign2.campaignname,
                                    campaign2.campaignstatus,
                                    newbudget.asdict(),
                                    campaign2.campaigntargetgooglesearch,
                                    campaign2.campaigntargetsearchnetwork,
                                    campaign2.campaigntargetcontentnetwork)

        service.mutate([mdict])

        Campaign.sync(client)

        campaign2 = Campaign.objects.get(campaignid=campaign2.campaignid)
        self.assertNotEqual(campaign2.campaignbudget.budgetid,
                            oldbudget.budgetid)
        self.assertEqual(campaign2.campaignbudget.budgetid, newbudget.budgetid)

        # modify budget name

        campaign3 = Campaign(campaignname='t026_campaign3')
        campaign3.save()

        abudget = campaign3.campaignbudget

        abudget.budgetname = 'budget_for_t026_new_budget_name'

        abudget.save()

        #mdict = Campaign.modifydict (campaign3.campaignid,
        #campaign3.campaignname,
        #campaign3.campaignstatus,
        #campaign3.campaignbudget,
        #campaign3.campaigntargetgooglesearch,
        #campaign3.campaigntargetsearchnetwork,
        #campaign3.campaigntargetcontentnetwork,
        #)

        #service.mutate ( [mdict] )

        campaign3budgetname = Campaign.objects.get(
            campaignid=campaign3.campaignid).campaignbudget.budgetname
        self.assertEqual(campaign3budgetname, 'budget_for_t026_campaign3')

        Campaign.sync(client)

        campaign3budgetname = Campaign.objects.get(
            campaignid=campaign3.campaignid).campaignbudget.budgetname
        self.assertEqual(campaign3budgetname,
                         'budget_for_t026_new_budget_name')

        # modify budget 4

        campaign4 = Campaign(campaignname='t026_campaign4')
        campaign4.save()

        oldbudget = Campaign.objects.get(
            campaignid=campaign4.campaignid).campaignbudget

        newbudget = Budget(client, 'test_t026_budget4', 6000000000)
        newbudget.save()

        campaign4.campaignbudget = newbudget
        campaign4.save()

        #Campaign.sync( client )

        campaign4 = Campaign.objects.get(campaignid=campaign4.campaignid)
        self.assertNotEqual(campaign4.campaignbudget.budgetid,
                            oldbudget.budgetid)
        self.assertEqual(campaign4.campaignbudget.budgetid, newbudget.budgetid)

        # modify ad channel type

        #campaign2 = Campaign ( campaignname = 't026_campaign2' )
        #campaign2.save ()

        #adchan = Campaign.objects.get ( campaignid = campaign2.campaignid ).campaignadchanneltype

        #if campaign2.campaignadchanneltype == Campaign.TYPE_AD_CHAN_SEARCH:
        #adchan = Campaign.TYPE_AD_CHAN_DISPLAY
        #else:
        #adchan = Campaign.TYPE_AD_CHAN_SEARCH

        #mdict = Campaign.modifydict (campaign2.campaignid,
        #campaign2.campaignname,
        #campaign2.campaignstatus,
        #adchan,
        #campaign2.campaignbudget )
        #print ( mdict )
        #service.mutate ( [mdict] )

        #if adchan == Campaign.TYPE_AD_CHAN_SEARCH:
        #adchan = Campaign.TYPE_AD_CHAN_DISPLAY
        #else:
        #adchan = Campaign.TYPE_AD_CHAN_SEARCH

        #campaign2 = Campaign.objects.get ( campaignid = campaign2.campaignid )
        #self.assertEqual ( campaign2.campaignadchanneltype, adchan )

        #Campaign.sync( client )

        #if adchan == Campaign.TYPE_AD_CHAN_SEARCH:
        #adchan = Campaign.TYPE_AD_CHAN_DISPLAY
        #else:
        #adchan = Campaign.TYPE_AD_CHAN_SEARCH

        #campaign2 = Campaign.objects.get ( campaignid = campaign2.campaignid )
        #self.assertEqual ( campaign2.campaignadchanneltype, adchan )

        campaign0.delete()
        campaign1.delete()
        campaign2.delete()
        campaign3.delete()
        campaign4.delete()

        removedbudgets = Budget.removenorefbudgets(client)

        self.assertEqual(len(removedbudgets), 5)