def test_rewards_search(self, helpmock, permock): """ Search rewards string :param helpmock: :param permock: :return: """ page = '"WindowsLiveId":"" "WindowsLiveId":"" ' page += 'action="0" value="0" ' page += 'value= "0" NAP value="0" ' page += 'ANON value="0" ' page += 'id="t" value="0" ' page += '<div> 999 livetime points</div> ' page += "t.innerHTML='100'" page += '<div id="b_content">' page += '<div id="content">' page += 'IG:"100"' page += "http://www.bing.com/fd/ls/GLinkPing.aspx" helpmock.return_value = page useragents = bingCommon.UserAgents().generate(self.config.accounts) reward = BingRewards(bingCommon.HEADERS, useragents, self.config) newbfp = bfp.RewardV1() reward.RewardResult(newbfp) newbfp.progressCurrent = 1 newbfp.progressMax = 100 newbfp.description = "Up to 10 points today, 10 points per search" newbfp.isDone = False # SEARCH case, PC, Mobile, Earn for data in [ newbfp.Type.SEARCH_MOBILE, newbfp.Type.SEARCH_PC, newbfp.Type.YOUR_GOAL, newbfp.Type.MAINTAIN_GOLD, newbfp.Type.REFER_A_FRIEND, newbfp.Type.SEND_A_TWEET, newbfp.Type.RE_EARNED_CREDITS, newbfp.Type.COMPLETED, newbfp.Type.SILVER_STATUS, newbfp.Type.INVITE_FRIENDS, newbfp.Type.EARN_MORE_POINTS, newbfp.Type.SEARCH_AND_EARN, newbfp.Type.THURSDAY_BONUS, newbfp.Type.RE_QUIZ]: newbfp.tp = data newbfp.url = "www.espn.com" newbfp.Type = bfp.RewardV1.Type.Action.SEARCH rewards = [newbfp] newbfp.isAchieved = lambda: data is False self.assertIsNotNone(reward.process(rewards, True), "should return res") newbfp.isDone = True self.assertIsNotNone(reward.process(rewards, True), "should return res") self.config.proxy = None BingRewards(bingCommon.HEADERS, useragents, self.config)
def _rewards_hit(self, classobj, helpmock): """ test rewards object :return: """ self.config.proxy = False reward = BingRewards(bingCommon.HEADERS, "", self.config) page = '"WindowsLiveId":"" "WindowsLiveId":"" ' page += 'action="0" value="0" ' page += 'value= "0" NAP value="0" ' page += 'ANON value="0" ' page += 'id="t" value="0" ' page += '<div> 999 livetime points</div> ' helpmock.return_value = page # if not login should have not found error for url self.assertIsNotNone(reward.getLifetimeCredits, "Should return int") page = "t.innerHTML='100'" helpmock.return_value = page self.assertIsNotNone(reward.getRewardsPoints(), "should not be None") self.assertRaisesRegexp(TypeError, "not an instance", reward.process, None, True) # NONE case newbfp = classobj newbfp.tp = None rewards = [newbfp] self.assertIsNotNone(reward.process(rewards, True), "handle not none") # HIT case newbfp.tp = mock.Mock() newbfp.tp = [0, 1, 2, 3, bfp.RewardV1.Type.Action.HIT] # SEARCH case newbfp.tp = mock.Mock() newbfp.tp = [0, 1, 2, 3, bfp.RewardV1.Type.Action.SEARCH] newbfp.progressCurrent = 100 rewards = [newbfp] self.assertIsNotNone(reward.process(rewards, True), "should return res") self.assertRaisesRegexp(TypeError, "not an instance", reward.printResults, None, True) result = mock.Mock() result.action = bfp.RewardV1.Type.Action.SEARCH result.isError = True result.o = newbfp result.message = "done" newbfp.progressCurrent = 1 newbfp.progressMax = 100 newbfp.url = "http:0.0.0.0" self.assertIsNone(reward.printResults([result], True), "should return None") self.assertRaisesRegexp(TypeError, "rewards is not", reward.printRewards, None) rewards[0].isDone = True self.assertIsNone(reward.printRewards(rewards), "should return None") self.assertRaisesRegexp(TypeError, "reward is not", reward.RewardResult, None) self.assertIsNotNone(reward.RewardResult(newbfp), "should return class") proxy = mock.Mock() proxy.login = True proxy.password = "******" proxy.url = "http://127.0.0.1" proxy.protocols = "http" self.config.proxy = proxy self.assertIsNotNone(BingRewards(bingCommon.HEADERS, "", self.config), "should return class") proxy.login = False self.config.proxy = proxy self.assertIsNotNone(BingRewards(bingCommon.HEADERS, "", self.config), "should return class") self.assertRaisesRegexp(ConfigError, "not found", self.config.parseFromString, PROTXML) self.assertRaisesRegexp(ConfigError, "not found", self.config.parseFromString, URLXML)