def setUp(self): connection = Connection() connection.login(username,password) self.user = User() Daily.update_all() Habit.update_all() ToDo.update_all()
class TestUserProfile(unittest.TestCase): def setUp(self): connection = Connection() connection.login(username,password) self.user = User() def test_status_update(self): self.user.update_status() self.assertIsNotNone(self.user.hp) self.assertIsNotNone(self.user.maxhp) self.assertIsNotNone(self.user.mp) self.assertIsNotNone(self.user.maxmp) self.assertIsNotNone(self.user.xp) self.assertIsNotNone(self.user.xp_to_level) self.assertIsNotNone(self.user.gp)
class TestPurchasing(unittest.TestCase): def setUp(self): connection = Connection() connection.login(username,password) self.user = User() Habit.update_all() def test_buy_healing_potion(self): healing_potion_cost = 25 testing_habit = Habit.add(title='Test habit for stat manipulation',up=True,down=True) while self.user.gp < healing_potion_cost: testing_habit.score('up') if self.user.hp == self.user.maxhp: testing_habit.score('down') testing_habit.delete() health_before_potion = self.user.hp self.user.buy_health_potion() self.assertTrue(self.user.hp > health_before_potion,"Before health: %s, Current health: %s" % (health_before_potion,self.user.hp)) def test_buy_list(self): self.user.get_buy_list() self.assertTrue(len(self.user.buy_list) > 0, 'Buy list is 0 length') self.assertIsNotNone(self.user.buy_list[0].text, 'Invalid item data') def test_buy_gear(self): self.user.get_buy_list() buy_list_by_price = {} for item in self.user.buy_list: buy_list_by_price[item.value] = item.key buy_cost = min(buy_list_by_price.keys()) item_to_buy = buy_list_by_price[buy_cost] testing_habit = Habit.add(title='Test habit for stat manipulation',up=True,down=True) while self.user.gp < buy_cost: testing_habit.score('up') testing_habit.delete() self.user.buy_item(item_to_buy) self.user.update_status() all_owned_items = [] for item in self.user.inventory['gear']['owned'].keys(): if self.user.inventory['gear']['owned'][item]: all_owned_items.append(item) for item in self.user.inventory['gear']['equipped']: all_owned_items.append(item) self.assertIn(item_to_buy,all_owned_items)
class TestScoring(unittest.TestCase): def setUp(self): connection = Connection() connection.login(username,password) self.user = User() Daily.update_all() Habit.update_all() ToDo.update_all() def test_score_task(self): daily = Daily.add(title='Test score daily') daily.score() self.assertTrue(daily.completed) daily.delete() def test_score_habit(self): habit = Habit.add(title='Test score habit',up=True,down=True) self.user.update_status() current_xp = self.user.profile['stats']['exp'] current_hp = self.user.profile['stats']['hp'] habit.score('up') self.user.update_status() self.assertNotEqual(current_xp,self.user.profile['stats']['exp'],'XP has not changed') habit.score('down') self.user.update_status() self.assertNotEqual(current_hp,self.user.profile['stats']['hp'],'HP has not changed') habit.delete() def test_score_checklist(self): todo = ToDo.add(title='Test score checklist') checklist_text = "Check me off!" todo.add_to_checklist(checklist_text) todo.score_checklist(todo.checklist[0]['id']) self.assertTrue(todo.checklist[0]['completed']) todo.delete()
def setUp(self): connection = Connection() connection.login(username,password) self.user = User()