def test_get_user_profile_user_has_badges(self): user_1 = UserFactory(name='Name') profile_badge_1 = ProfileItemFactory( file_path=os.path.join("tests", "support", "badge1.png")) profile_badge_2 = ProfileItemFactory( file_path=os.path.join("tests", "support", "badge2.png")) profile_badge_3 = ProfileItemFactory( file_path=os.path.join("tests", "support", "badge3.png")) profile_badge_4 = ProfileItemFactory( file_path=os.path.join("tests", "support", "badge1.png")) user_1.profile_items = [ UserProfileItemFactory(profile_item=profile_badge_1), UserProfileItemFactory(profile_item=profile_badge_2), UserProfileItemFactory(profile_item=profile_badge_3), UserProfileItemFactory(profile_item=profile_badge_4, equipped=False), ] self.test_session.commit() with open(os.path.join('tests', 'support', 'user_avatar.png'), 'rb') as f: user_avatar_bytes = f.read() result = asyncio.run(Profile().get_user_profile(user_1.id, user_avatar_bytes, lang='pt')) with open( os.path.join('tests', 'support', 'get_user_profile_with_badges.png'), 'rb') as f: self.assertEqual(result.getvalue(), f.read())
def test_unequip_item_user_has_item(self): user = UserFactory() profile_item = ProfileItemFactory() user.profile_items = [ UserProfileItemFactory(equipped=True, profile_item=profile_item) ] self.db_session.commit() result = asyncio.run(Palplatina().unequip_item(user.id, profile_item.name)) self.assertFalse(result.equipped) Session.remove() fetched_user_profile_item = self.db_session.query(UserProfileItem).get( (user.id, profile_item.id)) self.assertFalse(fetched_user_profile_item.equipped)
def test_buy_item_item_already_bought(self): profile_item = ProfileItemFactory() user = UserFactory(currency=150) user.profile_items = [ UserProfileItemFactory(profile_item=profile_item) ] self.db_session.commit() with self.assertRaises(AlreadyOwnsItem): asyncio.run(Palplatina().buy_item(user.id, profile_item.name)) persisted_user = self.db_session.query(User).get(user.id) persisted_user_profile_items = persisted_user.profile_items self.assertEqual(persisted_user.currency, 150) self.assertEqual(len(persisted_user_profile_items), 1) self.assertEqual(persisted_user_profile_items[0].profile_item.id, profile_item.id)
def test_get_user_profile_user_has_wallpaper(self): user_1 = UserFactory(name='Name') profile_badge = ProfileItemFactory(type='wallpaper', file_path=os.path.join( "tests", "support", "wallpaper.png")) user_1.profile_items = [ UserProfileItemFactory(profile_item=profile_badge), ] self.test_session.commit() with open(os.path.join('tests', 'support', 'user_avatar.png'), 'rb') as f: user_avatar_bytes = f.read() result = asyncio.run(Profile().get_user_profile(user_1.id, user_avatar_bytes, lang='pt')) with open( os.path.join('tests', 'support', 'get_user_profile_with_wallpaper.png'), 'rb') as f: self.assertEqual(result.getvalue(), f.read())