Exemplo n.º 1
0
    def doCleanups(self):

        client = adwords.AdWordsClient.LoadFromStorage()

        # create a list of all current campaigns
        allcampaigns = Campaign.listcampaigns(client)

        # iterate the list of current campaigns
        for campaign in allcampaigns:
            # check if the campaign is in the startingcampaignsids list
            if campaign['id'] not in self.startingcampaignsids:
                # if it is not in the list then remove the campaign
                Campaign.removecampaign(client, campaign['id'])

        # budgets section

        # create a list of all current budgets
        allbudgets = Budget.listbudgets(client)

        # iterate the list of current budgets
        for budget in allbudgets:
            # check if the budget is in the startingbudgetsids list
            if budget['budgetId'] not in self.startingbudgetsids:
                # if it is not in the list then remove the budget
                Budget.removebudget(client, budget['budgetId'])
Exemplo n.º 2
0
    def doCleanups(self):

        client = adwords.AdWordsClient.LoadFromStorage()

        # create a list of all current budgets
        allbudgets = Budget.listbudgets(client)

        # iterate the list of current budgets
        for budget in allbudgets:
            # check if the budget is in the startingbudgetsids list
            if budget['budgetId'] not in self.startingbudgetsids:
                # if it is not in the list then remove the budget
                Budget.removebudget(client, budget['budgetId'])
Exemplo n.º 3
0
    def test_t009_wad_Budget_addbudget_removebudget(self):

        print('wad_Budget test t009')

        # save a new instance

        client = adwords.AdWordsClient.LoadFromStorage()

        rslt = Budget._aw_addbudget(client, 'test_t009_budget0')

        Budget.removebudget(client, rslt['budgetId'])

        rslt = Budget.addbudget(client, 'test_t010_budget1')

        rslt = Budget.removebudget(client, rslt.budgetid)
Exemplo n.º 4
0
    def test_t003_wad_Budget_sync_add_remove_usingsync(self):

        print('wad_Budget test t003')

        client = adwords.AdWordsClient.LoadFromStorage()

        # sync with django db
        Budget.sync(client)

        # beginning django budgets queryset
        beginningbudgets = Budget.objects.all()

        # beginning awbudgetslst
        beginningawbudgetslst = Budget.listbudgets(client)

        # assert that the django budget set and aw budgetset correspond
        self.assertEqual(len(beginningbudgets), len(beginningawbudgetslst))

        # create three new budgets in aw
        budget0id = Budget._aw_addbudget(client, 'test_t003_budget0',
                                         7000000000)['budgetId']
        budget1id = Budget._aw_addbudget(client, 'test_t003_budget1',
                                         7000000000)['budgetId']
        budget2id = Budget._aw_addbudget(client, 'test_t003_budget2',
                                         7000000000)['budgetId']

        # sync with django db
        Budget.sync(client)

        # test if the new budgets added to aw are in the Django system
        self.assertEqual(len(beginningbudgets) + 3, len(Budget.objects.all()))
        self.assertEqual(
            len(beginningawbudgetslst) + 3, len(Budget.objects.all()))

        self.assertTrue(
            Budget.objects.filter(budgetname='test_t003_budget0').exists())
        self.assertTrue(
            Budget.objects.filter(budgetname='test_t003_budget1').exists())
        self.assertTrue(
            Budget.objects.filter(budgetname='test_t003_budget2').exists())

        # removes the budgets from aw
        Budget.removebudget(client, budget0id)
        Budget.removebudget(client, budget1id)
        Budget.removebudget(client, budget2id)

        # sync with django db
        Budget.sync(client)

        # test if the django budget set is equal to the aw budget set after deletions
        self.assertEqual(len(beginningbudgets), len(Budget.objects.all()))
        self.assertEqual(len(beginningawbudgetslst), len(Budget.objects.all()))

        self.assertFalse(
            Budget.objects.filter(budgetname='test_t003_budget0').exists())
        self.assertFalse(
            Budget.objects.filter(budgetname='test_t003_budget1').exists())
        self.assertFalse(
            Budget.objects.filter(budgetname='test_t003_budget2').exists())
