コード例 #1
0
    def test_check(self):
        campaign = Campaign(
            name=self.campaign_name,
            dayBudget=1,
        )

        c = get_client(CampaignsClient)

        with self.assertRaisesRegexp(InvalidDataError, '406; campaign_dayBudget_is_too_low'):
            c.check_campaigns([campaign])
コード例 #2
0
    def test_create_get_delete_restore_delete(self):
        c = get_client(KeywordsClient)
        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]

        keyword = Keyword(self.keyword)
        keyword.groupId = group_id

        # 1) create
        ids = c.create_keywords([keyword])
        existing = len(c.list_keywords(groups=[group_id]))
        self.assertEqual(existing, 1)

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

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

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

        # 5) update
        keyword = Keyword(self.keyword)
        keyword.cpc = 10000
        keyword.id = ids[0]
        c.update_keywords([keyword])

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

        # 7) delete
        c.remove_keywords(ids)
        grp_c.remove_groups([group_id])
        camp_c.remove_campaigns([campaign_id])
コード例 #3
0
    def test_create_get_delete_restore_delete(self):
        c = get_client(CampaignsClient)

        # 1) create
        ids = c.create_campaigns([self.campaign])

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

        # 3) list
        existing = len(c.list_campaigns())
        self.assertGreaterEqual(existing, 1)

        # 4) delete
        c.remove_campaigns(ids)
        existing2 = len(c.list_campaigns())
        self.assertEqual(1, existing - existing2)

        # 5) restore
        c.restore_campaigns(ids)
        existing3 = len(c.list_campaigns())
        self.assertEqual(existing, existing3)

        # 6) update
        campaign = Campaign(self.campaign)
        campaign.dayBudget = 20000
        campaign.id = ids[0]
        c.update_campaigns([campaign])

        # 7) check equality
        from_api = c.get_campaigns(ids)[0]
        for key, val in campaign:
            self.assertEqual(val, getattr(from_api, key))

        # 8) delete
        c.remove_campaigns(ids)
コード例 #4
0
    def test_create_get_delete_restore_delete(self):
        c = get_client(GroupsClient)
        camp_c = get_client(CampaignsClient)

        # 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

        # 1) create
        ids = c.create_groups([group])
        existing = len(c.list_groups(campaigns=[campaign_id]))
        self.assertEqual(1, existing)

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

        # 3) delete
        c.remove_groups(ids)
        existing2 = len(c.list_groups(campaigns=[campaign_id]))
        self.assertEqual(0, existing2)

        # 4) restore
        c.restore_groups(ids)
        existing3 = len(c.list_groups(campaigns=[campaign_id]))
        self.assertEqual(1, existing3)

        # 5) update
        group = Group(self.group)
        group.cpc = 20000
        group.id = ids[0]
        c.update_groups([group])

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

        # 7) delete
        c.remove_groups(ids)
        camp_c.remove_campaigns([campaign_id])
コード例 #5
0
    def test_check(self):
        camp_c = get_client(CampaignsClient)
        campaign = Campaign(self.campaign)
        campaign.name += 'check'
        campaign_id = camp_c.create_campaigns([campaign])[0]

        try:
            group = Group(
                campaignId=campaign_id,
                name=self.group_name,
                cpc=1,
            )

            c = get_client(GroupsClient)

            with self.assertRaisesRegexp(InvalidDataError, '406; group_cpc_is_too_low'):
                c.check_groups([group])

        finally:
            camp_c.remove_campaigns([campaign_id])
