Exemplo n.º 1
0
    def test_create_get_delete_restore_delete(self):
        c = get_client(AdsClient)
        camp_c = get_client(CampaignsClient)
        grp_c = get_client(GroupsClient)

        # 0) prepare campaign and group
        campaign = Campaign(self.campaign)
        campaign.name += 'crud'
        campaign_id = camp_c.create_campaigns([campaign])[0]
        group = Group(self.group)
        group.campaignId = campaign_id
        group_id = grp_c.create_groups([group])[0]

        ad = Ad(self.ad)
        ad.groupId = group_id

        # 1) create
        ids = c.create_ads([ad])
        existing = len(c.list_ads(groups=[group_id]))
        self.assertEqual(existing, 1)

        # 2) check equality
        from_api = c.get_ads(ids)[0]
        for key, val in self.ad:
            self.assertEqual(val, getattr(from_api, key))

        # 3) delete
        c.remove_ads(ids)
        existing2 = len(c.list_ads(groups=[group_id]))
        self.assertEqual(0, existing2)

        # 4) restore
        c.restore_ads(ids)
        existing3 = len(c.list_ads(groups=[group_id]))
        self.assertEqual(1, existing3)

        # 5) update
        ad = Ad(self.ad)
        ad.clickthruUrl += '&utm_cosi=nic'
        ad.id = ids[0]
        new_ids = c.update_ads([ad])
        self.assertEqual([], new_ids)

        # 6) check equality
        from_api = c.get_ads(ids)[0]
        for key, val in ad:
            self.assertEqual(val, getattr(from_api, key))

        # 7) create new one via update
        ad = Ad(self.ad)
        ad.creative3 += 'cosi'
        ad.id = ids[0]
        new_ids = c.update_ads([ad])
        self.assertEqual(1, len(new_ids))

        # 8) check equality
        ad.id = new_ids[0]
        from_api = c.get_ads(new_ids)[0]
        for key, val in ad:
            self.assertEqual(val, getattr(from_api, key))

        # 9) delete
        c.remove_ads(ids)
        grp_c.remove_groups([group_id])
        camp_c.remove_campaigns([campaign_id])
Exemplo n.º 2
0
    def test_create_get_delete_restore_delete(self):
        c = get_client(AdsClient)
        camp_c = get_client(CampaignsClient)
        grp_c = get_client(GroupsClient)

        # 0) prepare campaign and group
        campaign = Campaign(self.campaign)
        campaign.name += 'crud'
        campaign_id = camp_c.create_campaigns([campaign])[0]
        group = Group(self.group)
        group.campaignId = campaign_id
        group_id = grp_c.create_groups([group])[0]

        ad = Ad(self.ad)
        ad.groupId = group_id

        # 1) create
        ids = c.create_ads([ad])
        existing = len(c.list_ads(groups=[group_id]))
        self.assertEqual(existing, 1)

        # 2) check equality
        from_api = c.get_ads(ids)[0]
        for key, val in self.ad:
            self.assertEqual(val, getattr(from_api, key))

        # 3) delete
        c.remove_ads(ids)
        existing2 = len(c.list_ads(groups=[group_id]))
        self.assertEqual(0, existing2)

        # 4) restore
        c.restore_ads(ids)
        existing3 = len(c.list_ads(groups=[group_id]))
        self.assertEqual(1, existing3)

        # 5) update
        ad = Ad(self.ad)
        ad.clickthruUrl += '&utm_cosi=nic'
        ad.id = ids[0]
        new_ids = c.update_ads([ad])
        self.assertEqual([], new_ids)

        # 6) check equality
        from_api = c.get_ads(ids)[0]
        for key, val in ad:
            self.assertEqual(val, getattr(from_api, key))

        # 7) create new one via update
        ad = Ad(self.ad)
        ad.creative3 += 'cosi'
        ad.id = ids[0]
        new_ids = c.update_ads([ad])
        self.assertEqual(1, len(new_ids))

        # 8) check equality
        ad.id = new_ids[0]
        from_api = c.get_ads(new_ids)[0]
        for key, val in ad:
            self.assertEqual(val, getattr(from_api, key))

        # 9) delete
        c.remove_ads(ids)
        grp_c.remove_groups([group_id])
        camp_c.remove_campaigns([campaign_id])