Exemplo n.º 5
0
    def test_t004_wad_Budget_sync_modify(self):

        print('wad_Budget test t004')

        client = adwords.AdWordsClient.LoadFromStorage()

        # add 3 budgets to aw only
        budget0 = Budget._aw_addbudget(client, 'test_t004_budget0', 7000000000)
        budget1 = Budget._aw_addbudget(client, 'test_t004_budget1', 7000000000)
        budget2 = Budget._aw_addbudget(client, 'test_t004_budget2', 7000000000)

        # initial sync
        Budget.sync(client)

        # control will be used to check if the values return to original after modifications
        beginningbudgets_control = Budget.objects.all()
        # queryset used to modify values
        beginningbudgets = Budget.objects.all()

        # make sure we are working with querysets that aren't empty, should be at least 3
        self.assertTrue(len(beginningbudgets) >= 3)
        self.assertTrue(len(beginningbudgets_control) >= 3)

        # change values in the django database
        for budget in beginningbudgets:

            budget.budgetstatus = Budget.STATE_TESTING
            budget.budgetname = budget.budgetname + '_testing'
            budget.budgetamount = budget.budgetamount + 10000000

            budget.save(sync_aw=False)

        # sync
        Budget.sync(client)

        # queryset used to test if values revert to original values
        postmodifybudgets = Budget.objects.all()

        # make sure we are working with querysets that aren't empty, should be at least 3 b/c of SetUp
        self.assertTrue(len(postmodifybudgets) >= 3)

        # iterate budgets in database to check if values returned to original
        for budget in postmodifybudgets:

            controlbudget = beginningbudgets_control.get(id=budget.id)

            self.assertEqual(controlbudget.budgetstatus, budget.budgetstatus)
            self.assertEqual(controlbudget.budgetname, budget.budgetname)
            self.assertEqual(controlbudget.budgetamount, budget.budgetamount)

        # remove the budgets we initially created
        Budget.removebudget(client, budget0['budgetId'])
        Budget.removebudget(client, budget1['budgetId'])
        Budget.removebudget(client, budget2['budgetId'])
Exemplo n.º 6
0
    def test_t002_wad_Budget_add_remove_usingsync(self):

        print('wad_Budget test t002')

        client = adwords.AdWordsClient.LoadFromStorage()

        # creates three new budgets
        budget0id = Budget._aw_addbudget(client, 'test_t002_budget0',
                                         6000000000)['budgetId']
        budget1id = Budget._aw_addbudget(client, 'test_t002_budget1',
                                         6000000000)['budgetId']
        budget2id = Budget._aw_addbudget(client, 'test_t002_budget2',
                                         6000000000)['budgetId']

        # gets the lists of all budgets
        budgetlist = Budget.listbudgets(client)

        budgetidlist = []

        # builds a list of budgets with status != REMOVED
        for budget in budgetlist:
            if budget['status'] != Budget.STATE_REMOVED:
                budgetidlist.append(budget['budgetId'])

        # asserts the budgets added are in the list
        self.assertTrue(budget0id in budgetidlist)
        self.assertTrue(budget1id in budgetidlist)
        self.assertTrue(budget2id in budgetidlist)

        # removes the budgets
        Budget.removebudget(client, budget0id)
        Budget.removebudget(client, budget1id)
        Budget.removebudget(client, budget2id)

        # gets the list of all budgets
        budgetlist = Budget.listbudgets(client)

        budgetidlist = []

        # builds a list of budgets with status != REMOVED
        for budget in budgetlist:
            if budget['status'] != Budget.STATE_REMOVED:
                budgetidlist.append(budget['budgetId'])

        # asserts the budgets added are not in the list
        self.assertFalse(budget0id in budgetidlist)
        self.assertFalse(budget1id in budgetidlist)
        self.assertFalse(budget2id in budgetidlist)