コード例 #6
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])
コード例 #7
0
class AdsTest(unittest.TestCase):

    creative1 = 'test ad'
    creative2 = 'first line'
    creative3 = 'second line'
    url_display = 'http://example.com/'
    url_link = 'http://example.com/?utm_source=sklik'

    group_name = 'test ad group' + str(datetime.now())
    campaign_name = 'test ad campaign' + str(datetime.now())

    campaign = Campaign(name=campaign_name,
                        dayBudget=10000,
                        context=False,
                        fulltext=True)

    group = Group(name=group_name, cpc=10000, cpcContext=10000)

    ad = Ad(
        creative1=creative1,
        creative2=creative2,
        creative3=creative3,
        clickthruText=url_display,
        clickthruUrl=url_link,
    )

    values = dict(
        creative1=creative1,
        creative2=creative2,
        creative3=creative3,
        clickthruText=url_display,
        clickthruUrl=url_link,
    )

    def _get_client(self):
        return get_client(AdsClient)

    def test_construct(self):
        self.assertEqual(Ad(self.ad), self.ad)

    def test_marshall(self):
        self.assertEqual(marshall_param(self.ad), self.values)
        self.assertEqual(marshall_param([self.ad]), [self.values])
        self.assertEqual(Ad.marshall_list([self.values]), [self.ad])

    @only_with_login
    def test_check(self):
        ad = Ad(
            creative1=self.creative1,
            creative2=self.creative2,
            creative3=self.creative3,
            clickthruText=self.url_display,
            clickthruUrl='bad url',
        )

        c = get_client(AdsClient)

        with self.assertRaisesRegexp(InvalidDataError, '406; bad_url'):
            c.check_ads([ad])

    @only_with_login
    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])
コード例 #8
0
class GroupsTest(unittest.TestCase):

    group_name = 'test group' + str(datetime.now())
    campaign_name = 'test group campaign' + str(datetime.now())

    campaign = Campaign(
        name=campaign_name,
        dayBudget=10000,
        context=False,
        fulltext=True
    )

    group = Group(
        name=group_name,
        cpc=10000,
        cpcContext=10000
    )

    values = dict(
        name=group_name,
        cpc=10000,
        cpcContext=10000
    )

    def test_construct(self):
        self.assertEqual(Group(self.group), self.group)

    def test_marshall(self):
        self.assertEqual(marshall_param(self.group), self.values)
        self.assertEqual(marshall_param([self.group]), [self.values])
        self.assertEqual(Group.marshall_list([self.values]), [self.group])

    @only_with_login
    def test_check(self):
        camp_c = get_client(CampaignsClient)
        campaign = Campaign(self.campaign)
        campaign.name += 'check'
        campaign_id = camp_c.create_campaigns([campaign])[0]

        try:
            group = Group(
                campaignId=campaign_id,
                name=self.group_name,
                cpc=1,
            )

            c = get_client(GroupsClient)

            with self.assertRaisesRegexp(InvalidDataError, '406; group_cpc_is_too_low'):
                c.check_groups([group])

        finally:
            camp_c.remove_campaigns([campaign_id])

    @only_with_login
    def test_create_get_delete_restore_delete(self):
        c = get_client(GroupsClient)
        camp_c = get_client(CampaignsClient)

        # 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

        # 1) create
        ids = c.create_groups([group])
        existing = len(c.list_groups(campaigns=[campaign_id]))
        self.assertEqual(1, existing)

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

        # 3) delete
        c.remove_groups(ids)
        existing2 = len(c.list_groups(campaigns=[campaign_id]))
        self.assertEqual(0, existing2)

        # 4) restore
        c.restore_groups(ids)
        existing3 = len(c.list_groups(campaigns=[campaign_id]))
        self.assertEqual(1, existing3)

        # 5) update
        group = Group(self.group)
        group.cpc = 20000
        group.id = ids[0]
        c.update_groups([group])

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

        # 7) delete
        c.remove_groups(ids)
        camp_c.remove_campaigns([campaign_id])
