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])
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])
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])
def test_construct(self): self.assertEqual(Keyword(self.keyword), self.keyword)
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])
def test_construct(self): self.assertEqual(Keyword(self.keyword), self.keyword) self.assertEqual(Campaign(self.campaign), self.campaign)
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)