Ejemplo n.º 1
0
    def test_t002_wad_Campaign_add_remove_usingsync(self):

        print('wad_Campaign test t002')

        client = adwords.AdWordsClient.LoadFromStorage()

        # creates three new campaigns
        campaign0id = Campaign._aw_addcampaign(client,
                                               'test_t002_campaign0')['id']
        campaign1id = Campaign._aw_addcampaign(client,
                                               'test_t002_campaign1')['id']
        campaign2id = Campaign._aw_addcampaign(client,
                                               'test_t002_campaign2')['id']

        # gets the lists of all campaigns
        campaignlist = Campaign.listcampaigns(client)

        campaignidlist = []

        # builds a list of campaigns with status != REMOVED
        for campaign in campaignlist:
            if campaign['status'] != Campaign.STATE_REMOVED:
                campaignidlist.append(campaign['id'])

        # asserts the campaigns added are in the list
        self.assertTrue(campaign0id in campaignidlist)
        self.assertTrue(campaign1id in campaignidlist)
        self.assertTrue(campaign2id in campaignidlist)

        # removes the campaigns
        Campaign.removecampaign(client, campaign0id)
        Campaign.removecampaign(client, campaign1id)
        Campaign.removecampaign(client, campaign2id)

        # gets the list of all campaigns
        campaignlist = Campaign.listcampaigns(client)

        campaignidlist = []

        # builds a list of campaigns with status != REMOVED
        for campaign in campaignlist:
            if campaign['status'] != Campaign.STATE_REMOVED:
                campaignidlist.append(campaign['id'])

        # asserts the campaigns added are not in the list
        self.assertFalse(campaign0id in campaignidlist)
        self.assertFalse(campaign1id in campaignidlist)
        self.assertFalse(campaign2id in campaignidlist)

        #Budget.removenorefbudgets( client )

        removedbudgets = Budget.removenorefbudgets(client)
        self.assertEqual(len(removedbudgets), 3)
Ejemplo n.º 2
0
    def test_t020_wad_Campaign_list_campaigns(self):

        client = adwords.AdWordsClient.LoadFromStorage()

        campaigns = Campaign.listcampaigns(client)

        rslt = Campaign._aw_addcampaign(client, 'test_t020_campaign0')

        #print ( rslt )

        campaigns = Campaign.listcampaigns(client)

        Campaign.removecampaign(client, rslt['id'])

        rslt = Campaign.addcampaign(client, 'test_t020_campaign1')

        print(rslt)

        rslt = Campaign.removecampaign(client, rslt.campaignid)

        #print ( rslt )

        Budget.removenorefbudgets(client)
Ejemplo n.º 3
0
    def test_t024_wad_Campaign_sync_with_existing_budget2(self):

        print('wad_Campaign test t024')

        client = adwords.AdWordsClient.LoadFromStorage()

        # sync with django db
        Campaign.sync(client)

        budget0 = Budget._aw_addbudget(client, 't024_budget0', 10000000)
        budget1 = Budget._aw_addbudget(client, 't024_budget1', 20000000)
        budget2 = Budget._aw_addbudget(client, 't024_budget2', 30000000)

        Budget.sync(client)

        campaign0 = Campaign._aw_addcampaign(
            client, 't024_campaign0',
            Budget.objects.get(budgetamount=10000000))
        campaign1 = Campaign._aw_addcampaign(
            client, 't024_campaign1',
            Budget.objects.get(budgetamount=20000000))
        campaign2 = Campaign._aw_addcampaign(
            client, 't024_campaign2',
            Budget.objects.get(budgetamount=30000000))

        allcampaigns = Campaign.listcampaigns(client)

        #print ( budget0 )

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

            if campaign['id'] == campaign1['id']:
                self.assertEqual(campaign['budget']['amount']['microAmount'],
                                 budget1['amount']['microAmount'])

            if campaign['id'] == campaign2['id']:
                self.assertEqual(campaign['budget']['amount']['microAmount'],
                                 budget2['amount']['microAmount'])

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

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

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

        Campaign.sync(client)

        Campaign.objects.get(campaignbudget=Budget.objects.get(
            budgetid=budget0['budgetId'])).delete()
        Campaign.objects.get(campaignbudget=Budget.objects.get(
            budgetid=budget1['budgetId'])).delete()
        Campaign.objects.get(campaignbudget=Budget.objects.get(
            budgetid=budget2['budgetId'])).delete()

        #print ( campaign0 )

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

        Budget.removenorefbudgets(client)
Ejemplo n.º 4
0
    def test_t003_wad_Campaign_sync_add_remove_usingsync(self):

        print('wad_Campaign test t003')

        client = adwords.AdWordsClient.LoadFromStorage()

        # sync with django db
        Campaign.sync(client)

        # beginning django campaigns queryset
        beginningcampaigns = Campaign.objects.all()

        # beginning awcampaignslst
        beginningawcampaignslst = Campaign.listcampaigns(client)

        # assert that the django campaign set and aw campaignset correspond
        self.assertEqual(len(beginningcampaigns), len(beginningawcampaignslst))

        # create three new campaigns in aw
        campaign0id = Campaign._aw_addcampaign(client,
                                               'test_t003_campaign0')['id']
        campaign1id = Campaign._aw_addcampaign(client,
                                               'test_t003_campaign1')['id']
        campaign2id = Campaign._aw_addcampaign(client,
                                               'test_t003_campaign2')['id']

        # sync with django db
        Campaign.sync(client)

        # test if the new campaigns added to aw are in the Django system
        self.assertEqual(
            len(beginningcampaigns) + 3, len(Campaign.objects.all()))
        self.assertEqual(
            len(beginningawcampaignslst) + 3, len(Campaign.objects.all()))

        self.assertTrue(
            Campaign.objects.filter(
                campaignname='test_t003_campaign0').exists())
        self.assertTrue(
            Campaign.objects.filter(
                campaignname='test_t003_campaign1').exists())
        self.assertTrue(
            Campaign.objects.filter(
                campaignname='test_t003_campaign2').exists())

        # removes the campaigns from aw
        Campaign.removecampaign(client, campaign0id)
        Campaign.removecampaign(client, campaign1id)
        Campaign.removecampaign(client, campaign2id)

        # sync with django db
        Campaign.sync(client)

        # test if the django campaign set is equal to the aw campaign set after deletions
        self.assertEqual(len(beginningcampaigns), len(Campaign.objects.all()))
        self.assertEqual(len(beginningawcampaignslst),
                         len(Campaign.objects.all()))

        self.assertFalse(
            Campaign.objects.filter(
                campaignname='test_t003_campaign0').exists())
        self.assertFalse(
            Campaign.objects.filter(
                campaignname='test_t003_campaign1').exists())
        self.assertFalse(
            Campaign.objects.filter(
                campaignname='test_t003_campaign2').exists())

        Budget.removenorefbudgets(client)