コード例 #9
0
class KeywordsTest(unittest.TestCase):

    keyword_name = 'test keyword'
    group_name = 'test keyword group' + str(datetime.now())
    campaign_name = 'test keyword campaign' + str(datetime.now())

    campaign = Campaign(name=campaign_name,
                        dayBudget=10000,
                        context=False,
                        fulltext=True)

    group = Group(name=group_name, cpc=10000, cpcContext=10000)

    keyword = Keyword(name=keyword_name, matchType='phrase')

    values = dict(name=keyword_name, matchType='phrase')

    def test_construct(self):
        self.assertEqual(Keyword(self.keyword), self.keyword)

    def test_marshall(self):
        self.assertEqual(marshall_param(self.keyword), self.values)
        self.assertEqual(marshall_param([self.keyword]), [self.values])
        self.assertEqual(Keyword.marshall_list([self.values]), [self.keyword])

    @only_with_login
    def test_check(self):
        keyword = Keyword(
            name=self.keyword_name,
            cpc=1,
        )

        c = get_client(KeywordsClient)

        with self.assertRaisesRegexp(InvalidDataError, '406; ambiguous_check'):
            c.check_keywords([keyword])

    @only_with_login
    def test_create_get_delete_restore_delete(self):
        c = get_client(KeywordsClient)
        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]

        keyword = Keyword(self.keyword)
        keyword.groupId = group_id

        # 1) create
        ids = c.create_keywords([keyword])
        existing = len(c.list_keywords(groups=[group_id]))
        self.assertEqual(existing, 1)

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

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

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

        # 5) update
        keyword = Keyword(self.keyword)
        keyword.cpc = 10000
        keyword.id = ids[0]
        c.update_keywords([keyword])

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

        # 7) delete
        c.remove_keywords(ids)
        grp_c.remove_groups([group_id])
        camp_c.remove_campaigns([campaign_id])
コード例 #10
0
 def test_marshall(self):
     self.assertEqual(marshall_param(self.campaign), self.values)
     self.assertEqual(marshall_param([self.campaign]), [self.values])
     self.assertEqual(Campaign.marshall_list([self.values]), [self.campaign])
コード例 #11
0
 def test_construct(self):
     self.assertEqual(Keyword(self.keyword), self.keyword)
     self.assertEqual(Campaign(self.campaign), self.campaign)
コード例 #12
0
class CampaignsTest(unittest.TestCase):

    keyword = Keyword(name='some kw', matchType='negativeBroad')

    campaign_name = 'test campaign' + str(datetime.now())

    campaign = Campaign(
        name=campaign_name,
        dayBudget=10000,
        context=False,
        fulltext=True,
        negativeKeywords=[keyword]
    )

    values = dict(
        name=campaign_name,
        dayBudget=10000,
        context=False,
        fulltext=True,
        negativeKeywords=[dict(name='some kw', matchType='negativeBroad')]
    )

    def _get_client(self):
        return get_client(CampaignsClient)

    def test_construct(self):
        self.assertEqual(Keyword(self.keyword), self.keyword)
        self.assertEqual(Campaign(self.campaign), self.campaign)

    def test_marshall(self):
        self.assertEqual(marshall_param(self.campaign), self.values)
        self.assertEqual(marshall_param([self.campaign]), [self.values])
        self.assertEqual(Campaign.marshall_list([self.values]), [self.campaign])

    @only_with_login
    def test_check(self):
        campaign = Campaign(
            name=self.campaign_name,
            dayBudget=1,
        )

        c = get_client(CampaignsClient)

        with self.assertRaisesRegexp(InvalidDataError, '406; campaign_dayBudget_is_too_low'):
            c.check_campaigns([campaign])

    @only_with_login
    def test_create_get_delete_restore_delete(self):
        c = get_client(CampaignsClient)

        # 1) create
        ids = c.create_campaigns([self.campaign])

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

        # 3) list
        existing = len(c.list_campaigns())
        self.assertGreaterEqual(existing, 1)

        # 4) delete
        c.remove_campaigns(ids)
        existing2 = len(c.list_campaigns())
        self.assertEqual(1, existing - existing2)

        # 5) restore
        c.restore_campaigns(ids)
        existing3 = len(c.list_campaigns())
        self.assertEqual(existing, existing3)

        # 6) update
        campaign = Campaign(self.campaign)
        campaign.dayBudget = 20000
        campaign.id = ids[0]
        c.update_campaigns([campaign])

        # 7) check equality
        from_api = c.get_campaigns(ids)[0]
        for key, val in campaign:
            self.assertEqual(val, getattr(from_api, key))

        # 8) delete
        c.remove_campaigns(ids)